updated missing to active

main
oscar 1 month ago
parent 6c1c2970e8
commit ff0d790570

@ -34,7 +34,7 @@ def find_video_path(video_id: str):
return all_videos[video_id] if video_id in all_videos else None return all_videos[video_id] if video_id in all_videos else None
def mark_missing_videos(cursor, conn): def mark_missing_videos(cursor, conn):
cursor.execute("SELECT video_id, filepath FROM videos WHERE status != 'missing'") cursor.execute("SELECT video_id, filepath FROM videos WHERE status = 'active'")
videos = cursor.fetchall() videos = cursor.fetchall()
with tqdm(videos, desc="Scanning for missing videos...") as pbar: with tqdm(videos, desc="Scanning for missing videos...") as pbar:
@ -51,17 +51,14 @@ def update_video_paths(cursor, conn):
videos = cursor.fetchall() videos = cursor.fetchall()
with tqdm(videos, desc="Updating filepaths...") as pbar: with tqdm(videos, desc="Updating filepaths...") as pbar:
for vid in videos: for vid in videos:
filepath = vid['filepath']
status = vid['status']
path = find_video_path(vid['video_id']) path = find_video_path(vid['video_id'])
if not path: if not path:
continue continue
path = path.replace("\\", "/") path = path.replace("\\", "/")
if path == filepath and status != 'missing': # change this if path == vid['filepath']:
continue continue
cursor.execute("UPDATE videos SET filepath = %s, status = 'active' WHERE id = %s", (path, vid['id'])) cursor.execute("UPDATE videos SET filepath = %s, status = 'active' WHERE id = %s", (path, vid['id']))
@ -69,7 +66,7 @@ def update_video_paths(cursor, conn):
pbar.update(1) pbar.update(1)
def fill_missing_hashes(cursor, conn): def fill_missing_hashes(cursor, conn):
cursor.execute("SELECT video_id, filepath FROM videos WHERE (hash IS NULL OR hash = '') AND status != 'missing'") cursor.execute("SELECT video_id, filepath FROM videos WHERE (hash IS NULL OR hash = '') AND status = 'active'")
videos = cursor.fetchall() videos = cursor.fetchall()
with tqdm(videos, desc="Updating hashes...") as pbar: with tqdm(videos, desc="Updating hashes...") as pbar:
@ -82,7 +79,7 @@ def fill_missing_hashes(cursor, conn):
pbar.update(1) pbar.update(1)
def fill_missing_sizes(cursor, conn): def fill_missing_sizes(cursor, conn):
cursor.execute("SELECT video_id, filepath FROM videos WHERE size = 0 AND status != 'missing'") cursor.execute("SELECT video_id, filepath FROM videos WHERE size = 0 AND status = 'active'")
videos = cursor.fetchall() videos = cursor.fetchall()
with tqdm(videos, desc="Updating sizes...") as pbar: with tqdm(videos, desc="Updating sizes...") as pbar:
@ -95,7 +92,7 @@ def fill_missing_sizes(cursor, conn):
pbar.update(1) pbar.update(1)
def fill_missing_durations(cursor, conn): def fill_missing_durations(cursor, conn):
cursor.execute("SELECT video_id, filepath FROM videos WHERE duration = 0 AND status != 'missing' ORDER BY size ASC") cursor.execute("SELECT video_id, filepath FROM videos WHERE duration = 0 AND status = 'active' ORDER BY size ASC")
videos = cursor.fetchall() videos = cursor.fetchall()
with tqdm(videos, desc="Updating durations...") as pbar: with tqdm(videos, desc="Updating durations...") as pbar:
@ -139,7 +136,7 @@ def fill_missing_gender(cursor, conn):
return False return False
return data return data
cursor.execute("SELECT DISTINCT username, site FROM videos WHERE gender IS NULL AND status != 'missing'") cursor.execute("SELECT DISTINCT username, site FROM videos WHERE gender IS NULL AND status = 'active'")
videos = cursor.fetchall() videos = cursor.fetchall()
api_fetches = 10 api_fetches = 10
@ -168,7 +165,7 @@ def fill_missing_gender(cursor, conn):
pbar.update(1) pbar.update(1)
def generate_thumbnails_for_videos(cursor, conn): def generate_thumbnails_for_videos(cursor, conn):
cursor.execute("SELECT video_id, filepath FROM videos WHERE status != 'missing' AND thumbnail IS NULL") cursor.execute("SELECT video_id, filepath FROM videos WHERE status = 'active' AND thumbnail IS NULL")
videos = cursor.fetchall() videos = cursor.fetchall()
tasks = [] tasks = []
@ -279,16 +276,16 @@ if __name__ == '__main__':
all_videos = get_all_video_files() all_videos = get_all_video_files()
update_video_paths(cursor, conn) update_video_paths(cursor, conn)
mark_missing_videos(cursor, conn) mark_missing_videos(cursor, conn)
move_edited_videos(cursor, conn)
move_concated_videos(cursor, conn)
generate_thumbnails_for_videos(cursor, conn) generate_thumbnails_for_videos(cursor, conn)
fill_missing_sizes(cursor, conn) fill_missing_sizes(cursor, conn)
fill_missing_durations(cursor, conn) fill_missing_durations(cursor, conn)
fill_missing_gender(cursor, conn) fill_missing_gender(cursor, conn)
# fill_missing_hashes(cursor, conn) # fill_missing_hashes(cursor, conn)
move_edited_videos(cursor, conn)
move_concated_videos(cursor, conn)
cursor.close() cursor.close()
conn.close() conn.close()
print("✅ All cleanup tasks completed.") print("✅ All cleanup tasks completed.")

@ -7,10 +7,10 @@ sort_type = {"size": lambda x: sum([video['size'] for video in x]),"count": lamb
def get_videos(cursor, username=None): def get_videos(cursor, username=None):
if username: if username:
cursor.execute("SELECT * FROM videos WHERE username = %s AND status != 'missing';", (username,)) cursor.execute("SELECT * FROM videos WHERE username = %s AND status = 'active';", (username,))
return cursor.fetchall() return cursor.fetchall()
cursor.execute("SELECT * FROM videos WHERE status != 'missing';") cursor.execute("SELECT * FROM videos WHERE status = 'active';")
return cursor.fetchall() return cursor.fetchall()
def organize_videos(): def organize_videos():

@ -16,7 +16,7 @@ def db_get_videos(username: str = None, start=None, end=None):
filepath, size, duration, gender, filepath, size, duration, gender,
created_at, updated_at, thumbnail created_at, updated_at, thumbnail
FROM videos FROM videos
WHERE status != 'missing' WHERE status = 'active'
""" """
params = [] params = []

@ -5,7 +5,7 @@ if __name__ == "__main__":
output_dir = 'U:/streamaster/streams/' output_dir = 'U:/streamaster/streams/'
conn, cursor = config.get_local_db_connection() 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 + "%",)) cursor.execute("SELECT * FROM videos WHERE status = 'active' AND filepath NOT LIKE %s ORDER BY size ASC;", ("%" + output_dir + "%",))
videos = cursor.fetchall() videos = cursor.fetchall()
# process the videos # process the videos

@ -149,7 +149,7 @@ def smart_choice(cursor, small_mb=250):
SELECT v.* SELECT v.*
FROM videos v FROM videos v
WHERE v.codec IS NULL WHERE v.codec IS NULL
AND v.status <> 'missing' AND v.status = 'active'
AND v.filepath IS NOT NULL AND v.filepath IS NOT NULL
AND v.created_at >= NOW() - make_interval(days => %s) AND v.created_at >= NOW() - make_interval(days => %s)
), ),
@ -189,7 +189,7 @@ def smart_choice(cursor, small_mb=250):
SELECT v.* SELECT v.*
FROM videos v FROM videos v
WHERE v.codec IS NULL WHERE v.codec IS NULL
AND v.status <> 'missing' AND v.status = 'active'
AND v.filepath IS NOT NULL AND v.filepath IS NOT NULL
), ),
by_streamer AS ( by_streamer AS (
@ -231,7 +231,7 @@ def smart_choice_by_count(cursor, small_mb=250):
SELECT v.* SELECT v.*
FROM videos v FROM videos v
WHERE v.codec IS NULL WHERE v.codec IS NULL
AND v.status <> 'missing' AND v.status = 'active'
AND v.filepath IS NOT NULL AND v.filepath IS NOT NULL
AND v.created_at >= NOW() - make_interval(days => %s) AND v.created_at >= NOW() - make_interval(days => %s)
), ),
@ -271,7 +271,7 @@ def smart_choice_by_count(cursor, small_mb=250):
SELECT v.* SELECT v.*
FROM videos v FROM videos v
WHERE v.codec IS NULL WHERE v.codec IS NULL
AND v.status <> 'missing' AND v.status = 'active'
AND v.filepath IS NOT NULL AND v.filepath IS NOT NULL
), ),
by_streamer AS ( by_streamer AS (
@ -300,9 +300,9 @@ def smart_choice_by_count(cursor, small_mb=250):
def select_user_videos(username, cursor): def select_user_videos(username, cursor):
if username == "all": if username == "all":
cursor.execute("SELECT * FROM videos WHERE status != 'missing' AND codec IS NULL ORDER BY size ASC") cursor.execute("SELECT * FROM videos WHERE status = 'active' AND codec IS NULL ORDER BY size ASC")
else: else:
cursor.execute("SELECT * FROM videos WHERE username = %s AND status != 'missing' AND codec IS NULL ORDER BY size ASC", (username,)) cursor.execute("SELECT * FROM videos WHERE username = %s AND status = 'active' AND codec IS NULL ORDER BY size ASC", (username,))
return cursor.fetchall() return cursor.fetchall()
def reencode_videos_av1(): def reencode_videos_av1():

Loading…
Cancel
Save