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.

62 lines
2.2 KiB
Python

from funcs import group_videos, group_for_concatenation_simple
from concat_helper import concatenate_videos
import os, config, shutil
MOVE_FUCKED = False
sort_type = {"size": lambda x: sum([video['size'] for video in x]),"count": lambda x: len(x)}
def get_videos(cursor, username=None):
if username:
cursor.execute("SELECT * FROM videos WHERE username = %s AND status = 'active';", (username,))
return cursor.fetchall()
cursor.execute("SELECT * FROM videos WHERE status = 'active';")
return cursor.fetchall()
def organize_videos():
username = input("Enter username: ")
conn, cursor = config.get_local_db_connection()
videos = get_videos(cursor, username)
# process the videos
video_data = group_videos(videos, sort_by="size", order="asc")
# group all videos for concatation first.
grouped_videos = []
for user, videos in video_data.items():
grouped_videos.extend(group_for_concatenation_simple(videos))
sorted_processed_videos = sorted(grouped_videos, key=sort_type["count"], reverse=True)
# group the videos for concatenation
for video_list in sorted_processed_videos:
video_id = video_list[0]['video_id']
videos_sum_size = sum([video['size'] for video in video_list])
print(100*"=")
print("\n"*2)
print(f"Group {video_id} has {len(video_list)} videos and total size of {videos_sum_size} MB")
print("\n"*2)
print(100*"=")
main_video = concatenate_videos(video_list, reencode_concate=True)
if main_video:
print(f"Processed {len(video_list)} input videos into {main_video["filepath"]} output video.")
continue
if MOVE_FUCKED:
print(f"Videos are fucked.")
main_video = video_list[0]
video_name = main_video['video_id']
fucked_dir = os.path.join("concate_fucked", video_name)
os.makedirs(fucked_dir, exist_ok=True)
for video in video_list:
shutil.move(video['filepath'], os.path.join(fucked_dir, os.path.basename(video['filepath'])))
if __name__ == "__main__":
organize_videos()