From 8c3665f5de32fe0adedd72c06d7de23a7f844ec2 Mon Sep 17 00:00:00 2001 From: RPing Date: Wed, 18 Nov 2015 17:54:40 +0800 Subject: [PATCH] enhance test cases and fix UDN style --- test/unittest_all_urls.py | 11 ++++++----- youtube_dl/extractor/__init__.py | 5 +---- youtube_dl/extractor/generic.py | 2 +- youtube_dl/extractor/udn.py | 13 +++++-------- 4 files changed, 13 insertions(+), 18 deletions(-) diff --git a/test/unittest_all_urls.py b/test/unittest_all_urls.py index 2872c05e9..162853925 100644 --- a/test/unittest_all_urls.py +++ b/test/unittest_all_urls.py @@ -70,7 +70,6 @@ class TestAllURLsMatching(unittest.TestCase): def test_youtube_search_matching(self): self.assertMatch('http://www.youtube.com/results?search_query=making+mustard', ['youtube:search_url']) self.assertMatch('https://www.youtube.com/results?baz=bar&search_query=youtube-dl+test+video&filters=video&lclk=video', ['youtube:search_url']) - self.assertMatch('https://www.youtube.com/results?lclk=week&search_query=making+mustard&filters=week', ['youtube:search:date']) def test_youtube_extract(self): assertExtractId = lambda url, id: self.assertEqual(YoutubeIE.extract_id(url), id) @@ -139,10 +138,10 @@ class TestAllURLsMatching(unittest.TestCase): self.assertMatch('http://news.cts.com.tw/cts/life/201511/201511151683198.html#.VkssxbNZOHs', ['CtsNews']) self.assertMatch('http://news.cts.com.tw/cts/international/201511/201511171683689.html#.Vksv_bNZOHs', ['CtsNews']) - def test_UDN(self): + def test_udn(self): self.assertMatch('https://video.udn.com/news/398685', ['UDN']) - self.assertMatch('https://video.udn.com/embed/news/300040', ['UDNEmbed']) - self.assertMatch('https://video.udn.com/play/news/303776', ['UDNEmbed']) + self.assertMatch('https://video.udn.com/embed/news/300040', ['UDN']) + self.assertMatch('https://video.udn.com/play/news/303776', ['UDN']) def test_xuite(self): self.assertMatch('http://vlog.xuite.net/play/T2lMdGpZLTk0NDA1MS5mbHY=', ['Xuite']) @@ -153,7 +152,9 @@ class TestAllURLsMatching(unittest.TestCase): def test_mlb(self): self.assertMatch('http://m.mlb.com/video/topic/9674738/v529001783/111015-mlbcom-fastcast-gold-gloves-announced', ['MLB']) - + self.assertMatch('http://mlb.mlb.com/shared/video/embed/m-internal-embed.html?content_id=75609783&property=mlb&autoplay=true&hashmode=false&siteSection=mlb/multimedia/article_118550098/article_embed&club=mlb', ['MLB']) + self.assertMatch('http://washington.nationals.mlb.com/mlb/gameday/index.jsp?c_id=was&gid=2015_05_09_atlmlb_wasmlb_1&lang=en&content_id=108309983&mode=video#', ['MLB']) + self.assertMatch('http://m.mlb.com/video/v34577915/bautista-on-derby-captaining-duties-his-performance', ['MLB']) if __name__ == '__main__': unittest.main() diff --git a/youtube_dl/extractor/__init__.py b/youtube_dl/extractor/__init__.py index c0665c0e7..bceaa978f 100644 --- a/youtube_dl/extractor/__init__.py +++ b/youtube_dl/extractor/__init__.py @@ -706,10 +706,7 @@ from .udemy import ( UdemyIE, UdemyCourseIE ) -from .udn import ( - UDNEmbedIE, - UDNIE -) +from .udn import UDNIE from .ultimedia import UltimediaIE from .unistra import UnistraIE from .urort import UrortIE diff --git a/youtube_dl/extractor/generic.py b/youtube_dl/extractor/generic.py index 51516a38a..619fcfe86 100644 --- a/youtube_dl/extractor/generic.py +++ b/youtube_dl/extractor/generic.py @@ -42,7 +42,7 @@ from .sportbox import SportBoxEmbedIE from .smotri import SmotriIE from .myvi import MyviIE from .condenast import CondeNastIE -from .udn import UDNEmbedIE +from .udn import UDNIE from .senateisvp import SenateISVPIE from .bliptv import BlipTVIE from .svt import SVTIE diff --git a/youtube_dl/extractor/udn.py b/youtube_dl/extractor/udn.py index 852f9cad0..346ea13a4 100644 --- a/youtube_dl/extractor/udn.py +++ b/youtube_dl/extractor/udn.py @@ -10,9 +10,9 @@ from ..utils import ( from ..compat import compat_urlparse -class UDNEmbedIE(InfoExtractor): +class UDNIE(InfoExtractor): IE_DESC = '聯合影音' - _VALID_URL = r'https?://video\.udn\.com/(?:embed|play)/news/(?P\d+)' + _VALID_URL = r'https?://video\.udn\.com/((?:embed|play)/)?news/(?P\d+)' _TESTS = [{ 'url': 'http://video.udn.com/embed/news/300040', 'md5': 'de06b4c90b042c128395a88f0384817e', @@ -32,12 +32,12 @@ class UDNEmbedIE(InfoExtractor): }] def _real_extract(self, url): - video_id = self._match_id(url) - - if isinstance(self, UDNIE): + if "embed" not in url and "play" not in url: p = url.index("com/") + 4 url = url[:p] + "embed/" + url[p:] + video_id = self._match_id(url) + page = self._download_webpage(url, video_id) options = json.loads(js_to_json(self._html_search_regex( @@ -77,6 +77,3 @@ class UDNEmbedIE(InfoExtractor): 'title': options['title'], 'thumbnail': thumbnail } - -class UDNIE(UDNEmbedIE): - _VALID_URL = r'https?://video\.udn\.com/news/(?P\d+)'