You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
43 lines
1.6 KiB
Python
43 lines
1.6 KiB
Python
import os
|
|
from config import get_local_db_connection
|
|
from tqdm import tqdm
|
|
import shutil
|
|
|
|
RECORDER_DIR = 'E:/streamaster/streamaster/downloaded/'
|
|
ARCHIVE_DIR = 'U:/streamaster/streams/'
|
|
|
|
|
|
def get_all_video_files():
|
|
files = {}
|
|
for root, _, filenames in os.walk(RECORDER_DIR):
|
|
for filename in filenames:
|
|
if filename.endswith(".mp4"):
|
|
video_id = filename.split(".")[0]
|
|
files[video_id] = os.path.join(root, filename)
|
|
return files
|
|
|
|
if __name__ == '__main__':
|
|
conn, cursor = get_local_db_connection()
|
|
|
|
downloaded_videos = get_all_video_files()
|
|
|
|
# for every video in downloaded_videos, re-create the folder it would have been in, int he archive directory
|
|
# if it exists there already, check if its corrupted. if so, then move the one in the downloaded to the archive dir
|
|
# because it failed during moving in the other script
|
|
|
|
|
|
for video_id in tqdm(downloaded_videos.keys(), desc="Checking for failed videos..."):
|
|
video_path = downloaded_videos[video_id]
|
|
|
|
try:
|
|
cursor.execute("SELECT username FROM videos WHERE video_id = %s", (video_id,))
|
|
username = cursor.fetchone()['username']
|
|
except:
|
|
print(f"Video {video_id} does not exist in the database")
|
|
continue
|
|
|
|
archive_path = os.path.join(ARCHIVE_DIR, username, video_path.replace(RECORDER_DIR, ''))
|
|
|
|
if os.path.exists(archive_path):
|
|
print(f"Video {video_id} already exists in the archive directory")
|
|
shutil.move(video_path, archive_path) |