CLEANUP AND UPDATE

main
oscar 1 month ago
parent f726684c1d
commit 5c3f8dbd6a

@ -1,62 +0,0 @@
from funcs import process_videos, group_videos, match_data_to_video_fast, get_all_videos, get_all_data
from flask import Flask, render_template
import os
from collections import defaultdict
app = Flask(__name__)
SCAN_DIRS = [
"E:/streamaster/downloaded/",
"U:/encoded",
"U:/count_sorted"
]
DATA_DIRS = [
"E:/streamaster/data",
"E:/streamaster/downloaded",
]
# ----------- Data Processing -----------
def load_video_data():
videos = []
for d in SCAN_DIRS:
videos += get_all_videos(d)
data = []
for d in DATA_DIRS:
data += get_all_data(d)
parsed_videos, unmatched = match_data_to_video_fast(videos, data)
parsed_videos = process_videos(parsed_videos)
video_data = group_videos(parsed_videos, sort_by="count", order="desc")
return video_data
def compute_analytics(video_data):
storage_usage = defaultdict(lambda: {"total_size": 0, "video_count": 0})
per_video_sizes = {}
for (username, platform), vids in video_data.items():
total_size_gb = sum(v['size'] for v in vids) / 1024 # Convert MB to GB
avg_size_gb = (total_size_gb / len(vids)) if vids else 0
storage_usage[(username, platform)]["total_size"] += total_size_gb
storage_usage[(username, platform)]["video_count"] += len(vids)
per_video_sizes[(username, platform)] = avg_size_gb
return storage_usage, per_video_sizes
# ----------- Flask Routes -----------
@app.route("/")
def analytics_dashboard():
video_data = load_video_data()
storage_usage, per_video_sizes = compute_analytics(video_data)
# Sort by total storage used
sorted_usage = sorted(storage_usage.items(), key=lambda x: x[1]["total_size"], reverse=True)
return render_template("analytics.html",
storage_usage=sorted_usage,
avg_sizes=per_video_sizes)
if __name__ == "__main__":
app.run(debug=True)

@ -3,10 +3,11 @@ from config import get_local_db_connection
from funcs import get_duration, get_file_size_in_mb, calculate_file_hash
from tqdm import tqdm
import os, hashlib, subprocess
import os, hashlib, subprocess, shutil
from config import get_local_db_connection
from concurrent.futures import ThreadPoolExecutor
EDITED_DIR = "edited/"
THUMB_DIR = "static/thumbnails"
THUMB_WIDTH = 640
FF_QUALITY = "80"
@ -211,12 +212,34 @@ def _gen_thumb_cmd(src: str, dest: str):
"-q:v", FF_QUALITY,
dest
]
def move_edited_videos(cursor, conn):
edited_videos = [f for f in os.listdir(EDITED_DIR) if os.path.isfile(os.path.join(EDITED_DIR, f)) and f.endswith(".mp4")]
for filename in edited_videos:
edited_path = os.path.join(EDITED_DIR, filename)
video_id = filename.split(".")[0]
cursor.execute("SELECT filepath FROM videos WHERE video_id = %s", (video_id,))
video = cursor.fetchone()
if not video:
continue
video_path = video['filepath']
if not os.path.exists(video_path):
continue
shutil.move(edited_path, video_path)
print(f"✅ Moved edited video {video_id} to {video_path}")
if __name__ == '__main__':
conn, cursor = get_local_db_connection()
print("🔍 Scanning for missing data...")
move_edited_videos(cursor, conn)
if True:
all_videos = get_all_video_files()
fill_missing_filepaths(cursor, conn)

@ -331,11 +331,6 @@ def concatenate_videos(grouped_videos, directory):
return processed_videos
def get_all_videos(directory):
# find all .mp4 files in the directory and its subdirectories
videos = []

@ -17,7 +17,8 @@ if __name__ == "__main__":
with tqdm(total=total_size, desc=f"Moved [{total_moved}/{len(videos)}] videos", unit="MB") as pbar:
for video in videos:
pbar.update(int(video["size"]))
file_size_mb = int(video["size"]) if video["size"] >= 1 else 1
pbar.update(file_size_mb)
username = video["username"]
video_path = video["filepath"]
@ -31,7 +32,7 @@ if __name__ == "__main__":
if os.path.exists(new_video_path):
cursor.execute("UPDATE videos SET filepath = %s WHERE id = %s;", (new_video_path, video["id"],))
conn.commit()
conn.commit()
continue
if not os.path.exists(video_path):

Binary file not shown.
Loading…
Cancel
Save