summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar OndrejIT <git@ondrej.it> 2016-04-28 13:43:33 +0200
committerGravatar OndrejIT <git@ondrej.it> 2016-04-28 13:43:33 +0200
commit8a7ba641f4b50fd633070aa01f20336259644549 (patch)
tree390a97159eb7ad3d2905d77e28a41d50bdb34e61
parent[MegaCoNz] Update (diff)
downloadpyload-8a7ba641f4b50fd633070aa01f20336259644549.tar.xz
Fix StreamCz hoster
-rw-r--r--module/plugins/hoster/StreamCz.py108
1 files 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'<link rel="video_src" href="http://www\.stream\.cz/\w+/(\d+)-(.+?)" />'
- OFFLINE_PATTERN = r'<h1 class="commonTitle">Str.nku nebylo mo.n. nal.zt \(404\)</h1>'
+ def setup(self):
+ self.resume_download = True
+ self.multiDL = True
- CDN_PATTERN = r'<param name="flashvars" value=".+?&id=(?P<ID>\d+)(?:&cdnLQ=(?P<cdnLQ>\d*))?(?:&cdnHQ=(?P<cdnHQ>\d*))?(?:&cdnHD=(?P<cdnHD>\d*))?&'
+ def process(self, pyfile):
+ episode = re.search(self.__pattern__, pyfile.url).group(1)
+ api_password = get_api_password(episode)
+ api_url = urljoin("https://www.stream.cz/API/episode/", str(episode))
+ self.req.putHeader("Api-Password", api_password)
+ resp = self.load(api_url)
- def setup(self):
- self.resume_download = True
- self.multiDL = True
+ data = json.loads(resp)
+ quality = self.config.get("quality")
+ container = self.config.get("container")
- def process(self, pyfile):
- self.data = self.load(pyfile.url)
-
- if re.search(self.OFFLINE_PATTERN, self.data):
- self.offline()
-
- m = re.search(self.CDN_PATTERN, self.data)
- if m is None:
- self.error(_("CDN_PATTERN not found"))
- cdn = m.groupdict()
- self.log_debug(cdn)
- for cdnkey in ("cdnHD", "cdnHQ", "cdnLQ"):
- if cdnkey in cdn and cdn[cdnkey] > '':
- 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)