From f8d9be2d5a947a2adde12d187a52b18b7218c541 Mon Sep 17 00:00:00 2001
From: zrose584 <57181548+zrose584@users.noreply.github.com>
Date: Wed, 7 Oct 2020 19:28:52 +0200
Subject: settings.py: add 'proxy_images'
---
youtube/comments.py | 4 ++--
youtube/local_playlist.py | 4 ++--
youtube/playlist.py | 13 +++++++------
youtube/subscriptions.py | 1 +
youtube/templates/base.html | 4 +++-
youtube/util.py | 13 +++++++------
6 files changed, 22 insertions(+), 17 deletions(-)
(limited to 'youtube')
diff --git a/youtube/comments.py b/youtube/comments.py
index 07d4b89..1d0e92a 100644
--- a/youtube/comments.py
+++ b/youtube/comments.py
@@ -92,7 +92,7 @@ def post_process_comments_info(comments_info):
comment['author_url'] = concat_or_none(
util.URL_ORIGIN, comment['author_url'])
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=',
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,
'/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')
diff --git a/youtube/local_playlist.py b/youtube/local_playlist.py
index 3a058b3..857ed24 100644
--- a/youtube/local_playlist.py
+++ b/youtube/local_playlist.py
@@ -35,7 +35,7 @@ def add_to_playlist(name, video_info_list):
file.write(info + "\n")
missing_thumbnails.append(id)
gevent.spawn(util.download_thumbnails, os.path.join(thumbnails_directory, name), missing_thumbnails)
-
+
def get_local_playlist_videos(name, offset=0, amount=50):
try:
@@ -52,7 +52,7 @@ def get_local_playlist_videos(name, offset=0, amount=50):
try:
info = json.loads(video_json)
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:
info['thumbnail'] = util.get_thumbnail_url(info['id'])
missing_thumbnails.append(info['id'])
diff --git a/youtube/playlist.py b/youtube/playlist.py
index b7167f6..0a415c1 100644
--- a/youtube/playlist.py
+++ b/youtube/playlist.py
@@ -1,5 +1,6 @@
from youtube import util, yt_data_extract, proto
from youtube import yt_app
+import settings
import base64
import urllib
@@ -14,15 +15,15 @@ import flask
-def playlist_ctoken(playlist_id, offset):
-
+def playlist_ctoken(playlist_id, offset):
+
offset = proto.uint(1, offset)
# this is just obfuscation as far as I can tell. It doesn't even follow protobuf
offset = b'PT:' + proto.unpadded_b64encode(offset)
offset = proto.string(15, offset)
continuation_info = proto.string( 3, proto.percent_b64encode(offset) )
-
+
playlist_id = proto.string(2, 'VL' + playlist_id )
pointless_nest = proto.string(80226972, playlist_id + continuation_info)
@@ -51,7 +52,7 @@ def playlist_first_page(playlist_id, report_text = "Retrieved playlist"):
content = json.loads(util.uppercase_escape(content.decode('utf-8')))
return content
-
+
#https://m.youtube.com/playlist?itct=CBMQybcCIhMIptj9xJaJ2wIV2JKcCh3Idwu-&ctoken=4qmFsgI2EiRWTFBMT3kwajlBdmxWWlB0bzZJa2pLZnB1MFNjeC0tN1BHVEMaDmVnWlFWRHBEUWxFJTNE&pbj=1
def get_videos(playlist_id, page):
@@ -84,7 +85,7 @@ def get_playlist_page():
this_page_json = first_page_json
else:
tasks = (
- gevent.spawn(playlist_first_page, playlist_id, report_text="Retrieved playlist info" ),
+ gevent.spawn(playlist_first_page, playlist_id, report_text="Retrieved playlist info" ),
gevent.spawn(get_videos, playlist_id, page)
)
gevent.joinall(tasks)
@@ -103,7 +104,7 @@ def get_playlist_page():
util.prefix_urls(item)
util.add_extra_html_info(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
if item['index']:
diff --git a/youtube/subscriptions.py b/youtube/subscriptions.py
index 6f75578..a661f83 100644
--- a/youtube/subscriptions.py
+++ b/youtube/subscriptions.py
@@ -820,6 +820,7 @@ def get_subscriptions_page():
videos, number_of_videos_in_db = _get_videos(cursor, 60, (page - 1)*60, tag)
for video in videos:
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['item_size'] = 'small'
util.add_extra_html_info(video)
diff --git a/youtube/templates/base.html b/youtube/templates/base.html
index 4ff83c5..462cac4 100644
--- a/youtube/templates/base.html
+++ b/youtube/templates/base.html
@@ -3,7 +3,9 @@
{{ page_title }}
-
+ {% if settings.proxy_images %}
+
+ {% endif %}
diff --git a/youtube/util.py b/youtube/util.py
index 3c32ddb..a75a7b5 100644
--- a/youtube/util.py
+++ b/youtube/util.py
@@ -342,8 +342,8 @@ def video_id(url):
# default, sddefault, mqdefault, hqdefault, hq720
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):
seconds = int(seconds)
hours, seconds = divmod(seconds,3600)
@@ -394,10 +394,11 @@ def concat_or_none(*strings):
def prefix_urls(item):
- try:
- item['thumbnail'] = prefix_url(item['thumbnail'])
- except KeyError:
- pass
+ if settings.proxy_images:
+ try:
+ item['thumbnail'] = prefix_url(item['thumbnail'])
+ except KeyError:
+ pass
try:
item['author_url'] = prefix_url(item['author_url'])
--
cgit v1.2.3
From 4f46e14ad0154a9e8749c9e0e39a4a799d549dd4 Mon Sep 17 00:00:00 2001
From: zrose584 <57181548+zrose584@users.noreply.github.com>
Date: Fri, 9 Oct 2020 18:25:17 +0200
Subject: fix style
---
youtube/playlist.py | 2 +-
youtube/subscriptions.py | 3 ++-
youtube/util.py | 2 +-
3 files changed, 4 insertions(+), 3 deletions(-)
(limited to 'youtube')
diff --git a/youtube/playlist.py b/youtube/playlist.py
index 0a415c1..a5ec0db 100644
--- a/youtube/playlist.py
+++ b/youtube/playlist.py
@@ -104,7 +104,7 @@ def get_playlist_page():
util.prefix_urls(item)
util.add_extra_html_info(item)
if 'id' in item:
- item['thumbnail'] = f'{settings.img_prefix}https://i.ytimg.com/vi/' + item['id'] + '/default.jpg'
+ item['thumbnail'] = settings.img_prefix + 'https://i.ytimg.com/vi/' + item['id'] + '/default.jpg'
item['url'] += '&list=' + playlist_id
if item['index']:
diff --git a/youtube/subscriptions.py b/youtube/subscriptions.py
index a661f83..219a526 100644
--- a/youtube/subscriptions.py
+++ b/youtube/subscriptions.py
@@ -820,7 +820,8 @@ def get_subscriptions_page():
videos, number_of_videos_in_db = _get_videos(cursor, 60, (page - 1)*60, tag)
for video in videos:
video['thumbnail'] = util.URL_ORIGIN + '/data/subscription_thumbnails/' + video['id'] + '.jpg'
- if not settings.proxy_images: video['thumbnail'] = video['thumbnail'][1:]
+ if not settings.proxy_images:
+ video['thumbnail'] = video['thumbnail'][1:]
video['type'] = 'video'
video['item_size'] = 'small'
util.add_extra_html_info(video)
diff --git a/youtube/util.py b/youtube/util.py
index a75a7b5..579f512 100644
--- a/youtube/util.py
+++ b/youtube/util.py
@@ -342,7 +342,7 @@ def video_id(url):
# default, sddefault, mqdefault, hqdefault, hq720
def get_thumbnail_url(video_id):
- return f"{settings.img_prefix}https://i.ytimg.com/vi/" + video_id + "/mqdefault.jpg"
+ return settings.img_prefix + "https://i.ytimg.com/vi/" + video_id + "/mqdefault.jpg"
def seconds_to_timestamp(seconds):
seconds = int(seconds)
--
cgit v1.2.3
From ed0b20e6c8c4dc018fa8ad25e2af436510e05f73 Mon Sep 17 00:00:00 2001
From: zrose584 <57181548+zrose584@users.noreply.github.com>
Date: Fri, 9 Oct 2020 18:35:13 +0200
Subject: Don't remove the CSP completely
---
youtube/templates/base.html | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
(limited to 'youtube')
diff --git a/youtube/templates/base.html b/youtube/templates/base.html
index 462cac4..c647c68 100644
--- a/youtube/templates/base.html
+++ b/youtube/templates/base.html
@@ -3,9 +3,8 @@
{{ page_title }}
- {% if settings.proxy_images %}
-
- {% endif %}
+
--
cgit v1.2.3
From 7d7b072a5b588ecb897a9283ca0ca7ac90736af0 Mon Sep 17 00:00:00 2001
From: zrose584 <57181548+zrose584@users.noreply.github.com>
Date: Sat, 10 Oct 2020 18:42:54 +0200
Subject: always proxy cached thumbnails
---
youtube/local_playlist.py | 2 +-
youtube/subscriptions.py | 2 --
2 files changed, 1 insertion(+), 3 deletions(-)
(limited to 'youtube')
diff --git a/youtube/local_playlist.py b/youtube/local_playlist.py
index 857ed24..394e7db 100644
--- a/youtube/local_playlist.py
+++ b/youtube/local_playlist.py
@@ -52,7 +52,7 @@ def get_local_playlist_videos(name, offset=0, amount=50):
try:
info = json.loads(video_json)
if info['id'] + ".jpg" in thumbnails:
- info['thumbnail'] = settings.img_prefix + "https://youtube.com/data/playlist_thumbnails/" + name + "/" + info['id'] + ".jpg"
+ info['thumbnail'] = "https://youtube.com/data/playlist_thumbnails/" + name + "/" + info['id'] + ".jpg"
else:
info['thumbnail'] = util.get_thumbnail_url(info['id'])
missing_thumbnails.append(info['id'])
diff --git a/youtube/subscriptions.py b/youtube/subscriptions.py
index 219a526..6f75578 100644
--- a/youtube/subscriptions.py
+++ b/youtube/subscriptions.py
@@ -820,8 +820,6 @@ def get_subscriptions_page():
videos, number_of_videos_in_db = _get_videos(cursor, 60, (page - 1)*60, tag)
for video in videos:
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['item_size'] = 'small'
util.add_extra_html_info(video)
--
cgit v1.2.3
From 37d286fc7ce8feec72d9ecf5d238a42c873de1d0 Mon Sep 17 00:00:00 2001
From: zrose584 <57181548+zrose584@users.noreply.github.com>
Date: Mon, 12 Oct 2020 13:46:50 +0200
Subject: put the slash back
---
youtube/local_playlist.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'youtube')
diff --git a/youtube/local_playlist.py b/youtube/local_playlist.py
index 394e7db..891bb76 100644
--- a/youtube/local_playlist.py
+++ b/youtube/local_playlist.py
@@ -52,7 +52,7 @@ def get_local_playlist_videos(name, offset=0, amount=50):
try:
info = json.loads(video_json)
if info['id'] + ".jpg" in thumbnails:
- info['thumbnail'] = "https://youtube.com/data/playlist_thumbnails/" + name + "/" + info['id'] + ".jpg"
+ info['thumbnail'] = "/https://youtube.com/data/playlist_thumbnails/" + name + "/" + info['id'] + ".jpg"
else:
info['thumbnail'] = util.get_thumbnail_url(info['id'])
missing_thumbnails.append(info['id'])
--
cgit v1.2.3