From 2aae49003a1e1346d8fff35d8d0bac1db1e7fceb Mon Sep 17 00:00:00 2001 From: Olof Johansson Date: Sun, 9 Mar 2014 15:01:04 +0100 Subject: [PATCH 1/3] justin: support archived content from twitch and justin Archive contents have URLs that look like justin.tv//b/ and twitch.tv//b/. Otherwise, the implementation is equivalent with that of _get_video, which is now renamed to _get_chapter. Closes #67. --- lib/svtplay_dl/service/justin.py | 45 +++++++++++++++++++++++--------- 1 file changed, 32 insertions(+), 13 deletions(-) diff --git a/lib/svtplay_dl/service/justin.py b/lib/svtplay_dl/service/justin.py index f9ec73be9..5e38404d2 100644 --- a/lib/svtplay_dl/service/justin.py +++ b/lib/svtplay_dl/service/justin.py @@ -46,33 +46,52 @@ class Justin(Service): def get(self, options): urlp = urlparse(self.url) + success = False - try: - self._get_video(urlp, options) - except JustinUrlException as e: - log.debug(str(e)) - + for jtv_video_type in [self._get_chapter, self._get_archive, + self._get_channel]: try: - self._get_channel(urlp, options) + jtv_video_type(urlp, options) + success = True + break except JustinUrlException as e: log.debug(str(e)) - log.error("Can't find media for URL") - sys.exit(2) + if not success: + log.debug(str(e)) + log.error("Can't find media for URL") + sys.exit(2) - def _get_video(self, urlp, options): - match = re.match(r'/\w+/c/(\d+)', urlp.path) - if not match: - raise JustinUrlException('video', urlp.geturl()) - url = "http://api.justin.tv/api/broadcast/by_chapter/%s.xml?onsite=true" % match.group(1) + def _get_static_video(self, vid, options, vidtype): + url = "http://api.justin.tv/api/broadcast/by_%s/%s.xml?onsite=true" % ( + vidtype, vid) data = get_http_data(url) + if not data: + return False + xml = ET.XML(data) url = xml.find("archive").find("video_file_url").text download_http(options, url) + def _get_archive(self, urlp, options): + match = re.match(r'/\w+/b/(\d+)', urlp.path) + if not match: + raise JustinUrlException('video', urlp.geturl()) + + self._get_static_video(match.group(1), options, 'archive') + + + def _get_chapter(self, urlp, options): + match = re.match(r'/\w+/c/(\d+)', urlp.path) + if not match: + raise JustinUrlException('video', urlp.geturl()) + + self._get_static_video(match.group(1), options, 'chapter') + + def _get_access_token(self, channel): """ Get a Twitch access token. It's a three element dict: From d6eba115ba0f157a4ab325912ecc4892f9d17e9c Mon Sep 17 00:00:00 2001 From: Olof Johansson Date: Sun, 9 Mar 2014 15:04:08 +0100 Subject: [PATCH 2/3] justin: adjust error msg in case of type being unknown --- lib/svtplay_dl/service/justin.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/svtplay_dl/service/justin.py b/lib/svtplay_dl/service/justin.py index 5e38404d2..81c091dbe 100644 --- a/lib/svtplay_dl/service/justin.py +++ b/lib/svtplay_dl/service/justin.py @@ -59,7 +59,7 @@ def get(self, options): if not success: log.debug(str(e)) - log.error("Can't find media for URL") + log.error("This twitch/justin video type is unsupported") sys.exit(2) From cb710e60012e0d4ef88938e1b739e2a7d362d239 Mon Sep 17 00:00:00 2001 From: Olof Johansson Date: Sun, 9 Mar 2014 15:16:15 +0100 Subject: [PATCH 3/3] fetcher.http: send url to debug log before request --- lib/svtplay_dl/fetcher/http.py | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/svtplay_dl/fetcher/http.py b/lib/svtplay_dl/fetcher/http.py index c5ce5cd2e..9dd975883 100644 --- a/lib/svtplay_dl/fetcher/http.py +++ b/lib/svtplay_dl/fetcher/http.py @@ -11,6 +11,7 @@ def download_http(options, url): """ Get the stream from HTTP """ + log.debug("Fetching %s", url) request = Request(url) request.add_header('User-Agent', 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.9.0.3) Gecko/2008092417 Firefox/3.0.3') try: