]>
Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/mtv.py
2 import xml
.etree
.ElementTree
4 from .common
import InfoExtractor
10 def _media_xml_tag(tag
):
11 return '{http://search.yahoo.com/mrss/}%s' % tag
14 class MTVServicesInfoExtractor(InfoExtractor
):
16 def _id_from_uri(uri
):
17 return uri
.split(':')[-1]
19 # This was originally implemented for ComedyCentral, but it also works here
21 def _transform_rtmp_url(rtmp_video_url
):
22 m
= re
.match(r
'^rtmpe?://.*?/(?P<finalid>gsp\..+?/.*)$', rtmp_video_url
)
25 base
= 'http://mtvnmobile.vo.llnwd.net/kip0/_pxn=1+_pxI0=Ripod-h264+_pxL0=undefined+_pxM0=+_pxK=18639+_pxE=mp4/44620/mtvnorigin/'
26 return base
+ m
.group('finalid')
28 def _get_thumbnail_url(self
, uri
, itemdoc
):
29 search_path
= '%s/%s' % (_media_xml_tag('group'), _media_xml_tag('thumbnail'))
30 thumb_node
= itemdoc
.find(search_path
)
31 if thumb_node
is None:
34 return thumb_node
.attrib
['url']
36 def _extract_video_formats(self
, metadataXml
):
37 if '/error_country_block.swf' in metadataXml
:
38 raise ExtractorError(u
'This video is not available from your country.', expected
=True)
39 mdoc
= xml
.etree
.ElementTree
.fromstring(metadataXml
.encode('utf-8'))
42 for rendition
in mdoc
.findall('.//rendition'):
44 _
, _
, ext
= rendition
.attrib
['type'].partition('/')
45 rtmp_video_url
= rendition
.find('./src').text
46 formats
.append({'ext': ext
,
47 'url': self
._transform
_rtmp
_url
(rtmp_video_url
),
48 'format_id': rendition
.get('bitrate'),
49 'width': int(rendition
.get('width')),
50 'height': int(rendition
.get('height')),
52 except (KeyError, TypeError):
53 raise ExtractorError('Invalid rendition field.')
56 def _get_video_info(self
, itemdoc
):
57 uri
= itemdoc
.find('guid').text
58 video_id
= self
._id
_from
_uri
(uri
)
59 self
.report_extraction(video_id
)
60 mediagen_url
= itemdoc
.find('%s/%s' % (_media_xml_tag('group'), _media_xml_tag('content'))).attrib
['url']
61 # Remove the templates, like &device={device}
62 mediagen_url
= re
.sub(r
'&[^=]*?={.*?}(?=(&|$))', u
'', mediagen_url
)
63 if 'acceptMethods' not in mediagen_url
:
64 mediagen_url
+= '&acceptMethods=fms'
65 mediagen_page
= self
._download
_webpage
(mediagen_url
, video_id
,
66 u
'Downloading video urls')
68 description_node
= itemdoc
.find('description')
69 if description_node
is not None:
70 description
= description_node
.text
.strip()
75 'title': itemdoc
.find('title').text
,
76 'formats': self
._extract
_video
_formats
(mediagen_page
),
78 'thumbnail': self
._get
_thumbnail
_url
(uri
, itemdoc
),
79 'description': description
,
82 def _get_videos_info(self
, uri
):
83 video_id
= self
._id
_from
_uri
(uri
)
84 data
= compat_urllib_parse
.urlencode({'uri': uri
})
85 idoc
= self
._download
_xml
(self
._FEED
_URL
+'?' + data
, video_id
,
87 return [self
._get
_video
_info
(item
) for item
in idoc
.findall('.//item')]
90 class MTVIE(MTVServicesInfoExtractor
):
91 _VALID_URL
= r
'^https?://(?:www\.)?mtv\.com/videos/.+?/(?P<videoid>[0-9]+)/[^/]+$'
93 _FEED_URL
= 'http://www.mtv.com/player/embed/AS3/rss/'
97 u
'url': u
'http://www.mtv.com/videos/misc/853555/ours-vh1-storytellers.jhtml',
98 u
'file': u
'853555.mp4',
99 u
'md5': u
'850f3f143316b1e71fa56a4edfd6e0f8',
101 u
'title': u
'Taylor Swift - "Ours (VH1 Storytellers)"',
102 u
'description': u
'Album: Taylor Swift performs "Ours" for VH1 Storytellers at Harvey Mudd College.',
107 u
'url': u
'http://www.mtv.com/videos/taylor-swift/916187/everything-has-changed-ft-ed-sheeran.jhtml',
108 u
'file': u
'USCJY1331283.mp4',
109 u
'md5': u
'73b4e7fcadd88929292fe52c3ced8caf',
111 u
'title': u
'Everything Has Changed',
112 u
'upload_date': u
'20130606',
113 u
'uploader': u
'Taylor Swift',
115 u
'skip': u
'VEVO is only available in some countries',
119 def _get_thumbnail_url(self
, uri
, itemdoc
):
120 return 'http://mtv.mtvnimages.com/uri/' + uri
122 def _real_extract(self
, url
):
123 mobj
= re
.match(self
._VALID
_URL
, url
)
124 video_id
= mobj
.group('videoid')
126 webpage
= self
._download
_webpage
(url
, video_id
)
128 # Some videos come from Vevo.com
129 m_vevo
= re
.search(r
'isVevoVideo = true;.*?vevoVideoId = "(.*?)";',
132 vevo_id
= m_vevo
.group(1);
133 self
.to_screen(u
'Vevo video detected: %s' % vevo_id
)
134 return self
.url_result('vevo:%s' % vevo_id
, ie
='Vevo')
136 uri
= self
._html
_search
_regex
(r
'/uri/(.*?)\?', webpage
, u
'uri')
137 return self
._get
_videos
_info
(uri
)