コード例 #1
0
ファイル: anidb.py プロジェクト: djt5019/episode_renamer
def _parse_local(title):
    """
    Try to find the anime ID (aid) in the dump file provided by AniDB
    """
    if not utils.file_exists_in_resources('animetitles.dat'):
        logging.warning("AniDB database file not found, unable to poll AniDB at this time")
        logging.warning("Try using the --update-db option to download an copy of it")
        return -1

    logging.info("Searching the AniDB database file")

    title = title.lower()

    regex = re.compile(r'(?P<aid>\d+)\|(?P<type>\d)\|(?P<lang>.+)\|(?P<title>.*)')

    sequence = difflib.SequenceMatcher(lambda x: x in punct, title.lower())

    guesses = []

    with utils.open_file_in_resources('animetitles.dat') as f:
        for line in f:
            res = regex.search(line)

            if not res:
                continue

            original_title = utils.encode(res.group('title').lower())
            clean_title = utils.prepare_title(utils.encode(res.group('title'))).lower()

            if utils.prepare_title(title) in (original_title, clean_title):
                return int(res.group('aid'))

            sequence.set_seq2(clean_title.lower())
            ratio = sequence.quick_ratio()

            if ratio > .80:
                d = dict(ratio=ratio, aid=res.group('aid'), title=original_title)
                guesses.append(d)

    if guesses:
        logging.info("{} possibilities".format(len(guesses)))
        guesses = sorted(guesses, key=lambda x: x['ratio'])
        aid = guesses[0]['aid']
        name = guesses[0]['title']
        logging.error("Closest show to '{}' on AniDB is '{}'' with id {}".format(title, name, aid))

        for guess in guesses[1:]:
            logging.info("Similar show {} [{}] also found".format(guess['title'], guess['aid']))

    return -1
コード例 #2
0
ファイル: episode.py プロジェクト: Nooby/episode_renamer
 def show_title(self, val):
     """
     Sets the shows title to the value passed as well as prepares it for use
     """
     logging.debug("Setting show title to: {}".format(val))
     self.title = utils.encode(val.capitalize())
     self.proper_title = utils.prepare_title(val)
コード例 #3
0
def poll(title):
    cleanTitle = utils.prepare_title(title)
    episodes = []
    url = "http://www.epguides.com/{0}".format(cleanTitle)
    fd = utils.get_url_descriptor(url)

    if fd is None:
        return utils.show_not_found

    count = 1
    for line in fd.iter_lines():
        info = epguides_regex.match(utils.encode(line))

        if info is not None:
            name = info.group('name')
            episode = info.group('episode')
            season = int(info.group('season'))
            name = re.sub('<.*?>', '', name).strip()

            if '[Trailer]' in name:
                name = name.replace('[Trailer]', '')

            if name == "TBA":
                continue

            episodes.append(
                Episode(title=name, number=episode, season=season,
                        count=count))
            count += 1

    return episodes
コード例 #4
0
ファイル: episode.py プロジェクト: djt5019/episode_renamer
 def show_title(self, val):
     """
     Sets the shows title to the value passed as well as prepares it for use
     """
     logging.debug("Setting show title to: {}".format(val))
     self.title = utils.encode(val.capitalize())
     self.proper_title = utils.prepare_title(val)
コード例 #5
0
ファイル: epguides.py プロジェクト: djt5019/episode_renamer
def poll(title):
    cleanTitle = utils.prepare_title(title)
    episodes = []
    url = "http://www.epguides.com/{0}".format(cleanTitle)
    fd = utils.get_url_descriptor(url)

    if fd is None:
        return utils.show_not_found

    count = 1
    for line in fd.iter_lines():
        info = epguides_regex.match(utils.encode(line))

        if info is not None:
            name = info.group('name')
            episode = info.group('episode')
            season = int(info.group('season'))
            name = re.sub('<.*?>', '', name).strip()

            if '[Trailer]' in name:
                name = name.replace('[Trailer]', '')

            if name == "TBA":
                continue

            episodes.append(Episode(title=name, number=episode, season=season, count=count))
            count += 1

    return episodes
コード例 #6
0
 def setShow(self, showTitle):
     """Sets a new show to search for, the old show will be removed """
     if showTitle:
         self.show = Show(showTitle)
         self.show.proper_title = utils.prepare_title(showTitle.lower())
         self.show.title = showTitle
     else:
         raise ValueError("Empty show title passed to set show")
コード例 #7
0
ファイル: show_finder.py プロジェクト: Nooby/episode_renamer
 def setShow(self, showTitle):
     """Sets a new show to search for, the old show will be removed """
     if showTitle:
         self.show = Show(showTitle)
         self.show.proper_title = utils.prepare_title(showTitle.lower())
         self.show.title = showTitle
     else:
         raise ValueError("Empty show title passed to set show")
コード例 #8
0
ファイル: episode.py プロジェクト: Nooby/episode_renamer
    def __init__(self, seriesTitle, episodes=None):
        self.title = utils.encode(string.capwords(seriesTitle))
        self.proper_title = utils.prepare_title(seriesTitle.lower())
        self.episodes = []
        self.specials = []
        self._episodes_by_season = defaultdict(list)
        self.formatter = None

        if episodes:
            self.add_episodes(episodes)
コード例 #9
0
ファイル: episode.py プロジェクト: djt5019/episode_renamer
    def __init__(self, seriesTitle, episodes=None):
        self.title = utils.encode(string.capwords(seriesTitle))
        self.proper_title = utils.prepare_title(seriesTitle.lower())
        self.episodes = []
        self.specials = []
        self._episodes_by_season = defaultdict(list)
        self.formatter = None

        if episodes:
            self.add_episodes(episodes)
コード例 #10
0
ファイル: test_utils.py プロジェクト: Nooby/episode_renamer
def test_prepare_title():
    assert_equal(utils.prepare_title(None), "")
    assert_equal(utils.prepare_title("Hawaii Five-O"), "HawaiiFiveO")
    assert_equal(utils.prepare_title("Breaking Bad"), "BreakingBad")
    assert_equal(utils.prepare_title("The Office!@#$%^&*()>_"), "Office")
    assert_equal(utils.prepare_title("The Big 10"), "Bigten")
    assert_equal(utils.prepare_title("The !!! 352"), "three_hundred_fifty_two")
コード例 #11
0
def test_prepare_title():
    assert_equal(utils.prepare_title(None), "")
    assert_equal(utils.prepare_title("Hawaii Five-O"), "HawaiiFiveO")
    assert_equal(utils.prepare_title("Breaking Bad"), "BreakingBad")
    assert_equal(utils.prepare_title("The Office!@#$%^&*()>_"), "Office")
    assert_equal(utils.prepare_title("The Big 10"), "Bigten")
    assert_equal(utils.prepare_title("The !!! 352"), "three_hundred_fifty_two")