From 45a80c1b16172313c452a675cd8d651e3e3db9a6 Mon Sep 17 00:00:00 2001 From: sh!zeeg Date: Sun, 25 Dec 2016 04:40:44 +0300 Subject: [PATCH] [StreamMe]: flake8 checked --- youtube_dl/extractor/streamme.py | 67 +++++++++++++++++--------------- 1 file changed, 36 insertions(+), 31 deletions(-) diff --git a/youtube_dl/extractor/streamme.py b/youtube_dl/extractor/streamme.py index c7e396f6e..414f89bff 100644 --- a/youtube_dl/extractor/streamme.py +++ b/youtube_dl/extractor/streamme.py @@ -10,6 +10,7 @@ from ..utils import ( ExtractorError, ) + class StreamMeIE(InfoExtractor): IE_NAME = 'StreamMe:video' _API_CHANNEL = 'https://www.stream.me/api-user/v1//channel' @@ -35,7 +36,6 @@ class StreamMeIE(InfoExtractor): video_id = self._match_id(url) apiurl = self._API_ARCHIVE.replace('', m.group('channel_id')) - # webpage = self._download_webpage(url, video_id) data = json.loads(self._download_webpage(apiurl, video_id)) for vod in data.get('_embedded').get('vod'): @@ -43,14 +43,13 @@ class StreamMeIE(InfoExtractor): if vod.get('urlId') == video_id: vod_info = vod break - + manifest_json = self._download_json(vod_info - .get('_links') - .get('manifest') - .get('href'), video_id) + .get('_links') + .get('manifest') + .get('href'), video_id) formats = self._extract_formats(manifest_json.get('formats')) - self._sort_formats(formats, 'vbr') info = self._extract_info(vod_info) info['formats'] = formats @@ -79,23 +78,25 @@ class StreamMeIE(InfoExtractor): formats = [] for fmt_tag, d in fmts.items(): # skip websocket and mjpeg we can't handle them anyway - if fmt_tag in ('mjpeg-lodef', 'mp4-ws',): continue + if fmt_tag in ('mjpeg-lodef', 'mp4-ws',): + continue for fmt_info in d.get('encodings'): formats.append({ - 'url': fmt_info.get('location'), - 'width': fmt_info.get('videoWidth'), - 'height': fmt_info.get('videoHeight'), - 'vbr': fmt_info.get('videoKbps'), - 'abr': fmt_info.get('audioKbps'), - 'acodec': d.get('audioCodec'), - 'vcodec': d.get('videoCodec'), + 'url': fmt_info.get('location'), + 'width': fmt_info.get('videoWidth'), + 'height': fmt_info.get('videoHeight'), + 'vbr': fmt_info.get('videoKbps'), + 'abr': fmt_info.get('audioKbps'), + 'acodec': d.get('audioCodec'), + 'vcodec': d.get('videoCodec'), 'format_id': "%s%sp" % (fmt_tag, fmt_info.get('videoHeight')), 'ext': 'flv' if fmt_tag.split('-')[1] == 'rtmp' else 'mp4', # I don't know all the possible protocols yet. # 'protocol': 'm3u8_native' if fmt_tag == 'mp4-hls' else 'http' - }) + }) return formats + class StreamMeLiveIE(StreamMeIE): IE_NAME = 'StreamIE:live' _VALID_URL = r'%s/(?P[^\#]+$)' % StreamMeIE._VALID_URL_BASE @@ -106,44 +107,48 @@ class StreamMeLiveIE(StreamMeIE): data = json.loads(self._download_webpage(apiurl, channel_id)) stream_info = [] - # search for a live stream... + # search for a live stream... for stream in data.get('_embedded').get('streams'): stream_info = stream - break # TODO: add to a list (multi-streams?) - + break # TODO: add to a list (multi-streams?) + if not stream_info.get('active'): raise ExtractorError('%s is offline' % channel_id, expected=True) - - manifest_json = self._download_json(stream_info - .get('_links') - .get('manifest') - .get('href'), channel_id) - formats = self._extract_formats(manifest_json.get('formats')) + manifest_json = self._download_json(stream_info + .get('_links') + .get('manifest') + .get('href'), channel_id) + + formats = self._extract_formats(manifest_json.get('formats')) self._sort_formats(formats, 'vbr') info = self._extract_info(stream_info) info['formats'] = formats return info + class StreamMeArchiveIE(StreamMeIE): IE_NAME = 'StreamMe:archives' _VALID_URL = r'%s/(?P[^\#]+(?P\#archives)$)' % StreamMeIE._VALID_URL_BASE _PLAYLIST_TYPE = 'past broadcasts' _PLAYLIST_LIMIT = 128 _TEST = { - 'url': 'https://www.stream.me/kombatcup#archives', - 'info_dict': { - 'id': 'kombatcup', - 'title': 'KombatCup', - }, - 'playlist_mincount': 25, + 'url': 'https://www.stream.me/kombatcup#archives', + 'info_dict': { + 'id': 'kombatcup', + 'title': 'KombatCup', + }, + 'playlist_mincount': 25, + 'params': { + 'skip_download': True, + } } def _real_extract(self, url): channel_id = self._match_id(url).split('#')[0] apiurl = StreamMeIE._API_ARCHIVE.replace('', channel_id) # TODO: implement paginated downloading - data = json.loads(self._download_webpage(apiurl+'?limit=%d&offset=0' % self._PLAYLIST_LIMIT, channel_id)) + data = json.loads(self._download_webpage(apiurl + '?limit=%d&offset=0' % self._PLAYLIST_LIMIT, channel_id)) playlist = [] for vod in data.get('_embedded').get('vod'):