diff --git a/lib/svtplay_dl/service/__init__.py b/lib/svtplay_dl/service/__init__.py index aec977c..d1f5a88 100644 --- a/lib/svtplay_dl/service/__init__.py +++ b/lib/svtplay_dl/service/__init__.py @@ -2,9 +2,22 @@ # -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- from __future__ import absolute_import import re +from urlparse import urlparse class Service(object): - pass + supported_domains = [] + + def handle(self, url): + urlp = urlparse(url) + + if urlp.netloc in self.supported_domains: + return True + + # For every listed domain, try with www. subdomain as well. + if urlp.netloc in ['www.'+x for x in self.supported_domains]: + return True + + return False from svtplay_dl.service.aftonbladet import Aftonbladet from svtplay_dl.service.dr import Dr @@ -78,4 +91,4 @@ def service_handler(url): handler = i break - return handler \ No newline at end of file + return handler diff --git a/lib/svtplay_dl/service/aftonbladet.py b/lib/svtplay_dl/service/aftonbladet.py index 6130360..fdc8d7c 100644 --- a/lib/svtplay_dl/service/aftonbladet.py +++ b/lib/svtplay_dl/service/aftonbladet.py @@ -13,8 +13,7 @@ from svtplay_dl.fetcher.rtmp import download_rtmp from svtplay_dl.fetcher.http import download_http class Aftonbladet(Service): - def handle(self, url): - return "aftonbladet.se" in url + supported_domains = ['aftonbladet.se'] def get(self, options, url): parse = urlparse(url) diff --git a/lib/svtplay_dl/service/dr.py b/lib/svtplay_dl/service/dr.py index 351f415..52ffac8 100644 --- a/lib/svtplay_dl/service/dr.py +++ b/lib/svtplay_dl/service/dr.py @@ -12,8 +12,7 @@ from svtplay_dl.fetcher.hls import download_hls from svtplay_dl.log import log class Dr(Service): - def handle(self, url): - return "dr.dk" in url + supported_domains = ['dr.dk'] def get(self, options, url): data = get_http_data(url) diff --git a/lib/svtplay_dl/service/expressen.py b/lib/svtplay_dl/service/expressen.py index 2c1cbdc..7538197 100644 --- a/lib/svtplay_dl/service/expressen.py +++ b/lib/svtplay_dl/service/expressen.py @@ -13,8 +13,7 @@ from svtplay_dl.fetcher.rtmp import download_rtmp from svtplay_dl.utils.urllib import quote_plus class Expressen(Service): - def handle(self, url): - return "expressen.se" in url + supported_domains = ['expressen.se'] def get(self, options, url): data = get_http_data(url) diff --git a/lib/svtplay_dl/service/hbo.py b/lib/svtplay_dl/service/hbo.py index fccb408..8cfd1dc 100644 --- a/lib/svtplay_dl/service/hbo.py +++ b/lib/svtplay_dl/service/hbo.py @@ -12,8 +12,7 @@ from svtplay_dl.log import log from svtplay_dl.fetcher.rtmp import download_rtmp class Hbo(Service): - def handle(self, url): - return "hbo.com" in url + supported_domains = ['hbo.com'] def get(self, options, url): parse = urlparse(url) diff --git a/lib/svtplay_dl/service/justin.py b/lib/svtplay_dl/service/justin.py index b4c05e9..9c9ef5c 100644 --- a/lib/svtplay_dl/service/justin.py +++ b/lib/svtplay_dl/service/justin.py @@ -17,8 +17,7 @@ from svtplay_dl.fetcher.rtmp import download_rtmp from svtplay_dl.fetcher.http import download_http class Justin(Service): - def handle(self, url): - return ("twitch.tv" in url) or ("justin.tv" in url) + supported_domains = ['twitch.tv', 'justin.tv'] def get(self, options, url): parse = urlparse(url) diff --git a/lib/svtplay_dl/service/kanal5.py b/lib/svtplay_dl/service/kanal5.py index bc50030..29674a9 100644 --- a/lib/svtplay_dl/service/kanal5.py +++ b/lib/svtplay_dl/service/kanal5.py @@ -13,8 +13,7 @@ from svtplay_dl.fetcher.rtmp import download_rtmp from svtplay_dl.fetcher.hls import download_hls class Kanal5(Service): - def handle(self, url): - return ("kanal5play.se" in url) or ('kanal9play.se' in url) + supported_domains = ['kanal5play.se', 'kanal9play.se'] def get(self, options, url): cj = CookieJar() diff --git a/lib/svtplay_dl/service/mtvservices.py b/lib/svtplay_dl/service/mtvservices.py index 14e66c4..2471d79 100644 --- a/lib/svtplay_dl/service/mtvservices.py +++ b/lib/svtplay_dl/service/mtvservices.py @@ -10,8 +10,7 @@ from svtplay_dl.fetcher.http import download_http from svtplay_dl.log import log class Mtvservices(Service): - def handle(self, url): - return ("colbertnation.com" in url) or ("www.thedailyshow.com" in url) + supported_domains = ['colbertnation.com', 'thedailyshow.com'] def get(self, options, url): data = get_http_data(url) diff --git a/lib/svtplay_dl/service/nrk.py b/lib/svtplay_dl/service/nrk.py index f4b0582..cb525d9 100644 --- a/lib/svtplay_dl/service/nrk.py +++ b/lib/svtplay_dl/service/nrk.py @@ -10,8 +10,7 @@ from svtplay_dl.fetcher.hds import download_hds from svtplay_dl.fetcher.hls import download_hls class Nrk(Service): - def handle(self, url): - return "nrk.no" in url + supported_domains = ['nrk.no'] def get(self, options, url): data = get_http_data(url) diff --git a/lib/svtplay_dl/service/qbrick.py b/lib/svtplay_dl/service/qbrick.py index 9e02ab1..cc27b21 100644 --- a/lib/svtplay_dl/service/qbrick.py +++ b/lib/svtplay_dl/service/qbrick.py @@ -11,8 +11,7 @@ from svtplay_dl.log import log from svtplay_dl.fetcher.rtmp import download_rtmp class Qbrick(Service): - def handle(self, url): - return ("dn.se" in url) or ("di.se" in url) or ("svd.se" in url) or ("sydsvenskan.se" in url) + supported_domains = ['dn.se', 'di.se', 'svd.se', 'sydsvenskan.se'] def get(self, options, url): if re.findall(r"sydsvenskan.se", url): diff --git a/lib/svtplay_dl/service/radioplay.py b/lib/svtplay_dl/service/radioplay.py index add9cf5..14223f1 100644 --- a/lib/svtplay_dl/service/radioplay.py +++ b/lib/svtplay_dl/service/radioplay.py @@ -17,8 +17,7 @@ from svtplay_dl.fetcher.http import download_http from svtplay_dl.log import log class Radioplay(Service): - def handle(self, url): - return "radioplay.se" in url + supported_domains = ['radioplay.se'] def get(self, options, url): data = get_http_data(url) diff --git a/lib/svtplay_dl/service/ruv.py b/lib/svtplay_dl/service/ruv.py index 81ea7f7..145c2ea 100644 --- a/lib/svtplay_dl/service/ruv.py +++ b/lib/svtplay_dl/service/ruv.py @@ -8,8 +8,7 @@ from svtplay_dl.utils import get_http_data from svtplay_dl.fetcher.hls import download_hls class Ruv(Service): - def handle(self, url): - return "ruv.is" in url + supported_domains = ['ruv.is'] def get(self, options, url): data = get_http_data(url) diff --git a/lib/svtplay_dl/service/sr.py b/lib/svtplay_dl/service/sr.py index 3789e93..7cf3530 100644 --- a/lib/svtplay_dl/service/sr.py +++ b/lib/svtplay_dl/service/sr.py @@ -16,8 +16,7 @@ from svtplay_dl.log import log from svtplay_dl.fetcher.http import download_http class Sr(Service): - def handle(self, url): - return "sverigesradio.se" in url + supported_domains = ['sverigesradio.se'] def get(self, options, url): data = get_http_data(url) diff --git a/lib/svtplay_dl/service/svtplay.py b/lib/svtplay_dl/service/svtplay.py index 65bed54..e9b4f49 100644 --- a/lib/svtplay_dl/service/svtplay.py +++ b/lib/svtplay_dl/service/svtplay.py @@ -16,8 +16,7 @@ from svtplay_dl.fetcher.http import download_http from svtplay_dl.log import log class Svtplay(Service): - def handle(self, url): - return ("svtplay.se" in url) or ("svt.se" in url) or ("oppetarkiv.se" in url) + supported_domains = ['svtplay.se', 'svt.se', 'oppetarkiv.se'] def get(self, options, url): if re.findall("svt.se", url): diff --git a/lib/svtplay_dl/service/tests/service.py b/lib/svtplay_dl/service/tests/service.py new file mode 100644 index 0000000..c9e357f --- /dev/null +++ b/lib/svtplay_dl/service/tests/service.py @@ -0,0 +1,22 @@ +#!/usr/bin/python +# ex:ts=4:sw=4:sts=4:et +# -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- + +# The unittest framwork doesn't play nice with pylint: +# pylint: disable-msg=C0103 + +from __future__ import absolute_import +import unittest +import mock +from svtplay_dl.service import Service + +class MockService(Service): + supported_domains = ['example.com', 'example.net'] + +class ServiceTest(unittest.TestCase): + def test_supports(self): + service = MockService() + self.assertTrue(service.handle('http://example.com/video.swf?id=1')) + self.assertTrue(service.handle('http://example.net/video.swf?id=1')) + self.assertTrue(service.handle('http://www.example.com/video.swf?id=1')) + self.assertTrue(service.handle('http://www.example.net/video.swf?id=1')) diff --git a/lib/svtplay_dl/service/tv4play.py b/lib/svtplay_dl/service/tv4play.py index d827ac9..a065d04 100644 --- a/lib/svtplay_dl/service/tv4play.py +++ b/lib/svtplay_dl/service/tv4play.py @@ -13,8 +13,7 @@ from svtplay_dl.fetcher.rtmp import download_rtmp from svtplay_dl.fetcher.hds import download_hds class Tv4play(Service): - def handle(self, url): - return ("tv4play.se" in url) or ("tv4.se" in url) + supported_domains = ['tv4play.se', 'tv4.se'] def get(self, options, url): parse = urlparse(url) diff --git a/lib/svtplay_dl/service/urplay.py b/lib/svtplay_dl/service/urplay.py index 0b6b50b..4f38532 100644 --- a/lib/svtplay_dl/service/urplay.py +++ b/lib/svtplay_dl/service/urplay.py @@ -10,8 +10,7 @@ from svtplay_dl.fetcher.rtmp import download_rtmp from svtplay_dl.fetcher.hls import download_hls class Urplay(Service): - def handle(self, url): - return ("urplay.se" in url) or ("ur.se" in url) + supported_domains = ['urplay.se', 'ur.se'] def get(self, options, url): data = get_http_data(url) diff --git a/lib/svtplay_dl/service/viaplay.py b/lib/svtplay_dl/service/viaplay.py index 43f9bc9..09b6d4d 100644 --- a/lib/svtplay_dl/service/viaplay.py +++ b/lib/svtplay_dl/service/viaplay.py @@ -16,8 +16,8 @@ from svtplay_dl.log import log from svtplay_dl.fetcher.rtmp import download_rtmp class Viaplay(Service): - def handle(self, url): - return ("tv3play.se" in url) or ("tv6play.se" in url) or ("tv8play.se" in url) or ("tv10play.se" in url) + supported_domains = [ + 'tv3play.se', 'tv6play.se', 'tv8play.se', 'tv10play.se'] def get(self, options, url): parse = urlparse(url) diff --git a/lib/svtplay_dl/service/vimeo.py b/lib/svtplay_dl/service/vimeo.py index f152838..9e59ad5 100644 --- a/lib/svtplay_dl/service/vimeo.py +++ b/lib/svtplay_dl/service/vimeo.py @@ -11,8 +11,7 @@ from svtplay_dl.fetcher.http import download_http from svtplay_dl.log import log class Vimeo(Service): - def handle(self, url): - return "vimeo.com" in url + supported_domains = ['vimeo.com'] def get(self, options, url): data = get_http_data(url)