Board: Open.
BAN: Max 5 Scene Requests per time per 24 HOURS! | Mark your topics [FiLLED] after | No Non-Scene Audio Requests
Harassment of any kind not tolerated on the forum. Instant ban.

Mass checking scripts [Python 3x]

Track ID's, abuse, or anything else on your minds :)
Post Reply
khudea
100 Posts
100 Posts
Posts: 142
Joined: Fri Jan 27, 2023 10:08 pm
Has thanked: 142 times
Been thanked: 4 times
Seychelles

Mass checking scripts [Python 3x]

Post by khudea » Sun May 28, 2023 5:33 pm

Hello. Being a lazy fuck (as usual), today I got AI to craft me some scripts that can mass-check for missing NFO, M3U and SFV across folders and folders with bad files, based on existing SFVs. I'm sharing them here, since I thought some users here might find them useful. You need Python 3x in order to run them. They seem to be working fine on Windows. Haven't tested on Linux.

Missing files checkers:


nfo.py

Code: Select all

import os

def find_missing_nfo_files(folder):
    missing_nfo_folders = []

    for root, dirs, files in os.walk(folder):
        if not any(file.lower().endswith('.nfo') for file in files):
            missing_nfo_folders.append(root)

    return missing_nfo_folders

def main():
    folder = input("Enter the path of the folder to scan: ")
    missing_nfo_folders = find_missing_nfo_files(folder)

    if missing_nfo_folders:
        print("Folders missing .nfo files:")
        for folder in missing_nfo_folders:
            print(folder)
    else:
        print("No folders are missing .nfo files.")

if __name__ == "__main__":
    main()
m3u.py

Code: Select all

import os

def find_missing_m3u_files(folder):
    missing_m3u_folders = []

    for root, dirs, files in os.walk(folder):
        if not any(file.lower().endswith('.m3u') for file in files):
            missing_m3u_folders.append(root)

    return missing_m3u_folders

def main():
    folder = input("Enter the path of the folder to scan: ")
    missing_m3u_folders = find_missing_m3u_files(folder)

    if missing_m3u_folders:
        print("Folders missing .m3u files:")
        for folder in missing_m3u_folders:
            print(folder)
    else:
        print("No folders are missing .m3u files.")

if __name__ == "__main__":
    main()
sfv.py

Code: Select all

import os

def find_missing_sfv_files(folder):
    missing_sfv_folders = []

    for root, dirs, files in os.walk(folder):
        if not any(file.lower().endswith('.sfv') for file in files):
            missing_sfv_folders.append(root)

    return missing_sfv_folders

def main():
    folder = input("Enter the path of the folder to scan: ")
    missing_sfv_folders = find_missing_sfv_files(folder)

    if missing_sfv_folders:
        print("Folders missing .sfv files:")
        for folder in missing_sfv_folders:
            print(folder)
    else:
        print("No folders are missing .sfv files.")

if __name__ == "__main__":
    main()

Mass file integrity checker (based on [External Link Removed for Guests]by abjdiat)

mass_sfv_integrity.py

Code: Select all

import os
import sys
import zlib
from pathlib import Path

def crc(file_path):
    prev = 0
    if os.path.exists(file_path):
        with open(file_path, "rb") as store:
            for eachLine in store:
                prev = zlib.crc32(eachLine, prev)
        return "%x" % (prev & 0xFFFFFFFF)
    else:
        return None

def process_sfv_file(sfv_file_path):
    with open(sfv_file_path) as sfv_file:
        names_list = []
        sfv_list = []
        for line in sfv_file.readlines():
            line = line.strip()
            if line and not line.startswith(";"):
                m = line.rsplit(' ', 1)
                if len(m) == 2:
                    names_list.append(m[0])
                    sfv_list.append(m[1])

        folder_has_bad_files = False
        for i in range(len(names_list)):
            file_path = os.path.join(os.path.dirname(sfv_file_path), names_list[i])
            calc_sfv_value = crc(file_path)
            if calc_sfv_value is None or sfv_list[i].lstrip('0').lower() != calc_sfv_value.lower():
                folder_has_bad_files = True
                break

        if folder_has_bad_files:
            print(f"\nFolder with bad files: {os.path.dirname(sfv_file_path)}")

def scan_folder(folder_path):
    sfv_files = []
    for root, _, files in os.walk(folder_path):
        for file in files:
            if file.endswith(".sfv"):
                sfv_files.append(os.path.join(root, file))

    total_sfv_files = len(sfv_files)
    for index, sfv_file in enumerate(sfv_files, start=1):
        process_sfv_file(sfv_file)
        progress = (index / total_sfv_files) * 100
        sys.stdout.write(f"\rProgress: {progress:.2f}%")
        sys.stdout.flush()

if __name__ == "__main__":
    folder = input("Enter the folder path: ")
    if os.path.exists(folder):
        scan_folder(folder)
    else:
        print("The folder does not exist.")
Obviously, they're not perfect, and if you happen to be a programmer, feel free to improve them. Since they're AI generated and/or based on other scripts, I'm not taking any credit for them.

Enjoy!

Post Reply

Who is online

Users browsing this forum: Skaterr and 0 guests