mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2024-11-21 20:46:36 -05:00
[linter] youtube.py
This commit is contained in:
parent
545cc85d11
commit
8a784c74d1
1 changed files with 14 additions and 18 deletions
|
@ -7,6 +7,7 @@
|
||||||
import os.path
|
import os.path
|
||||||
import random
|
import random
|
||||||
import re
|
import re
|
||||||
|
import time
|
||||||
import traceback
|
import traceback
|
||||||
|
|
||||||
from .common import InfoExtractor, SearchInfoExtractor
|
from .common import InfoExtractor, SearchInfoExtractor
|
||||||
|
@ -30,9 +31,8 @@
|
||||||
int_or_none,
|
int_or_none,
|
||||||
mimetype2ext,
|
mimetype2ext,
|
||||||
parse_codecs,
|
parse_codecs,
|
||||||
parse_count,
|
|
||||||
parse_duration,
|
parse_duration,
|
||||||
qualities,
|
# qualities,
|
||||||
remove_start,
|
remove_start,
|
||||||
smuggle_url,
|
smuggle_url,
|
||||||
str_or_none,
|
str_or_none,
|
||||||
|
@ -1494,7 +1494,7 @@ def feed_entry(name):
|
||||||
formats = []
|
formats = []
|
||||||
itags = []
|
itags = []
|
||||||
player_url = None
|
player_url = None
|
||||||
q = qualities(['tiny', 'small', 'medium', 'large', 'hd720', 'hd1080', 'hd1440', 'hd2160', 'hd2880', 'highres'])
|
# q = qualities(['tiny', 'small', 'medium', 'large', 'hd720', 'hd1080', 'hd1440', 'hd2160', 'hd2880', 'highres'])
|
||||||
streaming_data = player_response.get('streamingData') or {}
|
streaming_data = player_response.get('streamingData') or {}
|
||||||
streaming_formats = streaming_data.get('formats') or []
|
streaming_formats = streaming_data.get('formats') or []
|
||||||
streaming_formats.extend(streaming_data.get('adaptiveFormats') or [])
|
streaming_formats.extend(streaming_data.get('adaptiveFormats') or [])
|
||||||
|
@ -1909,10 +1909,9 @@ def chapter_time(mmlir):
|
||||||
if not xsrf_token:
|
if not xsrf_token:
|
||||||
xsrf_token = self._search_regex(
|
xsrf_token = self._search_regex(
|
||||||
r'([\'"])XSRF_TOKEN\1\s*:\s*([\'"])(?P<xsrf_token>(?:(?!\2).)+)\2',
|
r'([\'"])XSRF_TOKEN\1\s*:\s*([\'"])(?P<xsrf_token>(?:(?!\2).)+)\2',
|
||||||
video_webpage, 'xsrf token', group='xsrf_token', fatal=False)
|
webpage, 'xsrf token', group='xsrf_token', fatal=False)
|
||||||
|
|
||||||
# annotations
|
# annotations
|
||||||
video_annotations = None
|
|
||||||
if get_annotations:
|
if get_annotations:
|
||||||
invideo_url = try_get(
|
invideo_url = try_get(
|
||||||
player_response, lambda x: x['annotations'][0]['playerAnnotationsUrlsRenderer']['invideoUrl'], compat_str)
|
player_response, lambda x: x['annotations'][0]['playerAnnotationsUrlsRenderer']['invideoUrl'], compat_str)
|
||||||
|
@ -1923,9 +1922,9 @@ def chapter_time(mmlir):
|
||||||
if not xsrf_field_name:
|
if not xsrf_field_name:
|
||||||
xsrf_field_name = self._search_regex(
|
xsrf_field_name = self._search_regex(
|
||||||
r'([\'"])XSRF_FIELD_NAME\1\s*:\s*([\'"])(?P<xsrf_field_name>\w+)\2',
|
r'([\'"])XSRF_FIELD_NAME\1\s*:\s*([\'"])(?P<xsrf_field_name>\w+)\2',
|
||||||
video_webpage, 'xsrf field name',
|
webpage, 'xsrf field name',
|
||||||
group='xsrf_field_name', default='session_token')
|
group='xsrf_field_name', default='session_token')
|
||||||
video_annotations = self._download_webpage(
|
info['annotations'] = self._download_webpage(
|
||||||
self._proto_relative_url(invideo_url),
|
self._proto_relative_url(invideo_url),
|
||||||
video_id, note='Downloading annotations',
|
video_id, note='Downloading annotations',
|
||||||
errnote='Unable to download video annotations', fatal=False,
|
errnote='Unable to download video annotations', fatal=False,
|
||||||
|
@ -1955,12 +1954,14 @@ def search_dict(partial, key):
|
||||||
for o in search_dict(i, key):
|
for o in search_dict(i, key):
|
||||||
yield o
|
yield o
|
||||||
|
|
||||||
|
continuations = []
|
||||||
|
if initial_data:
|
||||||
try:
|
try:
|
||||||
ncd = next(search_dict(yt_initial_data, 'nextContinuationData'))
|
ncd = next(search_dict(initial_data, 'nextContinuationData'))
|
||||||
continuations = [ncd['continuation']]
|
continuations = [ncd['continuation']]
|
||||||
# Handle videos where comments have been disabled entirely
|
# Handle videos where comments have been disabled entirely
|
||||||
except StopIteration:
|
except StopIteration:
|
||||||
continuations = []
|
pass
|
||||||
|
|
||||||
def get_continuation(continuation, session_token, replies=False):
|
def get_continuation(continuation, session_token, replies=False):
|
||||||
query = {
|
query = {
|
||||||
|
@ -2034,10 +2035,8 @@ def get_continuation(continuation, session_token, replies=False):
|
||||||
'parent': 'root'
|
'parent': 'root'
|
||||||
})
|
})
|
||||||
if 'replies' not in meta_comment['commentThreadRenderer']:
|
if 'replies' not in meta_comment['commentThreadRenderer']:
|
||||||
|
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
|
||||||
reply_continuations = [rcn['nextContinuationData']['continuation'] for rcn in meta_comment['commentThreadRenderer']['replies']['commentRepliesRenderer']['continuations']]
|
reply_continuations = [rcn['nextContinuationData']['continuation'] for rcn in meta_comment['commentThreadRenderer']['replies']['commentRepliesRenderer']['continuations']]
|
||||||
while reply_continuations:
|
while reply_continuations:
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
|
@ -2061,13 +2060,10 @@ def get_continuation(continuation, session_token, replies=False):
|
||||||
'parent': comment['commentId']
|
'parent': comment['commentId']
|
||||||
})
|
})
|
||||||
if 'continuations' not in reply_comment_meta or len(reply_comment_meta['continuations']) == 0:
|
if 'continuations' not in reply_comment_meta or len(reply_comment_meta['continuations']) == 0:
|
||||||
|
|
||||||
continue
|
continue
|
||||||
|
|
||||||
reply_continuations += [rcn['nextContinuationData']['continuation'] for rcn in reply_comment_meta['continuations']]
|
reply_continuations += [rcn['nextContinuationData']['continuation'] for rcn in reply_comment_meta['continuations']]
|
||||||
|
|
||||||
self.to_screen('Comments downloaded %s of ~%s' % (len(video_comments), expected_video_comment_count))
|
self.to_screen('Comments downloaded %s of ~%s' % (len(video_comments), expected_video_comment_count))
|
||||||
|
|
||||||
if 'continuations' in item_section:
|
if 'continuations' in item_section:
|
||||||
continuations += [ncd['nextContinuationData']['continuation'] for ncd in item_section['continuations']]
|
continuations += [ncd['nextContinuationData']['continuation'] for ncd in item_section['continuations']]
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
|
|
Loading…
Reference in a new issue