]>
Commit | Line | Data |
---|---|---|
43f0537c | 1 | from __future__ import unicode_literals |
2 | ||
3 | import re | |
4 | ||
5 | from .common import InfoExtractor | |
e0942e37 S |
6 | from ..utils import ( |
7 | parse_iso8601, | |
8 | str_to_int, | |
9 | ) | |
10 | ||
43f0537c | 11 | |
12 | class CrackedIE(InfoExtractor): | |
e0942e37 | 13 | _VALID_URL = r'https?://(?:www\.)?cracked\.com/video_(?P<id>\d+)_[\da-z-]+\.html' |
c610f38b S |
14 | _TESTS = [{ |
15 | 'url': 'http://www.cracked.com/video_19070_if-animal-actors-got-e21-true-hollywood-stories.html', | |
16 | 'md5': '89b90b9824e3806ca95072c4d78f13f7', | |
17 | 'info_dict': { | |
18 | 'id': '19070', | |
19 | 'ext': 'mp4', | |
20 | 'title': 'If Animal Actors Got E! True Hollywood Stories', | |
21 | 'timestamp': 1404954000, | |
22 | 'upload_date': '20140710', | |
23 | } | |
24 | }, { | |
25 | # youtube embed | |
e0942e37 | 26 | 'url': 'http://www.cracked.com/video_19006_4-plot-holes-you-didnt-notice-in-your-favorite-movies.html', |
c610f38b | 27 | 'md5': 'ccd52866b50bde63a6ef3b35016ba8c7', |
43f0537c | 28 | 'info_dict': { |
c610f38b | 29 | 'id': 'EjI00A3rZD0', |
43f0537c | 30 | 'ext': 'mp4', |
c610f38b S |
31 | 'title': "4 Plot Holes You Didn't Notice in Your Favorite Movies - The Spit Take", |
32 | 'description': 'md5:c603708c718b796fe6079e2b3351ffc7', | |
33 | 'upload_date': '20140725', | |
34 | 'uploader_id': 'Cracked', | |
35 | 'uploader': 'Cracked', | |
43f0537c | 36 | } |
c610f38b | 37 | }] |
43f0537c | 38 | |
39 | def _real_extract(self, url): | |
d7403332 | 40 | video_id = self._match_id(url) |
43f0537c | 41 | |
42 | webpage = self._download_webpage(url, video_id) | |
43f0537c | 43 | |
6447353f S |
44 | youtube_url = self._search_regex( |
45 | r'<iframe[^>]+src="((?:https?:)?//www\.youtube\.com/embed/[^"]+)"', | |
46 | webpage, 'youtube url', default=None) | |
47 | if youtube_url: | |
c610f38b | 48 | return self.url_result(youtube_url, 'Youtube') |
6447353f | 49 | |
e0942e37 | 50 | video_url = self._html_search_regex( |
6447353f S |
51 | [r'var\s+CK_vidSrc\s*=\s*"([^"]+)"', r'<video\s+src="([^"]+)"'], |
52 | webpage, 'video URL') | |
43f0537c | 53 | |
b46ed499 S |
54 | title = self._search_regex( |
55 | [r'property="?og:title"?\s+content="([^"]+)"', r'class="?title"?>([^<]+)'], | |
56 | webpage, 'title') | |
43f0537c | 57 | |
b46ed499 S |
58 | description = self._search_regex( |
59 | r'name="?(?:og:)?description"?\s+content="([^"]+)"', | |
60 | webpage, 'description', default=None) | |
61 | ||
62 | timestamp = self._html_search_regex( | |
63 | r'"date"\s*:\s*"([^"]+)"', webpage, 'upload date', fatal=False) | |
e0942e37 S |
64 | if timestamp: |
65 | timestamp = parse_iso8601(timestamp[:-6]) | |
43f0537c | 66 | |
e0942e37 | 67 | view_count = str_to_int(self._html_search_regex( |
b46ed499 S |
68 | r'<span\s+class="?views"? id="?viewCounts"?>([\d,\.]+) Views</span>', |
69 | webpage, 'view count', fatal=False)) | |
e0942e37 | 70 | comment_count = str_to_int(self._html_search_regex( |
b46ed499 S |
71 | r'<span\s+id="?commentCounts"?>([\d,\.]+)</span>', |
72 | webpage, 'comment count', fatal=False)) | |
43f0537c | 73 | |
e0942e37 S |
74 | m = re.search(r'_(?P<width>\d+)X(?P<height>\d+)\.mp4$', video_url) |
75 | if m: | |
76 | width = int(m.group('width')) | |
77 | height = int(m.group('height')) | |
78 | else: | |
79 | width = height = None | |
43f0537c | 80 | |
e0942e37 S |
81 | return { |
82 | 'id': video_id, | |
5f6a1245 | 83 | 'url': video_url, |
e0942e37 S |
84 | 'title': title, |
85 | 'description': description, | |
86 | 'timestamp': timestamp, | |
87 | 'view_count': view_count, | |
88 | 'comment_count': comment_count, | |
89 | 'height': height, | |
90 | 'width': width, | |
5f6a1245 | 91 | } |