]>
Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/mtv.py
a801c8123eb66d153e1752ccb7d1fbc1e0ac7ee6
3 import xml
.etree
.ElementTree
5 from .common
import InfoExtractor
10 compat_urllib_request
,
16 class MTVIE(InfoExtractor
):
17 _VALID_URL
= r
'^(?P<proto>https?://)?(?:www\.)?mtv\.com/videos/[^/]+/(?P<videoid>[0-9]+)/[^/]+$'
20 def _real_extract(self
, url
):
21 mobj
= re
.match(self
._VALID
_URL
, url
)
23 raise ExtractorError(u
'Invalid URL: %s' % url
)
24 if not mobj
.group('proto'):
26 video_id
= mobj
.group('videoid')
28 webpage
= self
._download
_webpage
(url
, video_id
)
30 #song_name = self._html_search_regex(r'<meta name="mtv_vt" content="([^"]+)"/>',
31 # webpage, u'song name', fatal=False)
33 video_title
= self
._html
_search
_regex
(r
'<meta name="mtv_an" content="([^"]+)"/>',
36 mtvn_uri
= self
._html
_search
_regex
(r
'<meta name="mtvn_uri" content="([^"]+)"/>',
37 webpage
, u
'mtvn_uri', fatal
=False)
39 content_id
= self
._search
_regex
(r
'MTVN.Player.defaultPlaylistId = ([0-9]+);',
40 webpage
, u
'content id', fatal
=False)
42 videogen_url
= 'http://www.mtv.com/player/includes/mediaGen.jhtml?uri=' + mtvn_uri
+ '&id=' + content_id
+ '&vid=' + video_id
+ '&ref=www.mtvn.com&viewUri=' + mtvn_uri
43 self
.report_extraction(video_id
)
44 request
= compat_urllib_request
.Request(videogen_url
)
46 metadataXml
= compat_urllib_request
.urlopen(request
).read()
47 except (compat_urllib_error
.URLError
, compat_http_client
.HTTPException
, socket
.error
) as err
:
48 raise ExtractorError(u
'Unable to download video metadata: %s' % compat_str(err
))
50 mdoc
= xml
.etree
.ElementTree
.fromstring(metadataXml
)
51 renditions
= mdoc
.findall('.//rendition')
53 # For now, always pick the highest quality.
54 rendition
= renditions
[-1]
57 _
,_
,ext
= rendition
.attrib
['type'].partition('/')
58 format
= ext
+ '-' + rendition
.attrib
['width'] + 'x' + rendition
.attrib
['height'] + '_' + rendition
.attrib
['bitrate']
59 video_url
= rendition
.find('./src').text
61 raise ExtractorError('Invalid rendition field.')