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