Example #1
0
def detect_music(path, types=None):
    count = len(types)
    if count > 100:
        return Classification.none(path)

    music_types = [t for t in types if 'audio' in t]
    score = int(round(float(len(music_types)) * 10 / count))

    mtype = None
    if any(['flac' in t for t in music_types]):
        mtype = MEDIA_TYPES.lossless_music
    else:
        mtype = MEDIA_TYPES.music

    if mtype:
        return Classification(path, mtype, score, name=os.path.basename(path))

    return Classification.none(path)
Example #2
0
def detect_movie(path):
    score = 0

    f = os.path.basename(path)

    if SEASON_NAME_REGEX.search(f):
        return Classification.none(path)

    hd_match = HD_YEAR_RES_REGEX.search(f)
    title_match = TITLE_AND_YEAR_REGEX.search(f)

    if hd_match:
        resolution = hd_match.group(3)
        parts = re.split('[ -._]', hd_match.group(1))
        title = ' '.join(filter(None, parts))
        year = hd_match.group(2)
        score = 8

    elif title_match:
        parts = re.split('[-_. ]', title_match.group(1))
        title = ' '.join(filter(None, parts))
        year = title_match.group(2)
        score = 6
    else:
        return Classification.none(path)

    logger.debug(title)
    logger.debug(year)

    rv = omdb.api(title=title, year=year)
    if rv:
        logger.debug('Response: %s' % rv.get("Response"))
        logger.debug('Type: %s' % rv.get("Type"))
        if rv.get("Response") == "True" and rv.get("Type") == "movie":
            return Classification(path, MEDIA_TYPES.movie, score, name=title)

    return Classification.none(path)
Example #3
0
    def classify_by_nfo(self, path):

        if os.path.isdir(path):
            nfos = find_nfos(path)
            ids = [extract_imdb_id(nfo) for nfo in nfos]
            omdb_responses = filter(None, [self.omdb.api(imdb=i) for i in ids])
            omdb_types = map(operator.itemgetter('Type'), omdb_responses)

            if 'movie' in omdb_types:
                return Classification(path, MEDIA_TYPES.movie, 10)

            elif set(['episode', 'series']).intersection(omdb_types):
                return Classification(path, MEDIA_TYPES.tv, 10)

        return Classification.none(path)
Example #4
0
def detect_tv(path):
    f = os.path.basename(path)

    match = SEASON_NAME_REGEX.search(f)
    if match:
        return Classification(path, MEDIA_TYPES.tv, 6, name=match.group(1))

    match = WHOLE_SEASON_REGEX.search(f)
    if match:
        return Classification(path, MEDIA_TYPES.tv, 4, name=match.group(1))

    match = NIGHTLY_REGEX.search(f)
    if match:
        return Classification(path, MEDIA_TYPES.tv, 4, name=match.group(1))

    return Classification.none(path)
Example #5
0
    def classify(self, path):
        types = self.get_types(path)
        logger.debug('%s: found types: %s' % (path, types))

        classifications = [
            self.classify_by_nfo(path),
            Classification.none(path),
        ]

        if any(['video' in t for t in types]):
            classifications.extend([
                detect_tv(path),
                detect_movie(path),
            ])

        if any(['audio' in t for t in types]):
            classifications.extend([
                detect_music(path, types),
            ])

        return max(classifications)