From f331a653b6e08219ab8bc61c4f7ede83b68e88fc Mon Sep 17 00:00:00 2001 From: Anders Waldenborg Date: Mon, 6 Jan 2014 23:14:06 +0100 Subject: [PATCH] Move url to object attribute --- lib/svtplay_dl/__init__.py | 2 +- lib/svtplay_dl/service/__init__.py | 11 +++++++---- lib/svtplay_dl/service/aftonbladet.py | 6 +++--- lib/svtplay_dl/service/dr.py | 4 ++-- lib/svtplay_dl/service/expressen.py | 4 ++-- lib/svtplay_dl/service/hbo.py | 4 ++-- lib/svtplay_dl/service/justin.py | 4 ++-- lib/svtplay_dl/service/kanal5.py | 4 ++-- lib/svtplay_dl/service/mtvservices.py | 4 ++-- lib/svtplay_dl/service/nrk.py | 6 +++--- lib/svtplay_dl/service/qbrick.py | 18 +++++++++--------- lib/svtplay_dl/service/radioplay.py | 6 +++--- lib/svtplay_dl/service/ruv.py | 4 ++-- lib/svtplay_dl/service/sr.py | 6 +++--- lib/svtplay_dl/service/svtplay.py | 8 +++++--- lib/svtplay_dl/service/tv4play.py | 10 +++++----- lib/svtplay_dl/service/urplay.py | 6 +++--- lib/svtplay_dl/service/viaplay.py | 4 ++-- lib/svtplay_dl/service/vimeo.py | 4 ++-- 19 files changed, 60 insertions(+), 55 deletions(-) diff --git a/lib/svtplay_dl/__init__.py b/lib/svtplay_dl/__init__.py index e9aed8d..20aaa5a 100644 --- a/lib/svtplay_dl/__init__.py +++ b/lib/svtplay_dl/__init__.py @@ -70,7 +70,7 @@ def get_media(url, options): # output is a directory os.path.join(options.output, filenamify(title_tag)) - stream.get(options, url) + stream.get(options) def setup_log(silent, verbose=False): fmt = logging.Formatter('%(levelname)s %(message)s') diff --git a/lib/svtplay_dl/service/__init__.py b/lib/svtplay_dl/service/__init__.py index ad7bb93..647ef4b 100644 --- a/lib/svtplay_dl/service/__init__.py +++ b/lib/svtplay_dl/service/__init__.py @@ -8,6 +8,9 @@ class Service(object): supported_domains = [] supported_domains_re = [] + def __init__(self, url): + self.url = url + @classmethod def handles(cls, url): urlp = urlparse(url) @@ -77,19 +80,19 @@ class Generic(object): url = match.group(1) for i in sites: if i.handles(url): - return url, i() + return url, i(url) match = re.search(r"src=\"(http://player.vimeo.com/video/[0-9]+)\" ", data) if match: for i in sites: if i.handles(match.group(1)): - return match.group(1), i() + return match.group(1), i(url) match = re.search(r"tv4video.swf\?vid=(\d+)", data) if match: url = "http://www.tv4play.se/?video_id=%s" % match.group(1) for i in sites: if i.handles(url): - return url, i() + return url, i(url) return url, stream def service_handler(url): @@ -97,7 +100,7 @@ def service_handler(url): for i in sites: if i.handles(url): - handler = i() + handler = i(url) break return handler diff --git a/lib/svtplay_dl/service/aftonbladet.py b/lib/svtplay_dl/service/aftonbladet.py index fdc8d7c..59de3f9 100644 --- a/lib/svtplay_dl/service/aftonbladet.py +++ b/lib/svtplay_dl/service/aftonbladet.py @@ -15,9 +15,9 @@ from svtplay_dl.fetcher.http import download_http class Aftonbladet(Service): supported_domains = ['aftonbladet.se'] - def get(self, options, url): - parse = urlparse(url) - data = get_http_data(url) + def get(self, options): + parse = urlparse(self.url) + data = get_http_data(self.url) match = re.search("abTvArticlePlayer-player-(.*)-[0-9]+-[0-9]+-clickOverlay", data) if not match: log.error("Can't find video file") diff --git a/lib/svtplay_dl/service/dr.py b/lib/svtplay_dl/service/dr.py index 52ffac8..dfcda3c 100644 --- a/lib/svtplay_dl/service/dr.py +++ b/lib/svtplay_dl/service/dr.py @@ -14,8 +14,8 @@ from svtplay_dl.log import log class Dr(Service): supported_domains = ['dr.dk'] - def get(self, options, url): - data = get_http_data(url) + def get(self, options): + data = get_http_data(self.url) match = re.search(r'resource:[ ]*"([^"]*)",', data) if match: resource_url = match.group(1) diff --git a/lib/svtplay_dl/service/expressen.py b/lib/svtplay_dl/service/expressen.py index 7538197..8a1b472 100644 --- a/lib/svtplay_dl/service/expressen.py +++ b/lib/svtplay_dl/service/expressen.py @@ -15,8 +15,8 @@ from svtplay_dl.utils.urllib import quote_plus class Expressen(Service): supported_domains = ['expressen.se'] - def get(self, options, url): - data = get_http_data(url) + def get(self, options): + data = get_http_data(self.url) match = re.search(r"xmlUrl: '(http://www.expressen.*)'", data) if not match: log.error("Can't find video file") diff --git a/lib/svtplay_dl/service/hbo.py b/lib/svtplay_dl/service/hbo.py index 8cfd1dc..160c7ae 100644 --- a/lib/svtplay_dl/service/hbo.py +++ b/lib/svtplay_dl/service/hbo.py @@ -14,8 +14,8 @@ from svtplay_dl.fetcher.rtmp import download_rtmp class Hbo(Service): supported_domains = ['hbo.com'] - def get(self, options, url): - parse = urlparse(url) + def get(self, options): + parse = urlparse(self.url) try: other = parse[5] except KeyError: diff --git a/lib/svtplay_dl/service/justin.py b/lib/svtplay_dl/service/justin.py index 004dd90..9e42355 100644 --- a/lib/svtplay_dl/service/justin.py +++ b/lib/svtplay_dl/service/justin.py @@ -24,8 +24,8 @@ class Justin(Service): r'^(?:(?:[a-z]{2}-)?[a-z]{2}\.)?(www\.)?twitch\.tv$', r'^(?:(?:[a-z]{2}-)?[a-z]{2}\.)?(www\.)?justin\.tv$'] - def get(self, options, url): - parse = urlparse(url) + def get(self, options): + parse = urlparse(self.url) match = re.search(r"/[-a-zA-Z0-9_]+/c/(\d+)", parse.path) if match: url = "http://api.justin.tv/api/broadcast/by_chapter/%s.xml?onsite=true" % match.group(1) diff --git a/lib/svtplay_dl/service/kanal5.py b/lib/svtplay_dl/service/kanal5.py index 29674a9..907c800 100644 --- a/lib/svtplay_dl/service/kanal5.py +++ b/lib/svtplay_dl/service/kanal5.py @@ -15,9 +15,9 @@ from svtplay_dl.fetcher.hls import download_hls class Kanal5(Service): supported_domains = ['kanal5play.se', 'kanal9play.se'] - def get(self, options, url): + def get(self, options): cj = CookieJar() - match = re.search(r".*video/([0-9]+)", url) + match = re.search(r".*video/([0-9]+)", self.url) if not match: log.error("Can't find video file") sys.exit(2) diff --git a/lib/svtplay_dl/service/mtvservices.py b/lib/svtplay_dl/service/mtvservices.py index 2471d79..89ab0d1 100644 --- a/lib/svtplay_dl/service/mtvservices.py +++ b/lib/svtplay_dl/service/mtvservices.py @@ -12,8 +12,8 @@ from svtplay_dl.log import log class Mtvservices(Service): supported_domains = ['colbertnation.com', 'thedailyshow.com'] - def get(self, options, url): - data = get_http_data(url) + def get(self, options): + data = get_http_data(self.url) match = re.search(r"mgid=\"(mgid.*[0-9]+)\" data-wi", data) if not match: log.error("Can't find video file") diff --git a/lib/svtplay_dl/service/nrk.py b/lib/svtplay_dl/service/nrk.py index cb525d9..8f08348 100644 --- a/lib/svtplay_dl/service/nrk.py +++ b/lib/svtplay_dl/service/nrk.py @@ -12,8 +12,8 @@ from svtplay_dl.fetcher.hls import download_hls class Nrk(Service): supported_domains = ['nrk.no'] - def get(self, options, url): - data = get_http_data(url) + def get(self, options): + data = get_http_data(self.url) match = re.search(r'data-media="(.*manifest.f4m)"', data) manifest_url = match.group(1) if options.hls: @@ -25,7 +25,7 @@ class Nrk(Service): if options.subtitle: match = re.search("data-subtitlesurl = \"(/.*)\"", data) if match: - parse = urlparse(url) + parse = urlparse(self.url) subtitle = "%s://%s%s" % (parse.scheme, parse.netloc, match.group(1)) data = get_http_data(subtitle) subtitle_tt(options, data) diff --git a/lib/svtplay_dl/service/qbrick.py b/lib/svtplay_dl/service/qbrick.py index cc27b21..a31d610 100644 --- a/lib/svtplay_dl/service/qbrick.py +++ b/lib/svtplay_dl/service/qbrick.py @@ -13,17 +13,17 @@ from svtplay_dl.fetcher.rtmp import download_rtmp class Qbrick(Service): supported_domains = ['dn.se', 'di.se', 'svd.se', 'sydsvenskan.se'] - def get(self, options, url): - if re.findall(r"sydsvenskan.se", url): - data = get_http_data(url) + def get(self, options): + if re.findall(r"sydsvenskan.se", self.url): + data = get_http_data(self.url) match = re.search(r"data-qbrick-mcid=\"([0-9A-F]+)\"", data) if not match: log.error("Can't find video file") sys.exit(2) mcid = match.group(1) host = "http://vms.api.qbrick.com/rest/v3/getsingleplayer/%s" % mcid - elif re.findall(r"di.se", url): - data = get_http_data(url) + elif re.findall(r"di.se", self.url): + data = get_http_data(self.url) match = re.search("src=\"(http://qstream.*)\">", data) - parse = urlparse(url) + parse = urlparse(self.url) station = parse.path[1:] streams = None if match: diff --git a/lib/svtplay_dl/service/ruv.py b/lib/svtplay_dl/service/ruv.py index 145c2ea..26e49c6 100644 --- a/lib/svtplay_dl/service/ruv.py +++ b/lib/svtplay_dl/service/ruv.py @@ -10,8 +10,8 @@ from svtplay_dl.fetcher.hls import download_hls class Ruv(Service): supported_domains = ['ruv.is'] - def get(self, options, url): - data = get_http_data(url) + def get(self, options): + data = get_http_data(self.url) match = re.search(r'(http://load.cache.is/vodruv.*)"', data) js_url = match.group(1) js = get_http_data(js_url) diff --git a/lib/svtplay_dl/service/sr.py b/lib/svtplay_dl/service/sr.py index 7cf3530..ac3b5c4 100644 --- a/lib/svtplay_dl/service/sr.py +++ b/lib/svtplay_dl/service/sr.py @@ -18,9 +18,9 @@ from svtplay_dl.fetcher.http import download_http class Sr(Service): supported_domains = ['sverigesradio.se'] - def get(self, options, url): - data = get_http_data(url) - parse = urlparse(url) + def get(self, options): + data = get_http_data(self.url) + parse = urlparse(self.url) if "metafile" in parse_qs(parse.query): options.other = "%s?%s" % (parse.path, parse.query) diff --git a/lib/svtplay_dl/service/svtplay.py b/lib/svtplay_dl/service/svtplay.py index 6078df4..4547cdf 100644 --- a/lib/svtplay_dl/service/svtplay.py +++ b/lib/svtplay_dl/service/svtplay.py @@ -18,9 +18,9 @@ from svtplay_dl.log import log class Svtplay(Service): supported_domains = ['svtplay.se', 'svt.se', 'oppetarkiv.se', 'beta.svtplay.se'] - def get(self, options, url): - if re.findall("svt.se", url): - data = get_http_data(url) + def get(self, options): + if re.findall("svt.se", self.url): + data = get_http_data(self.url) match = re.search(r"data-json-href=\"(.*)\"", data) if match: filename = match.group(1).replace("&", "&").replace("&format=json", "") @@ -28,6 +28,8 @@ class Svtplay(Service): else: log.error("Can't find video file") sys.exit(2) + else: + url = self.url pos = url.find("?") if pos < 0: diff --git a/lib/svtplay_dl/service/tv4play.py b/lib/svtplay_dl/service/tv4play.py index 00d9ad9..e37b0f2 100644 --- a/lib/svtplay_dl/service/tv4play.py +++ b/lib/svtplay_dl/service/tv4play.py @@ -15,20 +15,20 @@ from svtplay_dl.fetcher.hds import download_hds class Tv4play(Service): supported_domains = ['tv4play.se', 'tv4.se'] - def get(self, options, url): - parse = urlparse(url) - if "tv4play.se" in url: + def get(self, options): + parse = urlparse(self.url) + if "tv4play.se" in self.url: try: vid = parse_qs(parse[4])["video_id"][0] except KeyError: log.error("Can't find video file") sys.exit(2) else: - match = re.search(r"-(\d+)$", url) + match = re.search(r"-(\d+)$", self.url) if match: vid = match.group(1) else: - data = get_http_data(url) + data = get_http_data(self.url) match = re.search(r"\"vid\":\"(\d+)\",", data) if match: vid = match.group(1) diff --git a/lib/svtplay_dl/service/urplay.py b/lib/svtplay_dl/service/urplay.py index 199871e..aa07d4d 100644 --- a/lib/svtplay_dl/service/urplay.py +++ b/lib/svtplay_dl/service/urplay.py @@ -14,8 +14,8 @@ from svtplay_dl.log import log class Urplay(Service): supported_domains = ['urplay.se', 'ur.se'] - def get(self, options, url): - data = get_http_data(url) + def get(self, options): + data = get_http_data(self.url) match = re.search(r"urPlayer.init\((.*)\);", data) if not match: log.error("Can't find json info") @@ -69,4 +69,4 @@ class Urplay(Service): elif 'sd' in available: return available["sd"] else: - raise KeyError() \ No newline at end of file + raise KeyError() diff --git a/lib/svtplay_dl/service/viaplay.py b/lib/svtplay_dl/service/viaplay.py index 473464d..c101da6 100644 --- a/lib/svtplay_dl/service/viaplay.py +++ b/lib/svtplay_dl/service/viaplay.py @@ -21,8 +21,8 @@ class Viaplay(Service): 'tv3play.no', 'tv3play.dk', 'tv6play.no', 'viasat4play.no', 'tv3play.ee', 'tv3play.lv', 'tv3play.lt'] - def get(self, options, url): - parse = urlparse(url) + def get(self, options): + parse = urlparse(self.url) match = re.search(r'\/play\/(\d+)/?', parse.path) if not match: log.error("Cant find video file") diff --git a/lib/svtplay_dl/service/vimeo.py b/lib/svtplay_dl/service/vimeo.py index 9e59ad5..994225b 100644 --- a/lib/svtplay_dl/service/vimeo.py +++ b/lib/svtplay_dl/service/vimeo.py @@ -13,8 +13,8 @@ from svtplay_dl.log import log class Vimeo(Service): supported_domains = ['vimeo.com'] - def get(self, options, url): - data = get_http_data(url) + def get(self, options): + data = get_http_data(self.url) match = re.search("data-config-url=\"(.*)\" data-fallback-url", data) if not match: log.error("Can't find data")