]>
jfr.im git - yt-dlp.git/blob - youtube_dl/extractor/mtv.py
485c1fd7d02dd6920de2fae7d8dbca4d76bdf475
1 from __future__
import unicode_literals
5 from .common
import InfoExtractor
12 def _media_xml_tag(tag
):
13 return '{http://search.yahoo.com/mrss/}%s' % tag
16 class MTVServicesInfoExtractor(InfoExtractor
):
18 def _id_from_uri(uri
):
19 return uri
.split(':')[-1]
21 # This was originally implemented for ComedyCentral, but it also works here
23 def _transform_rtmp_url(rtmp_video_url
):
24 m
= re
.match(r
'^rtmpe?://.*?/(?P<finalid>gsp\..+?/.*)$', rtmp_video_url
)
27 base
= 'http://mtvnmobile.vo.llnwd.net/kip0/_pxn=1+_pxI0=Ripod-h264+_pxL0=undefined+_pxM0=+_pxK=18639+_pxE=mp4/44620/mtvnorigin/'
28 return base
+ m
.group('finalid')
30 def _get_thumbnail_url(self
, uri
, itemdoc
):
31 search_path
= '%s/%s' % (_media_xml_tag('group'), _media_xml_tag('thumbnail'))
32 thumb_node
= itemdoc
.find(search_path
)
33 if thumb_node
is None:
36 return thumb_node
.attrib
['url']
38 def _extract_video_formats(self
, mdoc
):
39 if re
.match(r
'.*/error_country_block\.swf$', mdoc
.find('.//src').text
) is not None:
40 raise ExtractorError('This video is not available from your country.', expected
=True)
43 for rendition
in mdoc
.findall('.//rendition'):
45 _
, _
, ext
= rendition
.attrib
['type'].partition('/')
46 rtmp_video_url
= rendition
.find('./src').text
47 formats
.append({'ext': ext
,
48 'url': self
._transform
_rtmp
_url
(rtmp_video_url
),
49 'format_id': rendition
.get('bitrate'),
50 'width': int(rendition
.get('width')),
51 'height': int(rendition
.get('height')),
53 except (KeyError, TypeError):
54 raise ExtractorError('Invalid rendition field.')
57 def _get_video_info(self
, itemdoc
):
58 uri
= itemdoc
.find('guid').text
59 video_id
= self
._id
_from
_uri
(uri
)
60 self
.report_extraction(video_id
)
61 mediagen_url
= itemdoc
.find('%s/%s' % (_media_xml_tag('group'), _media_xml_tag('content'))).attrib
['url']
62 # Remove the templates, like &device={device}
63 mediagen_url
= re
.sub(r
'&[^=]*?={.*?}(?=(&|$))', '', mediagen_url
)
64 if 'acceptMethods' not in mediagen_url
:
65 mediagen_url
+= '&acceptMethods=fms'
66 mediagen_doc
= self
._download
_xml
(mediagen_url
, video_id
,
67 'Downloading video urls')
69 description_node
= itemdoc
.find('description')
70 if description_node
is not None:
71 description
= description_node
.text
.strip()
76 'title': itemdoc
.find('title').text
,
77 'formats': self
._extract
_video
_formats
(mediagen_doc
),
79 'thumbnail': self
._get
_thumbnail
_url
(uri
, itemdoc
),
80 'description': description
,
83 def _get_videos_info(self
, uri
):
84 video_id
= self
._id
_from
_uri
(uri
)
85 data
= compat_urllib_parse
.urlencode({'uri': uri}
)
87 idoc
= self
._download
_xml
(
88 self
._FEED
_URL
+ '?' + data
, video_id
,
89 'Downloading info', transform_source
=fix_xml_ampersands
)
90 return [self
._get
_video
_info
(item
) for item
in idoc
.findall('.//item')]
93 class MTVIE(MTVServicesInfoExtractor
):
94 _VALID_URL
= r
'''(?x)^https?://
95 (?:(?:www\.)?mtv\.com/videos/.+?/(?P<videoid>[0-9]+)/[^/]+$|
96 m\.mtv\.com/videos/video\.rbml\?.*?id=(?P<mgid>[^&]+))'''
98 _FEED_URL
= 'http://www.mtv.com/player/embed/AS3/rss/'
102 'url': 'http://www.mtv.com/videos/misc/853555/ours-vh1-storytellers.jhtml',
103 'file': '853555.mp4',
104 'md5': '850f3f143316b1e71fa56a4edfd6e0f8',
106 'title': 'Taylor Swift - "Ours (VH1 Storytellers)"',
107 'description': 'Album: Taylor Swift performs "Ours" for VH1 Storytellers at Harvey Mudd College.',
112 'url': 'http://www.mtv.com/videos/taylor-swift/916187/everything-has-changed-ft-ed-sheeran.jhtml',
113 'file': 'USCJY1331283.mp4',
114 'md5': '73b4e7fcadd88929292fe52c3ced8caf',
116 'title': 'Everything Has Changed',
117 'upload_date': '20130606',
118 'uploader': 'Taylor Swift',
120 'skip': 'VEVO is only available in some countries',
124 def _get_thumbnail_url(self
, uri
, itemdoc
):
125 return 'http://mtv.mtvnimages.com/uri/' + uri
127 def _real_extract(self
, url
):
128 mobj
= re
.match(self
._VALID
_URL
, url
)
129 video_id
= mobj
.group('videoid')
130 uri
= mobj
.groupdict().get('mgid')
132 webpage
= self
._download
_webpage
(url
, video_id
)
134 # Some videos come from Vevo.com
135 m_vevo
= re
.search(r
'isVevoVideo = true;.*?vevoVideoId = "(.*?)";',
138 vevo_id
= m_vevo
.group(1);
139 self
.to_screen('Vevo video detected: %s' % vevo_id
)
140 return self
.url_result('vevo:%s' % vevo_id
, ie
='Vevo')
142 uri
= self
._html
_search
_regex
(r
'/uri/(.*?)\?', webpage
, 'uri')
143 return self
._get
_videos
_info
(uri
)