diff options
author | Philipp Hagemeister <phihag@phihag.de> | 2014-03-09 18:08:16 +0100 |
---|---|---|
committer | Philipp Hagemeister <phihag@phihag.de> | 2014-03-09 18:08:16 +0100 |
commit | 9e55e37a2e0e3a4e7d3fac2efd4ea13efe689b0e (patch) | |
tree | d77de1b25da3c63f93142fc3fa781e2872965b72 /youtube_dl/extractor/mtv.py | |
parent | a4ff6c4762fd01b606d54a2962530c753d4c52ec (diff) | |
parent | 14719565733c114320e99228cf2dc570f8c3b6dc (diff) | |
download | youtube-dl-9e55e37a2e0e3a4e7d3fac2efd4ea13efe689b0e.tar.xz |
Merge remote-tracking branch 'origin/master'
Diffstat (limited to 'youtube_dl/extractor/mtv.py')
-rw-r--r-- | youtube_dl/extractor/mtv.py | 39 |
1 files changed, 35 insertions, 4 deletions
diff --git a/youtube_dl/extractor/mtv.py b/youtube_dl/extractor/mtv.py index 5447b6c0c..d75241d3f 100644 --- a/youtube_dl/extractor/mtv.py +++ b/youtube_dl/extractor/mtv.py @@ -5,9 +5,12 @@ import re from .common import InfoExtractor from ..utils import ( compat_urllib_parse, + compat_urllib_request, ExtractorError, find_xpath_attr, fix_xml_ampersands, + HEADRequest, + unescapeHTML, url_basename, RegexNotFoundError, ) @@ -18,6 +21,7 @@ def _media_xml_tag(tag): class MTVServicesInfoExtractor(InfoExtractor): + _MOBILE_TEMPLATE = None @staticmethod def _id_from_uri(uri): return uri.split(':')[-1] @@ -39,9 +43,29 @@ class MTVServicesInfoExtractor(InfoExtractor): else: return thumb_node.attrib['url'] - def _extract_video_formats(self, mdoc): - if re.match(r'.*/error_country_block\.swf$', mdoc.find('.//src').text) is not None: - raise ExtractorError('This video is not available from your country.', expected=True) + def _extract_mobile_video_formats(self, mtvn_id): + webpage_url = self._MOBILE_TEMPLATE % mtvn_id + req = compat_urllib_request.Request(webpage_url) + # Otherwise we get a webpage that would execute some javascript + req.add_header('Youtubedl-user-agent', 'curl/7') + webpage = self._download_webpage(req, mtvn_id, + 'Downloading mobile page') + metrics_url = unescapeHTML(self._search_regex(r'<a href="(http://metrics.+?)"', webpage, 'url')) + req = HEADRequest(metrics_url) + response = self._request_webpage(req, mtvn_id, 'Resolving url') + url = response.geturl() + # Transform the url to get the best quality: + url = re.sub(r'.+pxE=mp4', 'http://mtvnmobile.vo.llnwd.net/kip0/_pxn=0+_pxK=18639+_pxE=mp4', url, 1) + return [{'url': url,'ext': 'mp4'}] + + def _extract_video_formats(self, mdoc, mtvn_id): + if re.match(r'.*/(error_country_block\.swf|geoblock\.mp4)$', mdoc.find('.//src').text) is not None: + if mtvn_id is not None and self._MOBILE_TEMPLATE is not None: + self.to_screen('The normal version is not available from your ' + 'country, trying with the mobile version') + return self._extract_mobile_video_formats(mtvn_id) + raise ExtractorError('This video is not available from your country.', + expected=True) formats = [] for rendition in mdoc.findall('.//rendition'): @@ -94,9 +118,16 @@ class MTVServicesInfoExtractor(InfoExtractor): raise ExtractorError('Could not find video title') title = title.strip() + # This a short id that's used in the webpage urls + mtvn_id = None + mtvn_id_node = find_xpath_attr(itemdoc, './/{http://search.yahoo.com/mrss/}category', + 'scheme', 'urn:mtvn:id') + if mtvn_id_node is not None: + mtvn_id = mtvn_id_node.text + return { 'title': title, - 'formats': self._extract_video_formats(mediagen_doc), + 'formats': self._extract_video_formats(mediagen_doc, mtvn_id), 'id': video_id, 'thumbnail': self._get_thumbnail_url(uri, itemdoc), 'description': description, |