From e4f320a4d044b690721016e36972cd547ee787d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaime=20Marqui=CC=81nez=20Ferra=CC=81ndiz?= Date: Tue, 21 Jan 2014 19:57:38 +0100 Subject: [PATCH] =?UTF-8?q?[mtv]=20Check=20for=20geo-blocked=20videos=20in?= =?UTF-8?q?=20the=20xml=20document,=20not=20in=20the=20xml=E2=80=99s=20str?= =?UTF-8?q?ing?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Allows to use the `_download_xml` method --- youtube_dl/extractor/mtv.py | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/youtube_dl/extractor/mtv.py b/youtube_dl/extractor/mtv.py index e24f22656..485c1fd7d 100644 --- a/youtube_dl/extractor/mtv.py +++ b/youtube_dl/extractor/mtv.py @@ -1,7 +1,6 @@ from __future__ import unicode_literals import re -import xml.etree.ElementTree from .common import InfoExtractor from ..utils import ( @@ -36,10 +35,9 @@ def _get_thumbnail_url(self, uri, itemdoc): else: return thumb_node.attrib['url'] - def _extract_video_formats(self, metadataXml): - if '/error_country_block.swf' in metadataXml: + 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) - mdoc = xml.etree.ElementTree.fromstring(metadataXml.encode('utf-8')) formats = [] for rendition in mdoc.findall('.//rendition'): @@ -65,8 +63,8 @@ def _get_video_info(self, itemdoc): mediagen_url = re.sub(r'&[^=]*?={.*?}(?=(&|$))', '', mediagen_url) if 'acceptMethods' not in mediagen_url: mediagen_url += '&acceptMethods=fms' - mediagen_page = self._download_webpage(mediagen_url, video_id, - 'Downloading video urls') + mediagen_doc = self._download_xml(mediagen_url, video_id, + 'Downloading video urls') description_node = itemdoc.find('description') if description_node is not None: @@ -76,7 +74,7 @@ def _get_video_info(self, itemdoc): return { 'title': itemdoc.find('title').text, - 'formats': self._extract_video_formats(mediagen_page), + 'formats': self._extract_video_formats(mediagen_doc), 'id': video_id, 'thumbnail': self._get_thumbnail_url(uri, itemdoc), 'description': description,