1
0
mirror of https://github.com/spaam/svtplay-dl.git synced 2024-11-28 06:04:17 +01:00

Merge pull request #91 from olof/topic/refactor_oppetarkiv

Break out OppetArkiv to subclass of Svtplay
This commit is contained in:
Johan Andersson 2014-05-01 20:13:48 +02:00
commit 8290cefc80
5 changed files with 66 additions and 35 deletions

View File

@ -99,6 +99,7 @@ from svtplay_dl.service.ruv import Ruv
from svtplay_dl.service.radioplay import Radioplay from svtplay_dl.service.radioplay import Radioplay
from svtplay_dl.service.sr import Sr from svtplay_dl.service.sr import Sr
from svtplay_dl.service.svtplay import Svtplay from svtplay_dl.service.svtplay import Svtplay
from svtplay_dl.service.oppetarkiv import OppetArkiv
from svtplay_dl.service.tv4play import Tv4play from svtplay_dl.service.tv4play import Tv4play
from svtplay_dl.service.urplay import Urplay from svtplay_dl.service.urplay import Urplay
from svtplay_dl.service.viaplay import Viaplay from svtplay_dl.service.viaplay import Viaplay
@ -122,6 +123,7 @@ sites = [
Radioplay, Radioplay,
Sr, Sr,
Svtplay, Svtplay,
OppetArkiv,
Tv4play, Tv4play,
Urplay, Urplay,
Viaplay, Viaplay,

View File

@ -0,0 +1,35 @@
# ex:ts=4:sw=4:sts=4:et
# -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-
from __future__ import absolute_import
import sys
import re
from svtplay_dl.service.svtplay import Svtplay
from svtplay_dl.log import log
class OppetArkiv(Svtplay):
supported_domains = ['oppetarkiv.se']
def find_all_episodes(self, options):
page = 1
match = re.search(r'"http://www.oppetarkiv.se/etikett/titel/([^"/]+)', self.get_urldata())
if match is None:
match = re.search(r'"http://www.oppetarkiv.se/etikett/titel/([^"/]+)', self.url)
if match is None:
log.error("Couldn't find title")
sys.exit(2)
program = match.group(1)
more = True
episodes = []
while more:
url = "http://www.oppetarkiv.se/etikett/titel/%s/?sida=%s&sort=tid_stigande&embed=true" % (program, page)
data = get_http_data(url)
visa = re.search(r'svtXColorDarkLightGrey', data)
if not visa:
more = False
regex = re.compile(r'(http://www.oppetarkiv.se/video/[^"]+)')
for match in regex.finditer(data):
episodes.append(match.group(1))
page += 1
return episodes

View File

@ -17,7 +17,7 @@ from svtplay_dl.fetcher.http import download_http
from svtplay_dl.log import log from svtplay_dl.log import log
class Svtplay(Service, OpenGraphThumbMixin): class Svtplay(Service, OpenGraphThumbMixin):
supported_domains = ['svtplay.se', 'svt.se', 'oppetarkiv.se', 'beta.svtplay.se', 'svtflow.se'] supported_domains = ['svtplay.se', 'svt.se', 'beta.svtplay.se', 'svtflow.se']
def __init__(self, url): def __init__(self, url):
Service.__init__(self, url) Service.__init__(self, url)
@ -119,32 +119,6 @@ class Svtplay(Service, OpenGraphThumbMixin):
def find_all_episodes(self, options): def find_all_episodes(self, options):
parse = urlparse(self.url)
if parse.netloc == "www.oppetarkiv.se":
page = 1
match = re.search(r'"http://www.oppetarkiv.se/etikett/titel/([^"/]+)', self.get_urldata())
if match is None:
match = re.search(r'"http://www.oppetarkiv.se/etikett/titel/([^"/]+)', self.url)
if match is None:
log.error("Couldn't find title")
sys.exit(2)
program = match.group(1)
more = True
episodes = []
while more:
url = "http://www.oppetarkiv.se/etikett/titel/%s/?sida=%s&sort=tid_stigande&embed=true" % (program, page)
data = get_http_data(url)
visa = re.search(r'svtXColorDarkLightGrey', data)
if not visa:
more = False
regex = re.compile(r'(http://www.oppetarkiv.se/video/[^"]+)')
for match in regex.finditer(data):
episodes.append(match.group(1))
page += 1
return episodes
else:
match = re.search(r'<link rel="alternate" type="application/rss\+xml" [^>]*href="([^"]+)"', match = re.search(r'<link rel="alternate" type="application/rss\+xml" [^>]*href="([^"]+)"',
self.get_urldata()) self.get_urldata())
if match is None: if match is None:

View File

@ -0,0 +1,20 @@
#!/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
from svtplay_dl.service.oppetarkiv import OppetArkiv
class handlesTest(unittest.TestCase):
def handles_oppetarkiv_se_test(self):
self.assertTrue(OppetArkiv.handles(
"http://www.oppetarkiv.se/video/1129844/jacobs-stege-avsnitt-1-av-1"))
def handles_svtplay_se_test(self):
self.assertFalse(OppetArkiv.handles(
"http://www.svtplay.se/video/1090393/del-9"))

View File

@ -20,7 +20,7 @@ class handlesTest(unittest.TestCase):
"http://www.svt.se/nyheter/sverige/det-ar-en-dodsfalla")) "http://www.svt.se/nyheter/sverige/det-ar-en-dodsfalla"))
def handles_oppetarkiv_se_test(self): def handles_oppetarkiv_se_test(self):
self.assertTrue(Svtplay.handles( self.assertFalse(Svtplay.handles(
"http://www.oppetarkiv.se/video/1129844/jacobs-stege-avsnitt-1-av-1")) "http://www.oppetarkiv.se/video/1129844/jacobs-stege-avsnitt-1-av-1"))
def handles_dn_se_test(self): def handles_dn_se_test(self):