From 91db934f525afc8fac5e13c0d302f4f76b4f86a1 Mon Sep 17 00:00:00 2001 From: rmilooo <73422068+rmilooo@users.noreply.github.com> Date: Wed, 1 Jan 2025 22:10:56 +0100 Subject: [PATCH] Added Requirements.txt using pipreqs --- generateRequirements.sh | 1 + helper.py | 21 +++++++++++++++++++++ requirements.txt | 3 +++ revivetube.py | 20 +------------------- 4 files changed, 26 insertions(+), 19 deletions(-) create mode 100644 generateRequirements.sh create mode 100644 requirements.txt diff --git a/generateRequirements.sh b/generateRequirements.sh new file mode 100644 index 0000000..a182d84 --- /dev/null +++ b/generateRequirements.sh @@ -0,0 +1 @@ +pipreqs . --force --ignore .venv \ No newline at end of file diff --git a/helper.py b/helper.py index a514fcc..fa4c52a 100644 --- a/helper.py +++ b/helper.py @@ -1,3 +1,7 @@ +import json +import subprocess + + def read_file(path): assert isinstance(path, str), "Path must be a string" @@ -9,3 +13,20 @@ def read_file(path): return "Error: File not found." except Exception as e: return f"Error: {str(e)}" + + +def get_video_duration_from_file(video_path): + try: + result = subprocess.run( + ['ffprobe', '-v', 'error', '-show_format', '-show_streams', '-of', 'json', video_path], + stdout=subprocess.PIPE, stderr=subprocess.PIPE + ) + + video_info = json.loads(result.stdout) + + duration = float(video_info['format']['duration']) + + return duration + except Exception as e: + print(f"Can't fetch Video-Duration: {str(e)}") + return 0 \ No newline at end of file diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..76a77cb --- /dev/null +++ b/requirements.txt @@ -0,0 +1,3 @@ +Flask==3.1.0 +Requests==2.32.3 +yt_dlp==2024.12.23 diff --git a/revivetube.py b/revivetube.py index 09b58a3..031c86c 100644 --- a/revivetube.py +++ b/revivetube.py @@ -14,7 +14,6 @@ If you use this Code, you agree to https://revivemii.fr.to/revivetube/t-and-p.ht ReviveMii Project: https://revivemii.fr.to/ """ -import json import os import shutil import subprocess @@ -27,7 +26,7 @@ import requests import yt_dlp from flask import Flask, request, render_template_string, send_file, Response, abort, jsonify -from helper import read_file +from helper import read_file, get_video_duration_from_file app = Flask(__name__) @@ -241,23 +240,6 @@ def format_duration(seconds): return f"{minutes}:{str(seconds).zfill(2)}" -def get_video_duration_from_file(video_path): - try: - result = subprocess.run( - ['ffprobe', '-v', 'error', '-show_format', '-show_streams', '-of', 'json', video_path], - stdout=subprocess.PIPE, stderr=subprocess.PIPE - ) - - video_info = json.loads(result.stdout) - - duration = float(video_info['format']['duration']) - - return duration - except Exception as e: - print(f"Can't fetch Video-Duration: {str(e)}") - return 0 - - @app.route("/watch", methods=["GET"]) def watch(): video_id = request.args.get("video_id")