import os, json, bunny, config        
        
db, cursor = config.gen_connection()

cursor.execute('SELECT media_id FROM media WHERE media_id IS NOT NULL;')
mediaIDS = cursor.fetchall()



pins = json.load(open('pins.json', 'r'))

videos = json.load(open('db_videos.json', 'r'))
pins = json.load(open('db_pins.json', 'r'))
ids = [video['id'] for video in videos]

for pin in pins:
    if pin['id'] in ids:
        pins.remove(pin)

# save to the file
json.dump(pins, open('db_pins.json', 'w'))


medias = json.load(open('allVideos.json', 'r'))
mp4Medias = [media for media in medias if media['hasMP4Fallback'] == True]

missing = json.load(open('missing_videos.json', 'r'))

count = 0
cacheDir = 'old_mp4fallback_cache'
print(f"Found {len(medias)} files to process.")
for media in mp4Medias:
    count += 1
    filePath = os.path.join(cacheDir, media['guid'] + '.mp4')
    
    