From b9b3231316b032c7d43bfd4f4493a0cfe8ffbe43 Mon Sep 17 00:00:00 2001 From: God Date: Mon, 26 Jul 2021 15:06:45 -0400 Subject: [PATCH] [piczel] Add new extractor --- youtube_dl/extractor/extractors.py | 1 + youtube_dl/extractor/piczel.py | 95 ++++++++++++++++++++++++++++++ 2 files changed, 96 insertions(+) create mode 100644 youtube_dl/extractor/piczel.py diff --git a/youtube_dl/extractor/extractors.py b/youtube_dl/extractor/extractors.py index 6e8fc3961..931c9ae2a 100644 --- a/youtube_dl/extractor/extractors.py +++ b/youtube_dl/extractor/extractors.py @@ -907,6 +907,7 @@ from .picarto import ( PicartoIE, PicartoVodIE, ) +from .piczel import PiczelIE from .piksel import PikselIE from .pinkbike import PinkbikeIE from .pinterest import ( diff --git a/youtube_dl/extractor/piczel.py b/youtube_dl/extractor/piczel.py new file mode 100644 index 000000000..38eb86b7f --- /dev/null +++ b/youtube_dl/extractor/piczel.py @@ -0,0 +1,95 @@ + +# coding: utf-8 +from __future__ import unicode_literals + +from .common import InfoExtractor +from ..compat import ( + compat_HTTPError, + compat_urllib_request +) +from ..utils import ( + ExtractorError +) + + +class PiczelIE(InfoExtractor): + _VALID_URL = r'https?://(?:www.)?piczel\.tv/watch/(?P[a-zA-Z0-9]+)' + _TESTS = [{ + 'url': 'https://piczel.tv/watch/Schwoo', + 'info_dict': { + 'id': 'Schwoo', + 'uploader_id': '43564', + 'ext': 'mp4', + 'title': 'Schwoo - Piczel.tv', + 'description': 'Horni Vibin\'', + 'is_live': bool, + }, + #'skip': 'Stream is offline' + 'params': { + 'skip_download': True, + }, + }, { + 'url': 'https://piczel.tv/watch/GeneralButchTv', + 'info_dict': { + 'id': 'GeneralButchTv', + 'uploader_id': '39042', + 'ext': 'mp4', + 'title': 'GeneralButchTv - Piczel.tv', + 'description': 'GENERAL BUTCH', + 'is_live': bool, + }, + #'skip': 'Stream is offline' + 'params': { + 'skip_download': True, + }, + }, { + 'url': 'https://piczel.tv/watch/Nifffi', + 'info_dict': { + 'id': 'Nifffi', + 'uploader_id': '60996', + 'ext': 'mp4', + 'title': 'Nifffi - Piczel.tv', + 'description': u'(ノ´ヮ`)ノ*: ・゚', + 'is_live': bool, + }, + #'skip': 'Stream is offline' + 'params': { + 'skip_download': True, + }, + }] + + + def _real_extract(self, url): + video_id = self._match_id(url) + + webpage = self._download_webpage(url, video_id) + title = self._html_search_regex(r'(.+?)<\/title>', webpage, 'title') + + api_data = self._download_json('https://piczel.tv/api/streams/%s' % video_id, video_id) + uploader_id = api_data['data'][0]['id'] + is_live = api_data['data'][0]['live'] + + if not is_live: + # There is a bug where the api says user is not streaming when they are. + # So checing user's index.m3u8 file for 404 errors + try: + req = compat_urllib_request.urlopen('https://piczel.tv/hls/%i/index.m3u8' % uploader_id) + print(req.code) + except: + raise ExtractorError('Stream is offline', expected=True) + + + formats = [] + formats.append({ + 'url': 'https://piczel.tv/hls/%i/index.m3u8' % uploader_id, + 'ext': 'mp4', + }) + + return { + 'id': video_id, + 'uploader_id': str(uploader_id), + 'title': title, + 'description': self._og_search_description(webpage), + 'is_live': is_live, + 'formats': formats, + }