Skip to content
Snippets Groups Projects
FileValidator.py 2.26 KiB
Newer Older
kjk's avatar
kjk committed
import os
import logging
from UltraStarSongFile import UltraStarSongFile

class FileValidator:
    def __init__(self):
        pass

    def validate(self, songfile_object: UltraStarSongFile):
        basepath = os.path.abspath(os.path.dirname(songfile_object.path))
        txtfile = os.path.basename(songfile_object.path)
        if songfile_object.mp3 != "":
            audiopath = os.path.join(basepath, songfile_object.mp3)
            if not os.path.isfile(audiopath):
                logging.error(f"{txtfile} has invalid mp3.")
                return False
        else:
            logging.error(f"{txtfile} has no mp3!")
            return False

        if songfile_object.video != "":
            logging.info(songfile_object.video)
            videopath = os.path.join(basepath, songfile_object.video)
            logging.info(videopath)
            if not os.path.isfile(videopath):
                logging.error(f"{txtfile} has invalid videofile.")
                return False
        else:
            logging.info(f"{txtfile} has no videofile.")

        if songfile_object.background != "":
            backgroundpath = os.path.join(basepath, songfile_object.background)
            if not os.path.isfile(backgroundpath):
                logging.error(f"{txtfile} has invalid backgroundfile.")
                return False
        else:
            logging.info(f"{txtfile} has no backgroundfile.")

        if songfile_object.cover != "":
            coverpath = os.path.join(basepath, songfile_object.cover)
            if not os.path.isfile(coverpath):
                logging.error(f"{txtfile} has invalid coverfile")
                return False
        else:
            logging.info(f"{txtfile} has no coverfile.")

        return True

    def validate_mp3(self, songfile_object: UltraStarSongFile):
        basepath = os.path.abspath(os.path.dirname(songfile_object.path))
        txtfile = os.path.basename(songfile_object.path)
        if songfile_object.mp3 != "":
            audiopath = os.path.join(basepath, songfile_object.mp3)
            if not os.path.isfile(audiopath):
                logging.error(f"{txtfile} has invalid mp3.")
                return False
        else:
            logging.error(f"{txtfile} has no mp3!")
            return False

        return True