Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion feed_scraper/video_scraper.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ def fetch_feed(feed, force_refetch, max_per_feed=200):
article_kwargs["full_text_html"] = f"""
<iframe style="width: 100%; height: auto; min-height: 30vw; max-height:400px; aspect-ratio: 16 / 9;"
referrerpolicy="no-referrer"
src="https://www.youtube-nocookie.com/embed/{video['videoId']}?rel=0&autoplay=1"
src="/youtube-proxy/?v={video['videoId']}&rel=0&autoplay=1"
frameborder="0" allow="autoplay; encrypted-media" tabindex="0" allowfullscreen></iframe><br>\n
<div>{article_kwargs["extract"]}</div>
"""
Expand Down
1 change: 1 addition & 0 deletions news_platform/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
CSRF_TRUSTED_ORIGINS = HOSTS
ALLOWED_HOSTS = [urlparse(url).netloc for url in HOSTS]
CORS_ALLOWED_ORIGINS = HOSTS
X_FRAME_OPTIONS = "ALLOW-FROM " + MAIN_HOST

if (sentry_sdk_url := os.environ.get("SENTRY_URL", None)) is not None:
sentry_sdk.init(
Expand Down
2 changes: 2 additions & 0 deletions news_platform/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

from django.contrib import admin
from django.contrib.auth.views import LogoutView
from django.views.generic import TemplateView
from django.urls import include, path
from drf_spectacular.views import SpectacularAPIView, SpectacularSwaggerView

Expand Down Expand Up @@ -59,6 +60,7 @@ def trigger_error(request):
path("view/<int:article>/", articleView, name="view_article"),
path("redirect/<int:article>/", RedirectView, name="redirect_article"),
path("img-error/<int:article>/", ImageErrorView, name="image_error"),
path("youtube-proxy/", TemplateView.as_view(template_name="youtube-proxy.html"), name="youtube_proxy"),
path("", homeView, name="home"),
path("auth/", include("djoser.urls")),
path("auth/", include("djoser.urls.jwt")),
Expand Down
83 changes: 83 additions & 0 deletions templates/youtube-proxy.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
<!DOCTYPE html>
<!-- As per guide https://medium.com/@davidvesely.cz/fixing-youtube-error-153-in-ios-capacitor-apps-a-simple-proxy-solution-5807d3df83d5 --->
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, viewport-fit=cover">
<meta name="referrer" content="strict-origin-when-cross-origin">
<title>YouTube Video</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
html, body {
width: 100%;
height: 100%;
overflow: hidden;
background: #000;
}
#player {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
border: 0;
}
</style>
</head>
<body>
<iframe
id="player"
allowfullscreen
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share"
referrerpolicy="strict-origin-when-cross-origin"
></iframe>
<script>
(function() {
// Parse URL parameters
const urlParams = new URLSearchParams(window.location.search);
// Get video ID (required)
const videoId = urlParams.get('v');
if (!videoId) {
document.body.innerHTML = '<div style="color: white; padding: 20px; text-align: center;">Error: Missing video ID parameter (?v=VIDEO_ID)</div>';
return;
}
// Get optional parameters with defaults
const autoplay = urlParams.get('autoplay') || '0';
const loop = urlParams.get('loop') || '0';
const mute = urlParams.get('mute') || '0';
const playlist = urlParams.get('playlist') || videoId;
const controls = urlParams.get('controls') || '1';
const rel = urlParams.get('rel') || '0';
const modestbranding = urlParams.get('modestbranding') || '1';
const playsinline = urlParams.get('playsinline') || '1';
// Build YouTube embed URL parameters
const embedParams = new URLSearchParams({
autoplay: autoplay,
controls: controls,
rel: rel,
modestbranding: modestbranding,
playsinline: playsinline,
enablejsapi: '1',
origin: window.location.origin
});
// Add loop and playlist if loop is enabled
if (loop === '1') {
embedParams.append('loop', '1');
embedParams.append('playlist', playlist);
}
// Add mute if enabled
if (mute === '1') {
embedParams.append('mute', '1');
}
// Construct final URL
const embedUrl = `https://www.youtube-nocookie.com/embed/${encodeURIComponent(videoId)}?${embedParams.toString()}`;
// Set iframe src
document.getElementById('player').src = embedUrl;
})();
</script>
</body>
</html>