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.
53 lines
1.9 KiB
Python
53 lines
1.9 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")
|
|
|
|
print("Grouping videos for concatenation...")
|
|
# 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:
|
|
print(100*"=")
|
|
print("\n"*2)
|
|
|
|
video_id = video_list[0]['video_id']
|
|
videos_sum_size = sum([video['size'] for video in video_list])
|
|
|
|
print(f"Group {video_id} has {len(video_list)} videos and total size of {videos_sum_size} MB")
|
|
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
|
|
|
|
print(f"Failed to process {len(video_list)} input videos into output video.")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
organize_videos() |