Add option for reloading video without invidious
For faster usage of new identity button as an alternative
This commit is contained in:
parent
3d5293ba4a
commit
d7a4b03fdf
@ -288,7 +288,14 @@
|
|||||||
|
|
||||||
{% block main %}
|
{% block main %}
|
||||||
{% if playability_error %}
|
{% if playability_error %}
|
||||||
<div class="playability-error"><span>{{ 'Error: ' + playability_error }}</span></div>
|
<div class="playability-error">
|
||||||
|
<span>{{ 'Error: ' + playability_error }}
|
||||||
|
{% if invidious_reload_button %}
|
||||||
|
<a href="{{ video_url }}&use_invidious=0"><br>
|
||||||
|
Reload without invidious (for usage of new identity button).</a>
|
||||||
|
{% endif %}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
{% else %}
|
{% else %}
|
||||||
<video controls autofocus class="video">
|
<video controls autofocus class="video">
|
||||||
{% for video_source in video_sources %}
|
{% for video_source in video_sources %}
|
||||||
|
@ -207,7 +207,7 @@ headers = (
|
|||||||
('X-YouTube-Client-Version', '2.20180830'),
|
('X-YouTube-Client-Version', '2.20180830'),
|
||||||
) + util.mobile_ua
|
) + util.mobile_ua
|
||||||
|
|
||||||
def extract_info(video_id, playlist_id=None, index=None):
|
def extract_info(video_id, use_invidious, playlist_id=None, index=None):
|
||||||
# bpctr=9999999999 will bypass are-you-sure dialogs for controversial
|
# bpctr=9999999999 will bypass are-you-sure dialogs for controversial
|
||||||
# videos
|
# videos
|
||||||
url = 'https://m.youtube.com/watch?v=' + video_id + '&pbj=1&bpctr=9999999999'
|
url = 'https://m.youtube.com/watch?v=' + video_id + '&pbj=1&bpctr=9999999999'
|
||||||
@ -244,6 +244,7 @@ def extract_info(video_id, playlist_id=None, index=None):
|
|||||||
|
|
||||||
# check for 403
|
# check for 403
|
||||||
info['invidious_used'] = False
|
info['invidious_used'] = False
|
||||||
|
info['invidious_reload_button'] = False
|
||||||
if settings.route_tor and info['formats'] and info['formats'][0]['url']:
|
if settings.route_tor and info['formats'] and info['formats'][0]['url']:
|
||||||
try:
|
try:
|
||||||
response = util.head(info['formats'][0]['url'],
|
response = util.head(info['formats'][0]['url'],
|
||||||
@ -254,43 +255,48 @@ def extract_info(video_id, playlist_id=None, index=None):
|
|||||||
return info
|
return info
|
||||||
|
|
||||||
if response.status == 403:
|
if response.status == 403:
|
||||||
print(('Access denied (403) for video urls.'
|
print('Access denied (403) for video urls.')
|
||||||
' Retrieving urls from Invidious...'))
|
if use_invidious:
|
||||||
info['invidious_used'] = True
|
print(' Retrieving urls from Invidious...')
|
||||||
try:
|
info['invidious_used'] = True
|
||||||
video_info = util.fetch_url(
|
try:
|
||||||
'https://invidio.us/api/v1/videos/'
|
video_info = util.fetch_url(
|
||||||
+ video_id
|
'https://invidio.us/api/v1/videos/'
|
||||||
+ '?fields=adaptiveFormats,formatStreams',
|
+ video_id
|
||||||
report_text='Retrieved urls from Invidious',
|
+ '?fields=adaptiveFormats,formatStreams',
|
||||||
debug_name='invidious_urls')
|
report_text='Retrieved urls from Invidious',
|
||||||
except (util.FetchError, urllib3.exceptions.HTTPError) as e:
|
debug_name='invidious_urls')
|
||||||
traceback.print_exc()
|
except (util.FetchError, urllib3.exceptions.HTTPError) as e:
|
||||||
playability_error = ('Access denied (403) for video urls.'
|
traceback.print_exc()
|
||||||
+ ' Failed to use Invidious to get the urls: '
|
playability_error = ('Access denied (403) for video urls.'
|
||||||
+ str(e))
|
+ ' Failed to use Invidious to get the urls: '
|
||||||
if info['playability_error']:
|
+ str(e))
|
||||||
info['playability_error'] += '\n' + playability_error
|
if info['playability_error']:
|
||||||
else:
|
info['playability_error'] += '\n' + playability_error
|
||||||
info['playability_error'] = playability_error
|
else:
|
||||||
|
info['playability_error'] = playability_error
|
||||||
return info
|
# include button to reload without invidious
|
||||||
|
info['invidious_reload_button'] = True
|
||||||
|
return info
|
||||||
|
|
||||||
video_info = json.loads(video_info.decode('utf-8'))
|
video_info = json.loads(video_info.decode('utf-8'))
|
||||||
# collect invidious urls for each itag
|
# collect invidious urls for each itag
|
||||||
itag_to_url = {}
|
itag_to_url = {}
|
||||||
for invidious_fmt in (video_info['adaptiveFormats']
|
for invidious_fmt in (video_info['adaptiveFormats']
|
||||||
+ video_info['formatStreams']):
|
+ video_info['formatStreams']):
|
||||||
itag_to_url[invidious_fmt['itag']] = invidious_fmt['url']
|
itag_to_url[invidious_fmt['itag']] = invidious_fmt['url']
|
||||||
|
|
||||||
# replace urls with urls from invidious
|
# replace urls with urls from invidious
|
||||||
for fmt in info['formats']:
|
for fmt in info['formats']:
|
||||||
itag = str(fmt['itag'])
|
itag = str(fmt['itag'])
|
||||||
if itag not in itag_to_url:
|
if itag not in itag_to_url:
|
||||||
print(('Warning: itag '
|
print(('Warning: itag '
|
||||||
+ itag + ' not found in invidious urls'))
|
+ itag + ' not found in invidious urls'))
|
||||||
continue
|
continue
|
||||||
fmt['url'] = itag_to_url[itag]
|
fmt['url'] = itag_to_url[itag]
|
||||||
|
else:
|
||||||
|
info['playability_error'] = ('Access denied (403) for video '
|
||||||
|
'urls')
|
||||||
elif 300 <= response.status < 400:
|
elif 300 <= response.status < 400:
|
||||||
print('Error: exceeded max redirects while checking video URL')
|
print('Error: exceeded max redirects while checking video URL')
|
||||||
return info
|
return info
|
||||||
@ -345,9 +351,10 @@ def get_watch_page(video_id=None):
|
|||||||
lc = request.args.get('lc', '')
|
lc = request.args.get('lc', '')
|
||||||
playlist_id = request.args.get('list')
|
playlist_id = request.args.get('list')
|
||||||
index = request.args.get('index')
|
index = request.args.get('index')
|
||||||
|
use_invidious = bool(int(request.args.get('use_invidious', '1')))
|
||||||
tasks = (
|
tasks = (
|
||||||
gevent.spawn(comments.video_comments, video_id, int(settings.default_comment_sorting), lc=lc ),
|
gevent.spawn(comments.video_comments, video_id, int(settings.default_comment_sorting), lc=lc ),
|
||||||
gevent.spawn(extract_info, video_id, playlist_id=playlist_id,
|
gevent.spawn(extract_info, video_id, use_invidious, playlist_id=playlist_id,
|
||||||
index=index)
|
index=index)
|
||||||
)
|
)
|
||||||
gevent.joinall(tasks)
|
gevent.joinall(tasks)
|
||||||
@ -456,6 +463,8 @@ def get_watch_page(video_id=None):
|
|||||||
allowed_countries = info['allowed_countries'],
|
allowed_countries = info['allowed_countries'],
|
||||||
ip_address = info['ip_address'] if settings.route_tor else None,
|
ip_address = info['ip_address'] if settings.route_tor else None,
|
||||||
invidious_used = info['invidious_used'],
|
invidious_used = info['invidious_used'],
|
||||||
|
invidious_reload_button = info['invidious_reload_button'],
|
||||||
|
video_url = util.URL_ORIGIN + '/watch?v=' + video_id,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user