]>
Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/metacafe.py
4 from .common
import InfoExtractor
10 compat_urllib_request
,
16 class MetacafeIE(InfoExtractor
):
17 """Information Extractor for metacafe.com."""
19 _VALID_URL
= r
'(?:http://)?(?:www\.)?metacafe\.com/watch/([^/]+)/([^/]+)/.*'
20 _DISCLAIMER
= 'http://www.metacafe.com/family_filter/'
21 _FILTER_POST
= 'http://www.metacafe.com/f/index.php?inputType=filter&controllerGroup=user'
26 u
"add_ie": ["Youtube"],
27 u
"url": u
"http://metacafe.com/watch/yt-_aUehQsCQtM/the_electric_company_short_i_pbs_kids_go/",
28 u
"file": u
"_aUehQsCQtM.mp4",
30 u
"upload_date": u
"20090102",
31 u
"title": u
"The Electric Company | \"Short I\" | PBS KIDS GO!",
32 u
"description": u
"md5:2439a8ef6d5a70e380c22f5ad323e5a8",
34 u
"uploader_id": u
"PBS"
37 # Normal metacafe video
39 u
'url': u
'http://www.metacafe.com/watch/11121940/news_stuff_you_wont_do_with_your_playstation_4/',
40 u
'md5': u
'6e0bca200eaad2552e6915ed6fd4d9ad',
44 u
'title': u
'News: Stuff You Won\'t Do with Your PlayStation 4',
46 u
'description': u
'Sony released a massive FAQ on the PlayStation Blog detailing the PS4\'s capabilities and limitations.',
51 u
"url": u
"http://www.metacafe.com/watch/an-dVVXnuY7Jh77J/the_andromeda_strain_1971_stop_the_bomb_part_3/",
52 u
"file": u
"an-dVVXnuY7Jh77J.mp4",
54 u
"title": u
"The Andromeda Strain (1971): Stop the Bomb Part 3",
55 u
"uploader": u
"anyclip",
56 u
"description": u
"md5:38c711dd98f5bb87acf973d573442e67",
59 # age-restricted video
61 u
'url': u
'http://www.metacafe.com/watch/5186653/bbc_internal_christmas_tape_79_uncensored_outtakes_etc/',
62 u
'md5': u
'98dde7c1a35d02178e8ab7560fe8bd09',
66 u
'title': u
'BBC INTERNAL Christmas Tape \'79 - UNCENSORED Outtakes, Etc.',
67 u
'uploader': u
'Dwayne Pipe',
68 u
'description': u
'md5:950bf4c581e2c059911fa3ffbe377e4b',
75 def report_disclaimer(self
):
76 """Report disclaimer retrieval."""
77 self
.to_screen(u
'Retrieving disclaimer')
79 def _real_initialize(self
):
81 request
= compat_urllib_request
.Request(self
._DISCLAIMER
)
83 self
.report_disclaimer()
84 compat_urllib_request
.urlopen(request
).read()
85 except (compat_urllib_error
.URLError
, compat_http_client
.HTTPException
, socket
.error
) as err
:
86 raise ExtractorError(u
'Unable to retrieve disclaimer: %s' % compat_str(err
))
91 'submit': "Continue - I'm over 18",
93 request
= compat_urllib_request
.Request(self
._FILTER
_POST
, compat_urllib_parse
.urlencode(disclaimer_form
))
94 request
.add_header('Content-Type', 'application/x-www-form-urlencoded')
96 self
.report_age_confirmation()
97 compat_urllib_request
.urlopen(request
).read()
98 except (compat_urllib_error
.URLError
, compat_http_client
.HTTPException
, socket
.error
) as err
:
99 raise ExtractorError(u
'Unable to confirm age: %s' % compat_str(err
))
101 def _real_extract(self
, url
):
102 # Extract id and simplified title from URL
103 mobj
= re
.match(self
._VALID
_URL
, url
)
105 raise ExtractorError(u
'Invalid URL: %s' % url
)
107 video_id
= mobj
.group(1)
109 # Check if video comes from YouTube
110 mobj2
= re
.match(r
'^yt-(.*)$', video_id
)
111 if mobj2
is not None:
112 return [self
.url_result('http://www.youtube.com/watch?v=%s' % mobj2
.group(1), 'Youtube')]
114 # Retrieve video webpage to extract further information
115 req
= compat_urllib_request
.Request('http://www.metacafe.com/watch/%s/' % video_id
)
117 # AnyClip videos require the flashversion cookie so that we get the link
119 mobj_an
= re
.match(r
'^an-(.*?)$', video_id
)
121 req
.headers
['Cookie'] = 'flashVersion=0;'
122 webpage
= self
._download
_webpage
(req
, video_id
)
124 # Extract URL, uploader and title from webpage
125 self
.report_extraction(video_id
)
126 mobj
= re
.search(r
'(?m)&mediaURL=([^&]+)', webpage
)
128 mediaURL
= compat_urllib_parse
.unquote(mobj
.group(1))
129 video_ext
= mediaURL
[-3:]
131 # Extract gdaKey if available
132 mobj
= re
.search(r
'(?m)&gdaKey=(.*?)&', webpage
)
136 gdaKey
= mobj
.group(1)
137 video_url
= '%s?__gda__=%s' % (mediaURL
, gdaKey
)
139 mobj
= re
.search(r
'<video src="([^"]+)"', webpage
)
141 video_url
= mobj
.group(1)
144 mobj
= re
.search(r
' name="flashvars" value="(.*?)"', webpage
)
146 raise ExtractorError(u
'Unable to extract media URL')
147 vardict
= compat_parse_qs(mobj
.group(1))
148 if 'mediaData' not in vardict
:
149 raise ExtractorError(u
'Unable to extract media URL')
150 mobj
= re
.search(r
'"mediaURL":"(?P<mediaURL>http.*?)",(.*?)"key":"(?P<key>.*?)"', vardict
['mediaData'][0])
152 raise ExtractorError(u
'Unable to extract media URL')
153 mediaURL
= mobj
.group('mediaURL').replace('\\/', '/')
154 video_url
= '%s?__gda__=%s' % (mediaURL
, mobj
.group('key'))
155 video_ext
= determine_ext(video_url
)
157 video_title
= self
._html
_search
_regex
(r
'(?im)<title>(.*) - Video</title>', webpage
, u
'title')
158 description
= self
._og
_search
_description
(webpage
)
159 video_uploader
= self
._html
_search
_regex
(
160 r
'submitter=(.*?);|googletag\.pubads\(\)\.setTargeting\("(?:channel|submiter)","([^"]+)"\);',
161 webpage
, u
'uploader nickname', fatal
=False)
163 if re
.search(r
'"contentRating":"restricted"', webpage
) is not None:
172 'description': description
,
173 'uploader': video_uploader
,
175 'title': video_title
,
177 'age_limit': age_limit
,