# # Module to record our understanding of everything on disk. This # includes the raw DVDs, the ripped videos, and the Plex libraries. # # The "watch.py" module will update this data, as changes are made. # import os import logging LOGGER = logging.getLogger(__name__) # The video extensions we'll look for. VIDEO_EXT = { '.mp4', '.m4v', '.mkv', } # Plex libraries. Personalized for gstein. LIBRARIES = { 'movies', 'tv', 'workout', 'home', } DEFAULT_LIB = 'movies' class DVDRoot: def __init__(self, rootdir): self.rootdir = rootdir self.dvds = set() def load(self): for entry in os.scandir(self.rootdir): if entry.is_dir(): #LOGGER.debug(f'ADDING: {entry.name}') self.dvds.add(DVDDirectory(entry)) class DVDDirectory: def __init__(self, entry): self.dvddir = entry.path self.lib = None self.streams = set() # Load initial data self.scan() def scan(self): "Scan the DVDDIR to gather data. Replaces prior scan data." lib = None streams = set() for name in os.listdir(self.dvddir): if name in LIBRARIES: if lib: ### warning two libs named pass lib = name elif is_video(os.path.join(self.dvddir, name)): streams.add(name) self.lib = lib self.streams = streams #LOGGER.debug(f'LIBRARY: {lib} STREAMS: {streams}') def is_video(fname): return os.path.splitext(fname)[1] in VIDEO_EXT class LibraryRoot: pass if __name__ == '__main__': import sys root = DVDRoot(sys.argv[1]) root.load()