aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesús <heckyel@hyperbola.info>2020-12-19 22:13:37 -0500
committerJesús <heckyel@hyperbola.info>2020-12-19 22:13:37 -0500
commit1de9ae424573e3b0aed1bad68067430dd1baa357 (patch)
tree1ad2cd14d4e5bca2132a7e0d5f7eb795ee442fd6
parentafb2aca4609d554858e4e669409f7c30afdc7e63 (diff)
downloadyt-local-1de9ae424573e3b0aed1bad68067430dd1baa357.tar.lz
yt-local-1de9ae424573e3b0aed1bad68067430dd1baa357.tar.xz
yt-local-1de9ae424573e3b0aed1bad68067430dd1baa357.zip
Patch-import-migrate: Add embed page for embeds on the web
Issue #36 From e51f0a78c778a2283887db7ffc22421a7c849296 Mon Sep 17 00:00:00 2001 From: James Taylor <user234683@users.noreply.github.com>
-rw-r--r--README.md4
-rw-r--r--server.py1
-rw-r--r--settings.py8
-rw-r--r--youtube/templates/embed.html35
-rw-r--r--youtube/watch.py30
5 files changed, 70 insertions, 8 deletions
diff --git a/README.md b/README.md
index 525e888..3b0ffaa 100644
--- a/README.md
+++ b/README.md
@@ -92,7 +92,9 @@ To run the program on windows, open `run.bat`. On GNU+Linux/MacOS, run `python3
Access youtube URLs by prefixing them with `http://localhost:8080/`, For instance, `http://localhost:8080/https://www.youtube.com/watch?v=vBgulDeV2RU`
-You can use an addon such as Redirector ([Firefox](https://addons.mozilla.org/en-US/firefox/addon/redirector/)|[Chrome](https://chrome.google.com/webstore/detail/redirector/ocgpenflpmgnfapjedencafcfakcekcd)) to automatically redirect Youtube URLs to yt-local. I use the include pattern `^(https?://(?:[a-zA-Z0-9_-]*\.)?(?:youtube\.com|youtu\.be)/.*)` and the redirect pattern `http://localhost:8080/$1` (Make sure you're using regular expression mode).
+You can use an addon such as Redirector ([Firefox](https://addons.mozilla.org/en-US/firefox/addon/redirector/)|[Chrome](https://chrome.google.com/webstore/detail/redirector/ocgpenflpmgnfapjedencafcfakcekcd)) to automatically redirect Youtube URLs to yt-local. I use the include pattern `^(https?://(?:[a-zA-Z0-9_-]*\.)?(?:youtube\.com|youtu\.be|youtube-nocookie\.com)/.*)` and the redirect pattern `http://localhost:8080/$1` (Make sure you're using regular expression mode).
+
+If you want embeds on the web to also redirect to yt-local, make sure "Iframes" is checked under advanced options in your redirector rule.
yt-local can be added as a search engine in firefox to make searching more convenient. See [here](https://support.mozilla.org/en-US/kb/add-or-remove-search-engine-firefox) for information on firefox search plugins.
diff --git a/server.py b/server.py
index b388218..9e4f674 100644
--- a/server.py
+++ b/server.py
@@ -163,6 +163,7 @@ def proxy_video(env, start_response):
site_handlers = {
'youtube.com': yt_app,
+ 'youtube-nocookie.com': yt_app,
'youtu.be': youtu_be,
'ytimg.com': proxy_site,
'yt3.ggpht.com': proxy_site,
diff --git a/settings.py b/settings.py
index 0d52bc5..edb9211 100644
--- a/settings.py
+++ b/settings.py
@@ -197,6 +197,14 @@ For security reasons, enabling this is not recommended.''',
'category': 'interface',
}),
+ ('embed_page_mode', {
+ 'type': bool,
+ 'label': 'Enable embed page',
+ 'default': True,
+ 'comment': '',
+ 'category': 'interface',
+ }),
+
('autocheck_subscriptions', {
'type': bool,
'default': 0,
diff --git a/youtube/templates/embed.html b/youtube/templates/embed.html
new file mode 100644
index 0000000..728791b
--- /dev/null
+++ b/youtube/templates/embed.html
@@ -0,0 +1,35 @@
+<!DOCTYPE html>
+<html lang="es">
+ <head>
+ <meta charset="UTF-8"/>
+ <meta name="viewport" content="width=device-width, initial-scale=1"/>
+ <meta http-equiv="Content-Security-Policy" content="default-src 'self' 'unsafe-inline'; media-src 'self' https://*.googlevideo.com; {{ "img-src 'self' https://*.googleusercontent.com https://*.ggpht.com https://*.ytimg.com;" if not settings.proxy_images else "" }}"/>
+ <title>{{ title }}</title>
+ <link href="/youtube.com/static/favicon.ico" type="image/x-icon" rel="icon"/>
+ <style>
+ body {
+ margin: 0rem;
+ padding: 0rem;
+ }
+ video {
+ width: 100%;
+ height: auto;
+ }
+ </style>
+ </head>
+ <body>
+ <video controls autofocus onmouseleave="{{ title }}"
+ oncontextmenu="{{ title }}" onmouseenter="{{ title }}" title="{{ title }}">
+ {% for video_source in video_sources %}
+ <source src="{{ video_source['src'] }}" type="{{ video_source['type'] }}">
+ {% endfor %}
+ {% for source in subtitle_sources %}
+ {% if source['on'] %}
+ <track label="{{ source['label'] }}" src="{{ source['url'] }}" kind="subtitles" srclang="{{ source['srclang'] }}" default>
+ {% else %}
+ <track label="{{ source['label'] }}" src="{{ source['url'] }}" kind="subtitles" srclang="{{ source['srclang'] }}">
+ {% endif %}
+ {% endfor %}
+ </video>
+ </body>
+</html>
diff --git a/youtube/watch.py b/youtube/watch.py
index d260815..7c140d9 100644
--- a/youtube/watch.py
+++ b/youtube/watch.py
@@ -1,3 +1,4 @@
+import youtube
from youtube import yt_app
from youtube import util, comments, local_playlist, yt_data_extract
import settings
@@ -367,11 +368,19 @@ def get_watch_page(video_id=None):
playlist_id = request.args.get('list')
index = request.args.get('index')
use_invidious = bool(int(request.args.get('use_invidious', '1')))
- tasks = (
- gevent.spawn(comments.video_comments, video_id, int(settings.default_comment_sorting), lc=lc ),
- gevent.spawn(extract_info, video_id, use_invidious,
- playlist_id=playlist_id, index=index)
- )
+ if request.path.startswith('/embed') and settings.embed_page_mode:
+ tasks = (
+ gevent.spawn((lambda: {})),
+ gevent.spawn(extract_info, video_id, use_invidious,
+ playlist_id=playlist_id, index=index),
+ )
+ else:
+ tasks = (
+ gevent.spawn(comments.video_comments, video_id,
+ int(settings.default_comment_sorting), lc=lc),
+ gevent.spawn(extract_info, video_id, use_invidious,
+ playlist_id=playlist_id, index=index),
+ )
gevent.joinall(tasks)
util.check_gevent_exceptions(tasks[1])
comments_info, info = tasks[0].value, tasks[1].value
@@ -471,7 +480,12 @@ def get_watch_page(video_id=None):
'url': transcript_url
})
- return flask.render_template('watch.html',
+ if request.path.startswith('/embed') and settings.embed_page_mode:
+ template_name = 'embed.html'
+ else:
+ template_name = 'watch.html'
+ return flask.render_template(
+ template_name,
header_playlist_names = local_playlist.get_playlist_names(),
uploader_channel_url = ('/' + info['author_url']) if info['author_url'] else '',
time_published = info['time_published'],
@@ -514,7 +528,9 @@ def get_watch_page(video_id=None):
js_data = {
'video_id': video_info['id'],
- }
+ },
+ # for embed page
+ font_family=youtube.font_choices[settings.font],
)