From 8a7ba641f4b50fd633070aa01f20336259644549 Mon Sep 17 00:00:00 2001 From: OndrejIT Date: Thu, 28 Apr 2016 13:43:33 +0200 Subject: Fix StreamCz hoster --- module/plugins/hoster/StreamCz.py | 108 +++++++++++++++++++++++++------------- 1 file changed, 71 insertions(+), 37 deletions(-) diff --git a/module/plugins/hoster/StreamCz.py b/module/plugins/hoster/StreamCz.py index 19a288b22..8e89d2109 100644 --- a/module/plugins/hoster/StreamCz.py +++ b/module/plugins/hoster/StreamCz.py @@ -1,58 +1,92 @@ # -*- coding: utf-8 -*- +import os import re +import time +import json +import hashlib +from urlparse import urljoin -from module.plugins.internal.Hoster import Hoster +from module.plugins.internal.SimpleHoster import SimpleHoster -class StreamCz(Hoster): +def get_api_password(episode): + episode = "/episode/" + str(episode) + api_key = "fb5f58a820353bd7095de526253c14fd" + + timestamp = int(round(time.time() * 1000 / 1e3 / 24 / 3600)) + api_pass = api_key + episode + str(timestamp) + + m = hashlib.md5() + m.update(api_pass) + + return m.hexdigest() + +def get_all_link(data, container): + videos = [] + for i in range(0, len(data["video_qualities"])): + if len(data["video_qualities"][i]["formats"][1]) and container == "webm": + videos.append( + data["video_qualities"][i]["formats"][1]["source"], + ) + else: + videos.append( + data["video_qualities"][i]["formats"][0]["source"], + ) + + return videos + +def get_link_quality(videos, quality): + quality_index = ["240p", "360p", "480p", "720p", "1080p"] + quality = quality_index.index(quality) + + while quality >= 0: + if len(videos) >= quality + 1: + link = videos[quality] + break + else: + quality -= 1 + + return link + + +class StreamCz(SimpleHoster): __name__ = "StreamCz" __type__ = "hoster" - __version__ = "0.25" + __version__ = "0.35" __status__ = "testing" - __pattern__ = r'https?://(?:www\.)?stream\.cz/[^/]+/\d+' - __config__ = [("activated", "bool", "Activated", True)] + __pattern__ = r'https?://(?:www\.)?stream\.cz/[^/]+/(\d+).+' + __config__ = [("activated", "bool", "Activated", True), + ("quality", "240p;360p;480p;720p;1080p", "Quality", "720p"), + ("container", "mp4;webm", "Container", "mp4"),] __description__ = """Stream.cz hoster plugin""" - __license__ = "GPLv3" - __authors__ = [("zoidberg", "zoidberg@mujmail.cz")] + __authors__ = [("ondrej", "git@ondrej.it")] - NAME_PATTERN = r'' - OFFLINE_PATTERN = r'

Str.nku nebylo mo.n. nal.zt \(404\)

' + def setup(self): + self.resume_download = True + self.multiDL = True - CDN_PATTERN = r' '': - cdnid = cdn[cdnkey] - break - else: - self.fail(_("Stream URL not found")) + videos = get_all_link(data, container) + link = get_link_quality(videos, quality) - m = re.search(self.NAME_PATTERN, self.data) - if m is None: - self.error(_("NAME_PATTERN not found")) - pyfile.name = "%s-%s.%s.mp4" % (m.group(2), m.group(1), cdnkey[-2:]) + link_name, container = os.path.splitext(link) + self.pyfile.name = data["name"] + container - download_url = "http://cdn-dispatcher.stream.cz/?id=" + cdnid - self.log_info(_("STREAM: %s") % cdnkey[-2:], download_url) - self.download(download_url) + self.log_info(_("Downloading file...")) + self.download(link) -- cgit v1.2.3