settings.py: add 'proxy_images'
This commit is contained in:
parent
9123d9a6cf
commit
f8d9be2d5a
12
settings.py
12
settings.py
@ -128,6 +128,13 @@ For security reasons, enabling this is not recommended.''',
|
|||||||
'comment': '',
|
'comment': '',
|
||||||
}),
|
}),
|
||||||
|
|
||||||
|
('proxy_images', {
|
||||||
|
'label': 'proxy images',
|
||||||
|
'type': bool,
|
||||||
|
'default': True,
|
||||||
|
'comment': '',
|
||||||
|
}),
|
||||||
|
|
||||||
('theme', {
|
('theme', {
|
||||||
'type': int,
|
'type': int,
|
||||||
'default': 0,
|
'default': 0,
|
||||||
@ -298,6 +305,11 @@ else:
|
|||||||
globals().update(current_settings_dict)
|
globals().update(current_settings_dict)
|
||||||
|
|
||||||
|
|
||||||
|
if proxy_images:
|
||||||
|
img_prefix = "/"
|
||||||
|
else:
|
||||||
|
img_prefix = ""
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if route_tor:
|
if route_tor:
|
||||||
|
@ -92,7 +92,7 @@ def post_process_comments_info(comments_info):
|
|||||||
comment['author_url'] = concat_or_none(
|
comment['author_url'] = concat_or_none(
|
||||||
util.URL_ORIGIN, comment['author_url'])
|
util.URL_ORIGIN, comment['author_url'])
|
||||||
comment['author_avatar'] = concat_or_none(
|
comment['author_avatar'] = concat_or_none(
|
||||||
'/', comment['author_avatar'])
|
settings.img_prefix, comment['author_avatar'])
|
||||||
|
|
||||||
comment['permalink'] = concat_or_none(util.URL_ORIGIN, '/watch?v=',
|
comment['permalink'] = concat_or_none(util.URL_ORIGIN, '/watch?v=',
|
||||||
comments_info['video_id'], '&lc=', comment['id'])
|
comments_info['video_id'], '&lc=', comment['id'])
|
||||||
@ -139,7 +139,7 @@ def post_process_comments_info(comments_info):
|
|||||||
|
|
||||||
comments_info['video_url'] = concat_or_none(util.URL_ORIGIN,
|
comments_info['video_url'] = concat_or_none(util.URL_ORIGIN,
|
||||||
'/watch?v=', comments_info['video_id'])
|
'/watch?v=', comments_info['video_id'])
|
||||||
comments_info['video_thumbnail'] = concat_or_none('/i.ytimg.com/vi/',
|
comments_info['video_thumbnail'] = concat_or_none(settings.img_prefix, 'https://i.ytimg.com/vi/',
|
||||||
comments_info['video_id'], '/mqdefault.jpg')
|
comments_info['video_id'], '/mqdefault.jpg')
|
||||||
|
|
||||||
|
|
||||||
|
@ -52,7 +52,7 @@ def get_local_playlist_videos(name, offset=0, amount=50):
|
|||||||
try:
|
try:
|
||||||
info = json.loads(video_json)
|
info = json.loads(video_json)
|
||||||
if info['id'] + ".jpg" in thumbnails:
|
if info['id'] + ".jpg" in thumbnails:
|
||||||
info['thumbnail'] = "/youtube.com/data/playlist_thumbnails/" + name + "/" + info['id'] + ".jpg"
|
info['thumbnail'] = settings.img_prefix + "https://youtube.com/data/playlist_thumbnails/" + name + "/" + info['id'] + ".jpg"
|
||||||
else:
|
else:
|
||||||
info['thumbnail'] = util.get_thumbnail_url(info['id'])
|
info['thumbnail'] = util.get_thumbnail_url(info['id'])
|
||||||
missing_thumbnails.append(info['id'])
|
missing_thumbnails.append(info['id'])
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
from youtube import util, yt_data_extract, proto
|
from youtube import util, yt_data_extract, proto
|
||||||
from youtube import yt_app
|
from youtube import yt_app
|
||||||
|
import settings
|
||||||
|
|
||||||
import base64
|
import base64
|
||||||
import urllib
|
import urllib
|
||||||
@ -103,7 +104,7 @@ def get_playlist_page():
|
|||||||
util.prefix_urls(item)
|
util.prefix_urls(item)
|
||||||
util.add_extra_html_info(item)
|
util.add_extra_html_info(item)
|
||||||
if 'id' in item:
|
if 'id' in item:
|
||||||
item['thumbnail'] = '/https://i.ytimg.com/vi/' + item['id'] + '/default.jpg'
|
item['thumbnail'] = f'{settings.img_prefix}https://i.ytimg.com/vi/' + item['id'] + '/default.jpg'
|
||||||
|
|
||||||
item['url'] += '&list=' + playlist_id
|
item['url'] += '&list=' + playlist_id
|
||||||
if item['index']:
|
if item['index']:
|
||||||
|
@ -820,6 +820,7 @@ def get_subscriptions_page():
|
|||||||
videos, number_of_videos_in_db = _get_videos(cursor, 60, (page - 1)*60, tag)
|
videos, number_of_videos_in_db = _get_videos(cursor, 60, (page - 1)*60, tag)
|
||||||
for video in videos:
|
for video in videos:
|
||||||
video['thumbnail'] = util.URL_ORIGIN + '/data/subscription_thumbnails/' + video['id'] + '.jpg'
|
video['thumbnail'] = util.URL_ORIGIN + '/data/subscription_thumbnails/' + video['id'] + '.jpg'
|
||||||
|
if not settings.proxy_images: video['thumbnail'] = video['thumbnail'][1:]
|
||||||
video['type'] = 'video'
|
video['type'] = 'video'
|
||||||
video['item_size'] = 'small'
|
video['item_size'] = 'small'
|
||||||
util.add_extra_html_info(video)
|
util.add_extra_html_info(video)
|
||||||
|
@ -3,7 +3,9 @@
|
|||||||
<head>
|
<head>
|
||||||
<meta charset="utf-8">
|
<meta charset="utf-8">
|
||||||
<title>{{ page_title }}</title>
|
<title>{{ page_title }}</title>
|
||||||
<meta http-equiv="Content-Security-Policy" content="default-src 'self' 'unsafe-inline'; media-src 'self' https://*.googlevideo.com">
|
{% if settings.proxy_images %}
|
||||||
|
<meta http-equiv="Content-Security-Policy" content="default-src 'self' 'unsafe-inline'; media-src 'self' https://*.googlevideo.com">
|
||||||
|
{% endif %}
|
||||||
<link href="{{ theme_path }}" type="text/css" rel="stylesheet">
|
<link href="{{ theme_path }}" type="text/css" rel="stylesheet">
|
||||||
<link href="/youtube.com/static/shared.css" type="text/css" rel="stylesheet">
|
<link href="/youtube.com/static/shared.css" type="text/css" rel="stylesheet">
|
||||||
<link href="/youtube.com/static/comments.css" type="text/css" rel="stylesheet">
|
<link href="/youtube.com/static/comments.css" type="text/css" rel="stylesheet">
|
||||||
|
@ -342,7 +342,7 @@ def video_id(url):
|
|||||||
|
|
||||||
# default, sddefault, mqdefault, hqdefault, hq720
|
# default, sddefault, mqdefault, hqdefault, hq720
|
||||||
def get_thumbnail_url(video_id):
|
def get_thumbnail_url(video_id):
|
||||||
return "/i.ytimg.com/vi/" + video_id + "/mqdefault.jpg"
|
return f"{settings.img_prefix}https://i.ytimg.com/vi/" + video_id + "/mqdefault.jpg"
|
||||||
|
|
||||||
def seconds_to_timestamp(seconds):
|
def seconds_to_timestamp(seconds):
|
||||||
seconds = int(seconds)
|
seconds = int(seconds)
|
||||||
@ -394,10 +394,11 @@ def concat_or_none(*strings):
|
|||||||
|
|
||||||
|
|
||||||
def prefix_urls(item):
|
def prefix_urls(item):
|
||||||
try:
|
if settings.proxy_images:
|
||||||
item['thumbnail'] = prefix_url(item['thumbnail'])
|
try:
|
||||||
except KeyError:
|
item['thumbnail'] = prefix_url(item['thumbnail'])
|
||||||
pass
|
except KeyError:
|
||||||
|
pass
|
||||||
|
|
||||||
try:
|
try:
|
||||||
item['author_url'] = prefix_url(item['author_url'])
|
item['author_url'] = prefix_url(item['author_url'])
|
||||||
|
Loading…
x
Reference in New Issue
Block a user