Пример #1
0
def test_add_remove_eps():
    cache = Cache(":memory:")
    cache.recreate_cache()

    eps, spc = make_series()

    Settings['db_update'] = 7

    cache.add_show("test show", eps, spc)

    eps = cache.get_episodes("test show")

    spc = filter(lambda x: x.is_special, eps)
    eps = filter(lambda x: not x.is_special, eps)

    for count, e in enumerate(eps):
        name = "Episode {}".format(count)  # single ascii letter name

        assert e.title == name
        assert e.number == count
        assert e.season == 1

    for count, s in enumerate(spc):
        s_name = "Special {}".format(count)
        assert s.title == s_name
        assert s.number == count

    cache.remove_show(1)
    cache.close()
Пример #2
0
def test_add_remove_eps():
    cache = Cache(":memory:")
    cache.recreate_cache()

    eps, spc = make_series()

    Settings["db_update"] = 7

    cache.add_show("test show", eps, spc)

    eps = cache.get_episodes("test show")

    spc = filter(lambda x: x.is_special, eps)
    eps = filter(lambda x: not x.is_special, eps)

    for count, e in enumerate(eps):
        name = "Episode {}".format(count)  # single ascii letter name

        assert e.title == name
        assert e.number == count
        assert e.season == 1

    for count, s in enumerate(spc):
        s_name = "Special {}".format(count)
        assert s.title == s_name
        assert s.number == count

    cache.remove_show(1)
    cache.close()
Пример #3
0
def test_bad_add_show_eps():
    cache = Cache(":memory:")
    cache.recreate_cache()

    eps, spc = make_series()

    assert_raises(ValueError, cache.add_show, showTitle="", episodes=eps)
    assert_raises(ValueError, cache.add_show, showTitle=None, episodes=None)
    assert_raises(ValueError, cache.add_show, showTitle="Show", episodes=None)
    assert_raises(ValueError,
                  cache.add_show,
                  showTitle="Show",
                  episodes="Title")
    assert_raises(ValueError, cache.add_show, showTitle="Title", episodes=[])
    assert_raises(ValueError, cache.add_show, showTitle="Title", episodes={})
    assert_raises(ValueError,
                  cache.add_show,
                  showTitle="test",
                  episodes=(1, 3))

    ## Specials
    assert_raises(ValueError, cache.add_show, showTitle=None, specials=None)
    assert_raises(ValueError, cache.add_show, showTitle="Show", specials=None)
    assert_raises(ValueError,
                  cache.add_show,
                  showTitle="Show",
                  specials="Title")
    assert_raises(ValueError, cache.add_show, showTitle="Title", specials=[])
    assert_raises(ValueError,
                  cache.add_show,
                  showTitle="Title",
                  specials={'title': 't'})
    assert_raises(ValueError, cache.add_show, showTitle="test", specials=[])

    cache.close()
Пример #4
0
def test_update_old_entry():
    cache = Cache(":memory:")
    cache.recreate_cache()

    eps, spc = make_series()

    cache.add_show("test show", eps, spc)

    eps = cache.get_episodes("test show", -1)

    cache.close()
Пример #5
0
def test_update_old_entry():
    cache = Cache(":memory:")
    cache.recreate_cache()

    eps, spc = make_series()

    cache.add_show("test show", eps, spc)

    eps = cache.get_episodes("test show", -1)

    cache.close()
Пример #6
0
def test_bad_add_show_eps():
    cache = Cache(":memory:")
    cache.recreate_cache()

    eps, spc = make_series()

    assert_raises(ValueError, cache.add_show, showTitle="", episodes=eps)
    assert_raises(ValueError, cache.add_show, showTitle=None, episodes=None)
    assert_raises(ValueError, cache.add_show, showTitle="Show", episodes=None)
    assert_raises(ValueError, cache.add_show, showTitle="Show", episodes="Title")
    assert_raises(ValueError, cache.add_show, showTitle="Title", episodes=[])
    assert_raises(ValueError, cache.add_show, showTitle="Title", episodes={})
    assert_raises(ValueError, cache.add_show, showTitle="test", episodes=(1, 3))

    ## Specials
    assert_raises(ValueError, cache.add_show, showTitle=None, specials=None)
    assert_raises(ValueError, cache.add_show, showTitle="Show", specials=None)
    assert_raises(ValueError, cache.add_show, showTitle="Show", specials="Title")
    assert_raises(ValueError, cache.add_show, showTitle="Title", specials=[])
    assert_raises(ValueError, cache.add_show, showTitle="Title", specials={"title": "t"})
    assert_raises(ValueError, cache.add_show, showTitle="test", specials=[])

    cache.close()
Пример #7
0
def main():
    cmd = argparse.ArgumentParser(description="Renames your TV shows",
                                  prog='eplist',
                                  usage='%(prog)s --help [options] title')

    cmd.add_argument('title',
                     default="",
                     nargs='?',
                     help="The title of the show")

    cmd.add_argument('-d',
                     '--display-header',
                     action="store_true",
                     help="Display the header at the top of the output")

    cmd.add_argument('-v',
                     '--verbose',
                     action="store_true",
                     help="Be verbose, enable additional output")

    cmd.add_argument('-s',
                     '--season',
                     default="",
                     type=str,
                     metavar='N',
                     help="The specific season range to search for. Ex: 1-3")

    cmd.add_argument('-e',
                     '--episode',
                     default="",
                     type=str,
                     metavar='N',
                     help="The specific episode range to search for Ex: 15-30")

    cmd.add_argument(
        '-f',
        '--format',
        dest="format",
        metavar='F',
        help="Rename the files in a directory with a custom format")

    cmd.add_argument('-g',
                     '--gui-enabled',
                     action="store_true",
                     help="Use the gui rather than the command line")

    group = cmd.add_mutually_exclusive_group()

    group.add_argument('-r',
                       '--rename',
                       dest='pathname',
                       metavar="PATH",
                       help="Rename the files in the path provided")

    group.add_argument('-u',
                       '--undo-rename',
                       action='store_true',
                       help="Undo the last rename operation")

    cmd.add_argument('--delete-cache',
                     action="store_true",
                     help="Delete the cache file and create a new one")

    cmd.add_argument(
        '--update-db',
        action="store_true",
        help="Update the AniDB titles file, limit to once a day due to size")

    cmd.add_argument(
        '--verify',
        action="store_true",
        help="Verify the checksums in the filename if they are present")

    cmd.add_argument('--filter',
                     choices=['episodes', 'specials', 'both'],
                     help="Filters episodes based on type (default=both)")

    args = cmd.parse_args()

    if 'title' in args:
        Settings.title = args.title
    else:
        Settings.title = ""

    # Set the correct working path
    if args.pathname:
        Settings.path = os.path.realpath(args.pathname)
    else:
        Settings.path = os.path.realpath(os.getcwd())

    # If we are acting on files then load the old names into memory
    if args.pathname or args.undo_rename:
        utils.load_renamed_file()

    if args.filter:
        Settings.filter = args.filter

    cache = Cache(Settings.db_name)
    atexit.register(cache.close)

    if args.delete_cache:
        cache.recreate_cache()

    if Settings.title in ('-', '.', 'pwd'):
        # If a dash is entered use the current basename of the path
        Settings.title = os.path.split(os.getcwd())[1]
        print("Searching for {}".format(Settings.title))

    if args.verbose:
        Settings.verbose = True
        l = logging.getLogger()
        for handle in l.handlers:
            handle.setLevel(logging.NOTSET)
        l.setLevel(logging.NOTSET)

    if args.gui_enabled:
        from .gui.gui import main
        exit(main())

    if args.update_db:
        utils.update_db()

    if args.undo_rename:
        do_rename(utils.find_old_filenames(Settings.path, Settings.title))
        sys.exit(0)

    rename = args.pathname is not None

    if rename and not os.path.exists(args.pathname):
        sys.exit("ERROR - Path provided does not exist")

    if not Settings.title:
        cmd.print_usage()
        sys.exit(1)

    episodeParser = ShowFinder(Settings.title, cache)

    show = episodeParser.getShow()
    formatter = episode.EpisodeFormatter(show, args.format)
    show.formatter = formatter

    if not show.episodes:
        sys.exit(1)

    # If the user specified a specific season we will filter our results
    # this also checks to make sure its a reasonable season number
    eps = filter_episodes(show, args.season, args.episode)

    show.add_episodes(eps)

    ## Renaming functionality
    if rename:
        do_rename(utils.prepare_filenames(Settings.path, show))
        sys.exit(0)

    if args.verify:
        files = utils.clean_filenames(Settings.path)

        verify_files(files)
        sys.exit(1)

    if Settings.filter in ('both', 'episodes'):
        display_episodes(show, show.episodes, args.display_header)

    if Settings.filter in ('specials', 'both'):
        display_specials(show, args.display_header)
Пример #8
0
def main():
    cmd = argparse.ArgumentParser(description="Renames your TV shows",
                        prog='eplist', usage='%(prog)s --help [options] title')

    cmd.add_argument('title', default="", nargs='?',
        help="The title of the show")

    cmd.add_argument('-d', '--display-header', action="store_true",
        help="Display the header at the top of the output")

    cmd.add_argument('-v', '--verbose', action="store_true",
        help="Be verbose, enable additional output")

    cmd.add_argument('-s', '--season', default="", type=str, metavar='N',
        help="The specific season range to search for. Ex: 1-3")

    cmd.add_argument('-e', '--episode', default="", type=str, metavar='N',
        help="The specific episode range to search for Ex: 15-30")

    cmd.add_argument('-f', '--format', dest="format", metavar='F',
        help="Rename the files in a directory with a custom format")

    cmd.add_argument('-g', '--gui-enabled', action="store_true",
        help="Use the gui rather than the command line")

    group = cmd.add_mutually_exclusive_group()

    group.add_argument('-r', '--rename', dest='pathname', metavar="PATH",
        help="Rename the files in the path provided")

    group.add_argument('-u', '--undo-rename', action='store_true',
        help="Undo the last rename operation")

    cmd.add_argument('--delete-cache', action="store_true",
        help="Delete the cache file and create a new one")

    cmd.add_argument('--update-db', action="store_true",
        help="Update the AniDB titles file, limit to once a day due to size")

    cmd.add_argument('--verify', action="store_true",
        help="Verify the checksums in the filename if they are present")

    cmd.add_argument('--filter', choices=['episodes', 'specials', 'both'],
        help="Filters episodes based on type (default=both)")

    args = cmd.parse_args()

    if not os.path.exists(constants.resource_path):
        utils.init_resource_folder()

    logger.init_logging()

    atexit.register(utils.save_last_access_times)
    atexit.register(logger.shutdown_logging)

    if 'title' in args:
        Settings.title = args.title
    else:
        Settings.title = ""

    # Set the correct working path
    if args.pathname:
        Settings.path = os.path.realpath(args.pathname)
    else:
        Settings.path = os.path.realpath(os.getcwd())

    # If we are acting on files then load the old names into memory
    if args.pathname or args.undo_rename:
        utils.load_renamed_file()

    if args.filter:
        Settings.filter = args.filter

    cache = Cache(Settings.db_name)
    atexit.register(cache.close)

    if args.delete_cache:
        cache.recreate_cache()

    if Settings.title in ('-', '.', 'pwd'):
        # If a dash is entered use the current basename of the path
        Settings.title = os.path.split(os.getcwd())[1]
        print("Searching for {}".format(Settings.title))

    if args.verbose:
        Settings.verbose = True
        l = logging.getLogger()
        for handle in l.handlers:
            handle.setLevel(logging.NOTSET)
        l.setLevel(logging.NOTSET)

    if args.gui_enabled:
        from .gui.gui import main
        exit(main())

    if args.update_db:
        utils.update_db()

    if args.undo_rename:
        do_rename(utils.find_old_filenames(Settings.path, Settings.title))
        sys.exit(0)

    rename = args.pathname is not None

    if rename and not os.path.exists(args.pathname):
        sys.exit("ERROR - Path provided does not exist")

    if not Settings.title:
        cmd.print_usage()
        sys.exit(1)

    episodeParser = ShowFinder(Settings.title, cache)

    show = episodeParser.getShow()
    formatter = episode.EpisodeFormatter(show, args.format)
    show.formatter = formatter

    if not show.episodes:
        sys.exit(1)

    # If the user specified a specific season we will filter our results
    # this also checks to make sure its a reasonable season number
    eps = filter_episodes(show, args.season, args.episode)

    show.add_episodes(eps)

    ## Renaming functionality
    if rename:
        do_rename(utils.prepare_filenames(Settings.path, show))
        sys.exit(0)

    if args.verify:
        files = utils.clean_filenames(Settings.path)

        verify_files(files)
        sys.exit(1)

    if Settings.filter in ('both', 'episodes'):
        display_episodes(show, show.episodes, args.display_header)

    if Settings.filter in ('specials', 'both'):
        display_specials(show, args.display_header)