]>
jfr.im git - yt-dlp.git/blob - youtube_dl/extractor/metacafe.py
1 from __future__
import unicode_literals
5 from .common
import InfoExtractor
15 class MetacafeIE(InfoExtractor
):
16 _VALID_URL
= r
'(?:http://)?(?:www\.)?metacafe\.com/watch/([^/]+)/([^/]+)/.*'
17 _DISCLAIMER
= 'http://www.metacafe.com/family_filter/'
18 _FILTER_POST
= 'http://www.metacafe.com/f/index.php?inputType=filter&controllerGroup=user'
23 'add_ie': ['Youtube'],
24 'url': 'http://metacafe.com/watch/yt-_aUehQsCQtM/the_electric_company_short_i_pbs_kids_go/',
28 'upload_date': '20090102',
29 'title': 'The Electric Company | \"Short I\" | PBS KIDS GO!',
30 'description': 'md5:2439a8ef6d5a70e380c22f5ad323e5a8',
35 # Normal metacafe video
37 'url': 'http://www.metacafe.com/watch/11121940/news_stuff_you_wont_do_with_your_playstation_4/',
38 'md5': '6e0bca200eaad2552e6915ed6fd4d9ad',
42 'title': 'News: Stuff You Won\'t Do with Your PlayStation 4',
44 'description': 'Sony released a massive FAQ on the PlayStation Blog detailing the PS4\'s capabilities and limitations.',
49 'url': 'http://www.metacafe.com/watch/an-dVVXnuY7Jh77J/the_andromeda_strain_1971_stop_the_bomb_part_3/',
51 'id': 'an-dVVXnuY7Jh77J',
53 'title': 'The Andromeda Strain (1971): Stop the Bomb Part 3',
54 'uploader': 'anyclip',
55 'description': 'md5:38c711dd98f5bb87acf973d573442e67',
58 # age-restricted video
60 'url': 'http://www.metacafe.com/watch/5186653/bbc_internal_christmas_tape_79_uncensored_outtakes_etc/',
61 'md5': '98dde7c1a35d02178e8ab7560fe8bd09',
65 'title': 'BBC INTERNAL Christmas Tape \'79 - UNCENSORED Outtakes, Etc.',
66 'uploader': 'Dwayne Pipe',
67 'description': 'md5:950bf4c581e2c059911fa3ffbe377e4b',
73 'url': 'http://www.metacafe.com/watch/cb-0rOxMBabDXN6/samsung_galaxy_note_2_samsungs_next_generation_phablet/',
77 'title': 'Samsung Galaxy Note 2: Samsung\'s next-generation phablet',
78 'description': 'md5:54d49fac53d26d5a0aaeccd061ada09d',
83 'skip_download': True,
88 def report_disclaimer(self
):
89 """Report disclaimer retrieval."""
90 self
.to_screen('Retrieving disclaimer')
92 def _real_initialize(self
):
94 self
.report_disclaimer()
95 self
._download
_webpage
(self
._DISCLAIMER
, None, False, 'Unable to retrieve disclaimer')
100 'submit': "Continue - I'm over 18",
102 request
= compat_urllib_request
.Request(self
._FILTER
_POST
, compat_urllib_parse
.urlencode(disclaimer_form
))
103 request
.add_header('Content-Type', 'application/x-www-form-urlencoded')
104 self
.report_age_confirmation()
105 self
._download
_webpage
(request
, None, False, 'Unable to confirm age')
107 def _real_extract(self
, url
):
108 # Extract id and simplified title from URL
109 mobj
= re
.match(self
._VALID
_URL
, url
)
111 raise ExtractorError('Invalid URL: %s' % url
)
113 video_id
= mobj
.group(1)
115 # the video may come from an external site
116 m_external
= re
.match('^(\w{2})-(.*)$', video_id
)
117 if m_external
is not None:
118 prefix
, ext_id
= m_external
.groups()
119 # Check if video comes from YouTube
121 return self
.url_result('http://www.youtube.com/watch?v=%s' % ext_id
, 'Youtube')
122 # CBS videos use theplatform.com
124 return self
.url_result('theplatform:%s' % ext_id
, 'ThePlatform')
126 # Retrieve video webpage to extract further information
127 req
= compat_urllib_request
.Request('http://www.metacafe.com/watch/%s/' % video_id
)
129 # AnyClip videos require the flashversion cookie so that we get the link
131 mobj_an
= re
.match(r
'^an-(.*?)$', video_id
)
133 req
.headers
['Cookie'] = 'flashVersion=0;'
134 webpage
= self
._download
_webpage
(req
, video_id
)
136 # Extract URL, uploader and title from webpage
137 self
.report_extraction(video_id
)
138 mobj
= re
.search(r
'(?m)&mediaURL=([^&]+)', webpage
)
140 mediaURL
= compat_urllib_parse
.unquote(mobj
.group(1))
141 video_ext
= mediaURL
[-3:]
143 # Extract gdaKey if available
144 mobj
= re
.search(r
'(?m)&gdaKey=(.*?)&', webpage
)
148 gdaKey
= mobj
.group(1)
149 video_url
= '%s?__gda__=%s' % (mediaURL
, gdaKey
)
151 mobj
= re
.search(r
'<video src="([^"]+)"', webpage
)
153 video_url
= mobj
.group(1)
156 mobj
= re
.search(r
' name="flashvars" value="(.*?)"', webpage
)
158 raise ExtractorError('Unable to extract media URL')
159 vardict
= compat_parse_qs(mobj
.group(1))
160 if 'mediaData' not in vardict
:
161 raise ExtractorError('Unable to extract media URL')
163 r
'"mediaURL":"(?P<mediaURL>http.*?)",(.*?)"key":"(?P<key>.*?)"', vardict
['mediaData'][0])
165 raise ExtractorError('Unable to extract media URL')
166 mediaURL
= mobj
.group('mediaURL').replace('\\/', '/')
167 video_url
= '%s?__gda__=%s' % (mediaURL
, mobj
.group('key'))
168 video_ext
= determine_ext(video_url
)
170 video_title
= self
._html
_search
_regex
(r
'(?im)<title>(.*) - Video</title>', webpage
, 'title')
171 description
= self
._og
_search
_description
(webpage
)
172 thumbnail
= self
._og
_search
_thumbnail
(webpage
)
173 video_uploader
= self
._html
_search
_regex
(
174 r
'submitter=(.*?);|googletag\.pubads\(\)\.setTargeting\("(?:channel|submiter)","([^"]+)"\);',
175 webpage
, 'uploader nickname', fatal
=False)
177 if re
.search(r
'"contentRating":"restricted"', webpage
) is not None:
185 'description': description
,
186 'uploader': video_uploader
,
187 'title': video_title
,
188 'thumbnail':thumbnail
,
190 'age_limit': age_limit
,