mirror of
https://github.com/ReviveMii/riivivetube
synced 2025-09-04 04:21:13 +02:00
Update riivivetube.py
This commit is contained in:
parent
d8ef70896f
commit
d4c8f66166
@ -1,26 +1,21 @@
|
|||||||
|
# used code and swf files from liinback and yt2009wii
|
||||||
|
|
||||||
# work in progress
|
# work in progress
|
||||||
# videos and more things are not working
|
|
||||||
# search and trending is working
|
|
||||||
# swf files from yt2009wii
|
|
||||||
|
|
||||||
|
|
||||||
from flask import Flask, send_from_directory, send_file, request, Response, jsonify, stream_with_context
|
from flask import Flask, send_from_directory, send_file, request, Response, jsonify, stream_with_context
|
||||||
import os
|
import os
|
||||||
import json
|
|
||||||
import re
|
|
||||||
import requests
|
import requests
|
||||||
import xml.etree.ElementTree as ET
|
import xml.etree.ElementTree as ET
|
||||||
from datetime import datetime
|
|
||||||
import subprocess
|
import subprocess
|
||||||
import time
|
import time
|
||||||
import yt_dlp
|
|
||||||
import youtubei
|
import youtubei
|
||||||
from concurrent.futures import ThreadPoolExecutor, as_completed
|
from concurrent.futures import ThreadPoolExecutor, as_completed
|
||||||
import threading
|
import threading
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
#stream_cache = {}
|
stream_cache = {}
|
||||||
#CACHE_DURATION = 300
|
CACHE_DURATION = 300
|
||||||
executor = ThreadPoolExecutor(max_workers=10)
|
executor = ThreadPoolExecutor(max_workers=10)
|
||||||
CATEGORIES = ["trending", "music", "gaming", "sports", "news"]
|
CATEGORIES = ["trending", "music", "gaming", "sports", "news"]
|
||||||
DL_FOLDER = "./dl"
|
DL_FOLDER = "./dl"
|
||||||
@ -33,7 +28,7 @@ def get_first_video_id_from_route(category):
|
|||||||
url = f"http://127.0.0.1:5005/{category}"
|
url = f"http://127.0.0.1:5005/{category}"
|
||||||
response = requests.get(url)
|
response = requests.get(url)
|
||||||
if response.status_code != 200:
|
if response.status_code != 200:
|
||||||
print(f"[{category}] HTTP ERROR : HTTP {response.status_code}")
|
print(f"[{category}] Error fetching: HTTP {response.status_code}")
|
||||||
return None
|
return None
|
||||||
ns = {
|
ns = {
|
||||||
'yt': 'http://www.youtube.com/xml/schemas/2015'
|
'yt': 'http://www.youtube.com/xml/schemas/2015'
|
||||||
@ -50,7 +45,7 @@ def get_first_video_id_from_route(category):
|
|||||||
return None
|
return None
|
||||||
return videoid_el.text.strip()
|
return videoid_el.text.strip()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"[{category}] xml parsing error: {e}")
|
print(f"[{category}] XML parsing error: {e}")
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def download_thumbnail(video_id, category):
|
def download_thumbnail(video_id, category):
|
||||||
@ -103,16 +98,16 @@ class GetVideoInfo:
|
|||||||
}
|
}
|
||||||
response = requests.post(streamUrl, json=payload, headers=headers)
|
response = requests.post(streamUrl, json=payload, headers=headers)
|
||||||
if response.status_code != 200:
|
if response.status_code != 200:
|
||||||
return f"Error retrieving video info: {response.status_code}", response.status_code
|
return f"video info error: {response.status_code}", response.status_code
|
||||||
|
|
||||||
try:
|
try:
|
||||||
json_data = response.json()
|
json_data = response.json()
|
||||||
# print(json_data)
|
# debug print(json_data)
|
||||||
title = json_data['videoDetails']['title']
|
title = json_data['videoDetails']['title']
|
||||||
length_seconds = json_data['videoDetails']['lengthSeconds']
|
length_seconds = json_data['videoDetails']['lengthSeconds']
|
||||||
author = json_data['videoDetails']['author']
|
author = json_data['videoDetails']['author']
|
||||||
except KeyError as e:
|
except KeyError as e:
|
||||||
return f"Missing key: {e}", 400
|
return f"KeyError ): {e}", 400
|
||||||
|
|
||||||
fmtList = "43/854x480/9/0/115"
|
fmtList = "43/854x480/9/0/115"
|
||||||
fmtStreamMap = f"43|"
|
fmtStreamMap = f"43|"
|
||||||
@ -149,7 +144,7 @@ class GetVideoInfo:
|
|||||||
def get_video_info():
|
def get_video_info():
|
||||||
video_id = request.args.get('video_id')
|
video_id = request.args.get('video_id')
|
||||||
if not video_id:
|
if not video_id:
|
||||||
return jsonify({"error": "Missing video_id parameter"}), 400
|
return jsonify({"error": "video id is missing"}), 400
|
||||||
|
|
||||||
video_info = GetVideoInfo().build(video_id)
|
video_info = GetVideoInfo().build(video_id)
|
||||||
return video_info
|
return video_info
|
||||||
@ -170,9 +165,53 @@ def serve_video(filename):
|
|||||||
def player():
|
def player():
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
#@app.route('/get_video', methods=['GET'])
|
|
||||||
#def get_video():
|
@app.route('/get_video', methods=['GET'])
|
||||||
#work in progress
|
def get_video():
|
||||||
|
if not os.path.exists("sigma/videos"):
|
||||||
|
os.makedirs("sigma/videos")
|
||||||
|
|
||||||
|
video_id = request.args.get('video_id')
|
||||||
|
if not video_id:
|
||||||
|
return "", 400
|
||||||
|
|
||||||
|
folder = "sigma/videos"
|
||||||
|
mp4_path = os.path.join(folder, f"{video_id}.mp4")
|
||||||
|
webm_path = os.path.join(folder, f"{video_id}.webm")
|
||||||
|
|
||||||
|
if os.path.exists(webm_path):
|
||||||
|
return send_file(webm_path, as_attachment=True)
|
||||||
|
|
||||||
|
ytdlp_cmd = [
|
||||||
|
'yt-dlp',
|
||||||
|
f'https://www.youtube.com/watch?v={video_id}',
|
||||||
|
'-f', 'best[ext=mp4]/best',
|
||||||
|
'-o', mp4_path
|
||||||
|
]
|
||||||
|
|
||||||
|
try:
|
||||||
|
result = subprocess.run(ytdlp_cmd, capture_output=True, text=True)
|
||||||
|
if result.returncode != 0:
|
||||||
|
return f"yt-dlp error: {result.stderr}", 500
|
||||||
|
except Exception as e:
|
||||||
|
return f"{e}", 500
|
||||||
|
|
||||||
|
if not os.path.exists(mp4_path):
|
||||||
|
return "Download failed", 500
|
||||||
|
|
||||||
|
vf = 'scale=-1:360'
|
||||||
|
ffmpeg_cmd = [
|
||||||
|
'ffmpeg', '-i', mp4_path,
|
||||||
|
'-vf', vf,
|
||||||
|
'-c:v', 'libvpx', '-b:v', '300k', '-cpu-used', '8',
|
||||||
|
'-pix_fmt', 'yuv420p', '-c:a', 'libvorbis', '-b:a', '128k',
|
||||||
|
'-r', '30', '-g', '30',
|
||||||
|
webm_path
|
||||||
|
]
|
||||||
|
|
||||||
|
subprocess.run(ffmpeg_cmd)
|
||||||
|
|
||||||
|
return send_file(webm_path, as_attachment=True) if os.path.exists(webm_path) else "", 500
|
||||||
|
|
||||||
|
|
||||||
@app.route('/apiplayer-loader')
|
@app.route('/apiplayer-loader')
|
||||||
|
Loading…
x
Reference in New Issue
Block a user