forked from ytdl-org/youtube-dl
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20 from blackjack4494/master
release 01.09.2020
- Loading branch information
Showing
15 changed files
with
587 additions
and
1,127 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
from __future__ import division, unicode_literals | ||
|
||
import re | ||
import json | ||
|
||
from .fragment import FragmentFD | ||
|
||
|
||
class YoutubeLiveChatReplayFD(FragmentFD): | ||
""" Downloads YouTube live chat replays fragment by fragment """ | ||
|
||
FD_NAME = 'youtube_live_chat_replay' | ||
|
||
def real_download(self, filename, info_dict): | ||
video_id = info_dict['video_id'] | ||
self.to_screen('[%s] Downloading live chat' % self.FD_NAME) | ||
|
||
test = self.params.get('test', False) | ||
|
||
ctx = { | ||
'filename': filename, | ||
'live': True, | ||
'total_frags': None, | ||
} | ||
|
||
def dl_fragment(url): | ||
headers = info_dict.get('http_headers', {}) | ||
return self._download_fragment(ctx, url, info_dict, headers) | ||
|
||
def parse_yt_initial_data(data): | ||
window_patt = b'window\\["ytInitialData"\\]\\s*=\\s*(.*?)(?<=});' | ||
var_patt = b'var\\s+ytInitialData\\s*=\\s*(.*?)(?<=});' | ||
for patt in window_patt, var_patt: | ||
try: | ||
raw_json = re.search(patt, data).group(1) | ||
return json.loads(raw_json) | ||
except AttributeError: | ||
continue | ||
|
||
self._prepare_and_start_frag_download(ctx) | ||
|
||
success, raw_fragment = dl_fragment( | ||
'https://www.youtube.com/watch?v={}'.format(video_id)) | ||
if not success: | ||
return False | ||
data = parse_yt_initial_data(raw_fragment) | ||
continuation_id = data['contents']['twoColumnWatchNextResults']['conversationBar']['liveChatRenderer']['continuations'][0]['reloadContinuationData']['continuation'] | ||
# no data yet but required to call _append_fragment | ||
self._append_fragment(ctx, b'') | ||
|
||
first = True | ||
offset = None | ||
while continuation_id is not None: | ||
data = None | ||
if first: | ||
url = 'https://www.youtube.com/live_chat_replay?continuation={}'.format(continuation_id) | ||
success, raw_fragment = dl_fragment(url) | ||
if not success: | ||
return False | ||
data = parse_yt_initial_data(raw_fragment) | ||
else: | ||
url = ('https://www.youtube.com/live_chat_replay/get_live_chat_replay' | ||
+ '?continuation={}'.format(continuation_id) | ||
+ '&playerOffsetMs={}'.format(offset - 5000) | ||
+ '&hidden=false' | ||
+ '&pbj=1') | ||
success, raw_fragment = dl_fragment(url) | ||
if not success: | ||
return False | ||
data = json.loads(raw_fragment)['response'] | ||
|
||
first = False | ||
continuation_id = None | ||
|
||
live_chat_continuation = data['continuationContents']['liveChatContinuation'] | ||
offset = None | ||
processed_fragment = bytearray() | ||
if 'actions' in live_chat_continuation: | ||
for action in live_chat_continuation['actions']: | ||
if 'replayChatItemAction' in action: | ||
replay_chat_item_action = action['replayChatItemAction'] | ||
offset = int(replay_chat_item_action['videoOffsetTimeMsec']) | ||
processed_fragment.extend( | ||
json.dumps(action, ensure_ascii=False).encode('utf-8') + b'\n') | ||
continuation_id = live_chat_continuation['continuations'][0]['liveChatReplayContinuationData']['continuation'] | ||
|
||
self._append_fragment(ctx, processed_fragment) | ||
|
||
if test or offset is None: | ||
break | ||
|
||
self._finish_frag_download(ctx) | ||
|
||
return True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
# coding: utf-8 | ||
from __future__ import unicode_literals | ||
|
||
import string | ||
import random | ||
import time | ||
|
||
from .common import InfoExtractor | ||
|
||
|
||
class DoodStreamIE(InfoExtractor): | ||
_VALID_URL = r'https?://(?:www\.)?dood\.(?:to|watch)/[ed]/(?P<id>[a-z0-9]+)' | ||
_TESTS = [{ | ||
'url': 'http://dood.to/e/5s1wmbdacezb', | ||
'md5': '4568b83b31e13242b3f1ff96c55f0595', | ||
'info_dict': { | ||
'id': '5s1wmbdacezb', | ||
'ext': 'mp4', | ||
'title': 'Kat Wonders - Monthly May 2020', | ||
'description': 'Kat Wonders - Monthly May 2020 | DoodStream.com', | ||
'thumbnail': 'https://img.doodcdn.com/snaps/flyus84qgl2fsk4g.jpg', | ||
} | ||
}, { | ||
'url': 'https://dood.to/d/jzrxn12t2s7n', | ||
'md5': '3207e199426eca7c2aa23c2872e6728a', | ||
'info_dict': { | ||
'id': 'jzrxn12t2s7n', | ||
'ext': 'mp4', | ||
'title': 'Stacy Cruz Cute ALLWAYSWELL', | ||
'description': 'Stacy Cruz Cute ALLWAYSWELL | DoodStream.com', | ||
'thumbnail': 'https://img.doodcdn.com/snaps/8edqd5nppkac3x8u.jpg', | ||
} | ||
}] | ||
|
||
def _real_extract(self, url): | ||
video_id = self._match_id(url) | ||
webpage = self._download_webpage(url, video_id) | ||
|
||
if '/d/' in url: | ||
url = "https://dood.to" + self._html_search_regex( | ||
r'<iframe src="(/e/[a-z0-9]+)"', webpage, 'embed') | ||
video_id = self._match_id(url) | ||
webpage = self._download_webpage(url, video_id) | ||
|
||
title = self._html_search_meta(['og:title', 'twitter:title'], | ||
webpage, default=None) | ||
thumb = self._html_search_meta(['og:image', 'twitter:image'], | ||
webpage, default=None) | ||
token = self._html_search_regex(r'[?&]token=([a-z0-9]+)[&\']', webpage, 'token') | ||
description = self._html_search_meta( | ||
['og:description', 'description', 'twitter:description'], | ||
webpage, default=None) | ||
auth_url = 'https://dood.to' + self._html_search_regex( | ||
r'(/pass_md5.*?)\'', webpage, 'pass_md5') | ||
headers = { | ||
'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:53.0) Gecko/20100101 Firefox/66.0', | ||
'referer': url | ||
} | ||
|
||
webpage = self._download_webpage(auth_url, video_id, headers=headers) | ||
final_url = webpage + ''.join([random.choice(string.ascii_letters + string.digits) for _ in range(10)]) + "?token=" + token + "&expiry=" + str(int(time.time() * 1000)) | ||
|
||
return { | ||
'id': video_id, | ||
'title': title, | ||
'url': final_url, | ||
'http_headers': headers, | ||
'ext': 'mp4', | ||
'description': description, | ||
'thumbnail': thumb, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.