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.
50 lines
1.9 KiB
Python
50 lines
1.9 KiB
Python
import os, shutil, config
|
|
from tqdm import tqdm
|
|
|
|
if __name__ == "__main__":
|
|
output_dir = 'U:/streamaster/streams/'
|
|
|
|
conn, cursor = config.get_local_db_connection()
|
|
cursor.execute("SELECT * FROM videos WHERE status != 'missing' AND filepath NOT LIKE %s ORDER BY size ASC;", ("%" + output_dir + "%",))
|
|
videos = cursor.fetchall()
|
|
|
|
# process the videos
|
|
output_dir = "U:/streamaster/streams/"
|
|
os.makedirs(output_dir, exist_ok=True)
|
|
|
|
total_size = int(sum([video['size'] for video in videos]))
|
|
total_moved = 0
|
|
|
|
with tqdm(total=total_size, desc=f"Moved [{total_moved}/{len(videos)}] videos", unit="MB") as pbar:
|
|
for video in videos:
|
|
file_size_mb = int(video["size"]) if video["size"] >= 1 else 1
|
|
pbar.update(file_size_mb)
|
|
|
|
username = video["username"]
|
|
video_path = video["filepath"]
|
|
|
|
if not video_path:
|
|
continue
|
|
|
|
user_folder = os.path.join(output_dir, username)
|
|
video_name = os.path.basename(video_path)
|
|
new_video_path = os.path.join(user_folder, video_name)
|
|
|
|
if os.path.exists(new_video_path):
|
|
cursor.execute("UPDATE videos SET filepath = %s WHERE id = %s;", (new_video_path, video["id"],))
|
|
conn.commit()
|
|
continue
|
|
|
|
if not os.path.exists(video_path):
|
|
continue
|
|
|
|
os.makedirs(user_folder, exist_ok=True)
|
|
|
|
# move the file to the new location
|
|
shutil.move(video_path, new_video_path)
|
|
|
|
cursor.execute("UPDATE videos SET filepath = %s WHERE id = %s;", (new_video_path, video["id"],))
|
|
conn.commit()
|
|
|
|
total_moved += 1
|
|
pbar.desc = f"Moved [{total_moved}/{len(videos)}] videos" |