mirror of
https://github.com/spaam/svtplay-dl.git
synced 2024-11-28 06:04:17 +01:00
Add default handle method in Service base class
The default handle method will look for a supported_domains attribute (a list), containing the supported domains. The subclassed service class can of course override this if other means of determining support is needded.
This commit is contained in:
parent
dfeadd152c
commit
9f9bcad0c7
@ -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
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
@ -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()
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
@ -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):
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
@ -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):
|
||||
|
22
lib/svtplay_dl/service/tests/service.py
Normal file
22
lib/svtplay_dl/service/tests/service.py
Normal file
@ -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'))
|
@ -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)
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user