mirror of
https://github.com/JustAnimeCore/JustAnime.git
synced 2026-04-17 22:01:45 +00:00
corsproxy removed
This commit is contained in:
@@ -2,7 +2,7 @@
|
|||||||
const nextConfig = {
|
const nextConfig = {
|
||||||
reactStrictMode: true,
|
reactStrictMode: true,
|
||||||
env: {
|
env: {
|
||||||
NEXT_PUBLIC_CORSPROXY_URL: process.env.CORSPROXY_URL,
|
// Environment variables here
|
||||||
},
|
},
|
||||||
images: {
|
images: {
|
||||||
domains: [
|
domains: [
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
/** @type {import('next').NextConfig} */
|
/** @type {import('next').NextConfig} */
|
||||||
const nextConfig = {
|
const nextConfig = {
|
||||||
env: {
|
env: {
|
||||||
NEXT_PUBLIC_CORSPROXY_URL: process.env.CORSPROXY_URL,
|
// Environment variables here
|
||||||
},
|
},
|
||||||
images: {
|
images: {
|
||||||
unoptimized: true,
|
unoptimized: true,
|
||||||
|
|||||||
@@ -4,12 +4,6 @@ import { useEffect, useRef, useState } from 'react';
|
|||||||
import Hls from 'hls.js';
|
import Hls from 'hls.js';
|
||||||
import NextImage from 'next/image';
|
import NextImage from 'next/image';
|
||||||
|
|
||||||
// Get the M3U8 Proxy URL from environment variables
|
|
||||||
const CORSPROXY_URL = process.env.NEXT_PUBLIC_CORSPROXY_URL;
|
|
||||||
|
|
||||||
// Debug the environment variable
|
|
||||||
console.log('CORSPROXY_URL:', CORSPROXY_URL);
|
|
||||||
|
|
||||||
export default function VideoPlayer({ src, poster, headers = {}, subtitles = [], thumbnails = null, category = 'sub', intro = null, outro = null, autoSkipIntro = false, autoSkipOutro = false, episodeId }) {
|
export default function VideoPlayer({ src, poster, headers = {}, subtitles = [], thumbnails = null, category = 'sub', intro = null, outro = null, autoSkipIntro = false, autoSkipOutro = false, episodeId }) {
|
||||||
const videoRef = useRef(null);
|
const videoRef = useRef(null);
|
||||||
const [isPlaying, setIsPlaying] = useState(false);
|
const [isPlaying, setIsPlaying] = useState(false);
|
||||||
@@ -95,31 +89,6 @@ export default function VideoPlayer({ src, poster, headers = {}, subtitles = [],
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Function to check if a URL is an M3U8 URL and if so, route it through the external proxy
|
|
||||||
const getProxiedUrl = (url) => {
|
|
||||||
if (!url) return url;
|
|
||||||
|
|
||||||
// Log the original URL for debugging
|
|
||||||
console.log('[VideoPlayer] Original URL:', url);
|
|
||||||
|
|
||||||
// Check if the URL is an M3U8 URL
|
|
||||||
if (url.includes('.m3u8') || url.includes('application/vnd.apple.mpegurl')) {
|
|
||||||
// Check if we have a CORS proxy URL configured
|
|
||||||
if (!CORSPROXY_URL) {
|
|
||||||
console.warn('[VideoPlayer] No CORS proxy URL configured, using original URL');
|
|
||||||
return url;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Route through the external M3U8 proxy server
|
|
||||||
const encodedUrl = encodeURIComponent(url);
|
|
||||||
const proxiedUrl = `${CORSPROXY_URL}/m3u8-proxy?url=${encodedUrl}`;
|
|
||||||
console.log('[VideoPlayer] Using proxied URL:', proxiedUrl);
|
|
||||||
return proxiedUrl;
|
|
||||||
}
|
|
||||||
|
|
||||||
return url;
|
|
||||||
};
|
|
||||||
|
|
||||||
// Set headers from props when they change
|
// Set headers from props when they change
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setVideoHeaders(headers);
|
setVideoHeaders(headers);
|
||||||
@@ -256,34 +225,31 @@ export default function VideoPlayer({ src, poster, headers = {}, subtitles = [],
|
|||||||
console.log('[VideoPlayer] HLS is supported, initializing');
|
console.log('[VideoPlayer] HLS is supported, initializing');
|
||||||
|
|
||||||
hls = new Hls({
|
hls = new Hls({
|
||||||
xhrSetup: (xhr, url) => {
|
debug: true,
|
||||||
console.log('[VideoPlayer] HLS XHR setup for URL:', url);
|
|
||||||
|
|
||||||
// Set headers for HLS requests
|
|
||||||
Object.entries(videoHeaders).forEach(([key, value]) => {
|
|
||||||
xhr.setRequestHeader(key, value);
|
|
||||||
console.log(`[VideoPlayer] Setting header: ${key}`);
|
|
||||||
});
|
|
||||||
},
|
|
||||||
// Additional HLS settings for better performance
|
|
||||||
maxBufferLength: 30,
|
maxBufferLength: 30,
|
||||||
maxMaxBufferLength: 60,
|
maxMaxBufferLength: 60,
|
||||||
startLevel: -1, // Auto level selection
|
enableWorker: false, // Disable worker for easier debugging
|
||||||
capLevelToPlayerSize: true, // Limit quality based on player size
|
startLevel: -1, // Start with Auto quality
|
||||||
debug: false,
|
autoLevelEnabled: true, // Enable auto quality switching
|
||||||
// Add more robust error recovery
|
abrEwmaDefaultEstimate: 500000, // Start with a higher bandwidth estimate
|
||||||
fragLoadingMaxRetry: 5,
|
abrBandWidthFactor: 0.95, // Be more aggressive with quality upgrades
|
||||||
manifestLoadingMaxRetry: 5,
|
abrBandWidthUpFactor: 0.7, // Be more conservative with quality downgrades
|
||||||
levelLoadingMaxRetry: 5,
|
xhrSetup: function(xhr, url) {
|
||||||
fragLoadingRetryDelay: 1000,
|
console.log('HLS attempting to load:', url);
|
||||||
manifestLoadingRetryDelay: 1000,
|
|
||||||
levelLoadingRetryDelay: 1000
|
// Apply headers directly to all requests
|
||||||
|
if (!url.startsWith('blob:') && url.includes('://')) {
|
||||||
|
Object.entries(videoHeaders).forEach(([key, value]) => {
|
||||||
|
xhr.setRequestHeader(key, value);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
window.hls = hls; // Save reference for debugging
|
window.hls = hls; // Save reference for debugging
|
||||||
|
|
||||||
// Bind HLS to video element
|
// Bind HLS to video element
|
||||||
const proxiedSrc = getProxiedUrl(src);
|
const proxiedSrc = src;
|
||||||
console.log('[VideoPlayer] Loading proxied source:', proxiedSrc);
|
console.log('[VideoPlayer] Loading proxied source:', proxiedSrc);
|
||||||
hls.loadSource(proxiedSrc);
|
hls.loadSource(proxiedSrc);
|
||||||
hls.attachMedia(video);
|
hls.attachMedia(video);
|
||||||
@@ -390,9 +356,6 @@ export default function VideoPlayer({ src, poster, headers = {}, subtitles = [],
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the proxied URL if it's an M3U8 URL
|
|
||||||
const proxiedSrc = getProxiedUrl(src);
|
|
||||||
|
|
||||||
setIsLoading(true);
|
setIsLoading(true);
|
||||||
|
|
||||||
const setupHls = async () => {
|
const setupHls = async () => {
|
||||||
@@ -414,13 +377,11 @@ export default function VideoPlayer({ src, poster, headers = {}, subtitles = [],
|
|||||||
xhrSetup: function(xhr, url) {
|
xhrSetup: function(xhr, url) {
|
||||||
console.log('HLS attempting to load:', url);
|
console.log('HLS attempting to load:', url);
|
||||||
|
|
||||||
// Only route external URLs through the proxy
|
// Apply headers directly to all requests
|
||||||
if (!url.startsWith(CORSPROXY_URL) && !url.startsWith('blob:') && url.includes('://')) {
|
if (!url.startsWith('blob:') && url.includes('://')) {
|
||||||
// If this is a segment URL from an HLS manifest
|
Object.entries(videoHeaders).forEach(([key, value]) => {
|
||||||
const proxiedUrl = `${CORSPROXY_URL}/ts-proxy?url=${encodeURIComponent(url)}&headers=${encodeURIComponent(JSON.stringify(videoHeaders))}`;
|
xhr.setRequestHeader(key, value);
|
||||||
console.log('Redirecting segment request through proxy:', proxiedUrl);
|
});
|
||||||
xhr.open('GET', proxiedUrl, true);
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -488,8 +449,8 @@ export default function VideoPlayer({ src, poster, headers = {}, subtitles = [],
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (data.response && (data.response.code === 404 || data.url?.includes(CORSPROXY_URL))) {
|
if (data.response && data.response.code === 404) {
|
||||||
setError(`Could not connect to proxy server. Please check if the proxy is running at ${CORSPROXY_URL}`);
|
setError(`Video not found (404). Please try another server.`);
|
||||||
setIsLoading(false);
|
setIsLoading(false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -651,15 +612,7 @@ export default function VideoPlayer({ src, poster, headers = {}, subtitles = [],
|
|||||||
// Format subtitle URL correctly - it might be in different formats
|
// Format subtitle URL correctly - it might be in different formats
|
||||||
let subtitleUrl = activeSubtitle.src || activeSubtitle.url;
|
let subtitleUrl = activeSubtitle.src || activeSubtitle.url;
|
||||||
|
|
||||||
// Some subtitle URLs might need proxying if they're from a different origin
|
// Use subtitle URL directly
|
||||||
if (subtitleUrl && (subtitleUrl.startsWith('http://') || subtitleUrl.startsWith('https://'))) {
|
|
||||||
const proxyBase = process.env.NEXT_PUBLIC_CORSPROXY_URL || '';
|
|
||||||
if (proxyBase && !subtitleUrl.includes(window.location.host)) {
|
|
||||||
subtitleUrl = `${proxyBase}/subtitle-proxy?url=${encodeURIComponent(subtitleUrl)}`;
|
|
||||||
console.log('[VideoPlayer] Proxying subtitle URL:', subtitleUrl);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
track.src = subtitleUrl;
|
track.src = subtitleUrl;
|
||||||
track.default = true;
|
track.default = true;
|
||||||
|
|
||||||
@@ -688,15 +641,6 @@ export default function VideoPlayer({ src, poster, headers = {}, subtitles = [],
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Some subtitle URLs might need proxying if they're from a different origin
|
|
||||||
if (subtitleUrl && (subtitleUrl.startsWith('http://') || subtitleUrl.startsWith('https://'))) {
|
|
||||||
const proxyBase = process.env.NEXT_PUBLIC_CORSPROXY_URL || '';
|
|
||||||
if (proxyBase && !subtitleUrl.includes(window.location.host)) {
|
|
||||||
subtitleUrl = `${proxyBase}/subtitle-proxy?url=${encodeURIComponent(subtitleUrl)}`;
|
|
||||||
console.log('[VideoPlayer] Proxying subtitle URL:', subtitleUrl);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log('[VideoPlayer] Final subtitle URL:', subtitleUrl);
|
console.log('[VideoPlayer] Final subtitle URL:', subtitleUrl);
|
||||||
|
|
||||||
// Remove all existing tracks
|
// Remove all existing tracks
|
||||||
|
|||||||
Reference in New Issue
Block a user