Пример #1
0
def main():
    """Test code that processes a series of directories to generate DvdInfo instances"""
    from oreillycookbook.files import all_folders
    import argparse
    from pprint import pprint
    
    parser = argparse.ArgumentParser(
        description='Process a series of folders, reading the DVD information, display it to stdout')
    parser.add_argument('root_dir', nargs=1)
    args = parser.parse_args()
    
    formatter = logging.Formatter(
        '%(asctime)s - %(levelname)5s - %(module)s:%(lineno)03d[%(funcName)s()] - %(message)s')
    # create file handler and set level to debug
    fh = logging.FileHandler(filename='hbscan.log')
    fh.setLevel(logging.DEBUG)
    fh.setFormatter(formatter)
    logger.addHandler(fh)
    
    # create console handler and set level to debug
    ch = logging.StreamHandler()
    ch.setLevel(logging.DEBUG)
    ch.setFormatter(formatter)
    logger.addHandler(ch)
    
    # set overall logging detail here
    logger.setLevel(logging.DEBUG)

    folders = all_folders(args.root_dir[0], single_level=True)
    for movie_dir in folders:
        cmd_out = ScanDvd(movie_dir)
        dvd = ParseHBOutput(cmd_out)
        pprint(dvd)
Пример #2
0
    def ProcessFolder(self, folder):
        """
        Process the given folder for DVD content.
        If the folder does not contain DVD content, recurse into subfolders.
        """
        folder = os.path.abspath(folder)
        logger.info("Searching folder: %s", folder)
        if os.path.exists(os.path.join(folder, "VIDEO_TS")) or os.path.exists(os.path.join(folder, "VIDEO_TS.IFO")):
            # Process this folder
            basename = os.path.basename(folder)
            match = re.search("(.+?)_?[sS](\d+)_?[dD](\d+)", basename)
            if match:
                series = match.group(1)
                series = series.replace("_", " ")
                series = series.strip()
                season = int(match.group(2))
                disc = int(match.group(3))
                logger.info('series = "%s", season = %d, disc = %d', series, season, disc)

                if (
                    self.previous_season
                    and season != self.previous_season
                    or self.previous_series
                    and series != self.previous_series
                ):
                    # Restart the episode numbering
                    self.eps_start_num = 1
                    self.extras_start_num = 1

                raw = ScanDvd(folder)
                self.curr_dvd = ParseHBOutput(raw)
                self.curr_dvd.folder = folder
                self.curr_dvd.series = series
                self.curr_dvd.season = season

                if self.remove_dup_titles:
                    self.RemoveDuplicateTitles()
                self.RemoveShortTitles()
                if self.remove_virtual_titles:
                    self.RemoveVirtualTitles()

                # Report summary of durations kept/rejected
                active_durations = [x.duration for x in self.curr_dvd.titles if x.enabled]
                active_duration_total = sum(active_durations)
                inactive_durations = [x.duration for x in self.curr_dvd.titles if not x.enabled]
                inactive_duration_total = sum(inactive_durations)
                logger.info(
                    "*** %d active titles with total playtime of %s " "(%d inactive titles with playtime of %s) ***",
                    len(active_durations),
                    GetInHMS(active_duration_total),
                    len(inactive_durations),
                    GetInHMS(inactive_duration_total),
                )

                self.FindEpisodesAndExtras()
                self.EnableAudioAndSubtitleTracks()
                self.dvds.append(self.curr_dvd)
                logger.debug(pformat(self.curr_dvd))

                self.previous_season = season
                self.previous_series = series

            else:
                raise DvdNameError("Unable to parse folder name '{}'".format(folder))
        else:
            for sub_folder in sorted(all_folders(folder, single_level=True)):
                self.ProcessFolder(sub_folder)