Exemplo n.º 1
0
def add_mal_entry(list_item, on_mal_list):
    if on_mal_list == 'not_on_mal_list':
        logger.warning(
            '[PLEX -> MAL] No MAL entry found for matching season of {}, adding to MAL with status Watching ]'
            .format(list_item.title))

        anime_new = spice.get_blank(spice.get_medium('anime'))
        anime_new.episodes = 0
        spice.add(anime_new, int(list_item.id), spice.get_medium('anime'),
                  mal_credentials)
Exemplo n.º 2
0
def send_watched_to_mal(mal_list, plex_title, plex_watched_episode_count):
    show_in_mal_list = False
    mal_watched_episode_count = 0
    mal_show_id = 0

    # check if show is already on MAL list
    for list_item in mal_list:
        #logger.debug('Comparing %s with %s' % (list_item.title, plex_title))
        mal_id = int(list_item.id)
        mal_title = list_item.title
        mal_title_english = ""

        if (list_item.english is not None):
            mal_title_english = list_item.english
            #logger.debug('Comparing original: %s | english: %s with %s' % (mal_title, mal_title_english, plex_title))
        else:
            #logger.debug('Comparing original: %s with %s' % (mal_title, plex_title))
            pass

        if (mal_title.lower() == plex_title.lower()
                or mal_title_english.lower() == plex_title.lower()):
            #logger.debug('%s [%s] was already in list => status = %s | watch count = %s' % (plex_title, list_item.id, spice.get_status(list_item.status), list_item.episodes))
            mal_watched_episode_count = int(list_item.episodes)
            mal_show_id = int(list_item.id)
            show_in_mal_list = True

            if (mal_watched_episode_count > 0 and mal_show_id > 0):
                if (mal_watched_episode_count < plex_watched_episode_count):
                    anime_new = spice.get_blank(spice.get_medium('anime'))
                    anime_new.episodes = plex_watched_episode_count
                    new_status = 'watching'

                    # if full watched set status to completed, needs additional
                    # lookup as total episodes are not exposed in list (mal or
                    # spice limitation)
                    lookup_show = spice.search_id(mal_id,
                                                  spice.get_medium('anime'),
                                                  mal_credentials)
                    if (lookup_show):
                        if (lookup_show.episodes is not None):
                            mal_total_episodes = int(lookup_show.episodes)

                            if (plex_watched_episode_count >=
                                    mal_total_episodes):
                                new_status = 'completed'

                    anime_new.status = spice.get_status(new_status)

                    logger.warn(
                        '[PLEX -> MAL] Watch count for %s on Plex is %s and MAL is %s, updating MAL watch count to %s and status to %s ]'
                        % (plex_title, plex_watched_episode_count,
                           mal_watched_episode_count,
                           plex_watched_episode_count, new_status))
                    spice.update(anime_new, mal_show_id,
                                 spice.get_medium('anime'), mal_credentials)
                else:
                    logger.warning(
                        '[PLEX -> MAL] Watch count for %s on Plex was equal or higher on MAL so skipping update'
                        % (plex_title))
                    pass

    # if not listed in list lookup on MAL
    if (not show_in_mal_list):
        found_result = False
        update_list = True
        on_mal_list = False
        logger.info(
            '[PLEX -> MAL] %s not in MAL list, searching for show on MAL' %
            (plex_title))

        mal_shows = spice.search(plex_title, spice.get_medium('anime'),
                                 mal_credentials)
        for mal_show in mal_shows:
            mal_title = mal_show.title.lower()
            mal_title_english = ''
            mal_show_id = int(mal_show.id)
            mal_total_episodes = int(mal_show.episodes)

            if (mal_show.english is not None):
                mal_title_english = mal_show.english.lower()
                #logger.debug('Comparing original: %s | english: %s with %s' % (mal_title, mal_title_english, plex_title.lower()))
            else:
                #logger.debug('Comparing original: %s with %s' % (mal_title, plex_title.lower()))
                pass

            if (mal_title == plex_title.lower()
                    or mal_title_english == plex_title.lower()):
                found_result = True

                # double check against MAL list using id to see if matches and
                # update is required
                for list_item in mal_list:
                    mal_list_id = int(list_item.id)
                    mal_list_watched_episode_count = int(list_item.episodes)

                    if (mal_list_id == mal_show_id):
                        on_mal_list = True
                        if (plex_watched_episode_count ==
                                mal_list_watched_episode_count):
                            logger.warning(
                                '[PLEX -> MAL] show was found in current MAL list using id lookup however watch count was identical so skipping update'
                            )
                            update_list = False
                        break

                if (update_list):
                    anime_new = spice.get_blank(spice.get_medium('anime'))
                    anime_new.episodes = plex_watched_episode_count

                    if (plex_watched_episode_count >= mal_total_episodes):
                        logger.warn(
                            '[PLEX -> MAL] Found match on MAL and setting state to completed as watch count equal or higher than total episodes'
                        )
                        anime_new.status = spice.get_status('completed')
                        if (on_mal_list):
                            spice.update(anime_new, mal_show.id,
                                         spice.get_medium('anime'),
                                         mal_credentials)
                        else:
                            spice.add(anime_new, mal_show.id,
                                      spice.get_medium('anime'),
                                      mal_credentials)
                    else:
                        logger.warn(
                            '[PLEX -> MAL] Found match on MAL and setting state to watching with watch count: %s'
                            % (plex_watched_episode_count))
                        anime_new.status = spice.get_status('watching')
                        if (on_mal_list):
                            spice.update(anime_new, mal_show.id,
                                         spice.get_medium('anime'),
                                         mal_credentials)
                        else:
                            spice.add(anime_new, mal_show.id,
                                      spice.get_medium('anime'),
                                      mal_credentials)
                break

        if (not found_result):
            logger.error('[PLEX -> MAL] Failed to find %s on MAL' %
                         (plex_title))
Exemplo n.º 3
0
def send_watched_to_mal(plex_watched_shows, mal_list, mal_list_seasoned):
    for show, value in plex_watched_shows.items():
        plex_title = show.title
        plex_watched_episode_count, plex_watched_episode_season = value
        show_in_mal_list = False
        force_update = False
        #logger.debug('%s => watch count = %s' % (plex_title, watched_episode_count))

        if plex_watched_episode_count <= 0:
            continue

        # All shows with season > 1 were previously searched and are part of
        # the mal_list_seasoned object
        if plex_watched_episode_season > 1:
            force_update = True
            for anime, season, original_name, on_mal_list in mal_list_seasoned:
                if original_name.lower() == plex_title.lower():
                    try:
                        correct_item = [
                            value[0]
                            for index, value in enumerate(mal_list_seasoned)
                            if value[1] == plex_watched_episode_season
                            and value[2] == original_name
                        ][0]
                    except BaseException:
                        # Search failed to properly match seasons, e.g. Card Captor Sakura Clear Card is s4 on TVDB and s2 here
                        # assume most recent available season
                        # TODO: search by ID of the correct season
                        if force_update:
                            correct_item = spice.search_id(
                                int(mal_list_seasoned[-1][0].id),
                                spice.get_medium('anime'), mal_credentials)
                            on_mal_list = 'not_on_mal_list'
                        else:
                            break
                    # Trying to add before doens't really break anything and
                    # works for new series, since mal_list_seasoned includes
                    # things you haven't watched yet
                    add_mal_entry(correct_item, on_mal_list)
                    update_mal_entry(correct_item, plex_title,
                                     plex_watched_episode_count, force_update)
                    break
            continue

        # check if show is already on MAL list
        for list_item in mal_list:
            #logger.debug('Comparing %s with %s' % (list_item.title, plex_title))
            mal_title = list_item.title
            mal_title_english = ""
            if list_item.english is not None:
                mal_title_english = list_item.english
                #logger.debug('Comparing original: %s | english: %s with %s' % (mal_title, mal_title_english, plex_title))
            else:
                #logger.debug('Comparing original: %s with %s' % (mal_title, plex_title))
                pass

            if mal_title.lower() == plex_title.lower(
            ) or mal_title_english.lower() == plex_title.lower():
                show_status = spice.get_status(list_item.status)
                logger.debug(
                    '{} [{}] was already in list => status = {} | watch count = {}'
                    .format(plex_title, list_item.id, show_status,
                            list_item.episodes))
                show_in_mal_list = True
                update_mal_entry(list_item, plex_title,
                                 plex_watched_episode_count, force_update)

        # If not listed in list lookup on MAL
        if not show_in_mal_list:
            found_result = False
            update_list = True
            on_mal_list = False
            logger.info(
                '[PLEX -> MAL] {} not in MAL list, searching for show on MAL'.
                format(plex_title))

            potential_titles = [
                plex_title.lower(),
                guessit(plex_title)['title'].lower()
            ]
            for title in potential_titles:
                mal_shows = spice.search(title, spice.get_medium('anime'),
                                         mal_credentials)
                if len(mal_shows) >= 1:
                    break

            for mal_show in mal_shows:
                mal_title = mal_show.title.lower()
                mal_title_english = ''
                mal_show_id = int(mal_show.id)
                mal_total_episodes = int(mal_show.episodes)

                if mal_show.english:
                    mal_title_english = mal_show.english.lower()
                    #logger.debug('Comparing original: %s | english: %s with %s' % (mal_title, mal_title_english, plex_title.lower()))
                else:
                    #logger.debug('Comparing original: %s with %s' % (mal_title, plex_title.lower()))
                    pass

                if mal_title in potential_titles or mal_title_english in potential_titles:
                    found_result = True

                    # double check against MAL list using id to see if matches
                    # and update is required
                    for list_item in mal_list:
                        mal_list_id = int(list_item.id)
                        mal_list_watched_episode_count = int(
                            list_item.episodes)

                        if mal_list_id == mal_show_id:
                            on_mal_list = True
                            if plex_watched_episode_count == mal_list_watched_episode_count:
                                logger.warning(
                                    '[PLEX -> MAL] show was found in current MAL list using id lookup however watch count was identical so skipping update'
                                )
                                update_list = False
                            break

                    if update_list:
                        logger.warning(
                            '[PLEX -> MAL] Found match on MAL and setting state to watching with watch count: {}'
                            .format(plex_watched_episode_count))
                        anime_new = spice.get_blank(spice.get_medium('anime'))
                        anime_new.episodes = plex_watched_episode_count

                        if plex_watched_episode_count >= mal_total_episodes:
                            anime_new.status = spice.get_status('completed')
                            if on_mal_list:
                                spice.update(anime_new, mal_show.id,
                                             spice.get_medium('anime'),
                                             mal_credentials)
                            else:
                                spice.add(anime_new, mal_show.id,
                                          spice.get_medium('anime'),
                                          mal_credentials)
                        else:
                            anime_new.status = spice.get_status('watching')
                            if on_mal_list:
                                spice.update(anime_new, mal_show.id,
                                             spice.get_medium('anime'),
                                             mal_credentials)
                            else:
                                spice.add(anime_new, mal_show.id,
                                          spice.get_medium('anime'),
                                          mal_credentials)
                    break

            if not found_result:
                logger.error('[PLEX -> MAL] Failed to find {} on MAL'.format(
                    plex_title))
Exemplo n.º 4
0
                                update_list = False
                            break

                    if(update_list):
                        print(
                            Back.MAGENTA + '[PLEX -> MAL] Found match on MAL and setting state to watching with watch count: %s' % (watched_episode_count))
                        anime_new = spice.get_blank(spice.get_medium('anime'))
                        anime_new.episodes = watched_episode_count

                        if(watched_episode_count >= mal_total_episodes):
                            anime_new.status = spice.get_status('completed')
                            if(on_mal_list):
                                spice.update(anime_new, mal_show.id, spice.get_medium(
                                    'anime'), mal_credentials)
                            else:
                                spice.add(anime_new, mal_show.id, spice.get_medium(
                                    'anime'), mal_credentials)
                        else:
                            anime_new.status = spice.get_status('watching')
                            if(on_mal_list):
                                spice.update(anime_new, mal_show.id, spice.get_medium(
                                    'anime'), mal_credentials)
                            else:
                                spice.add(anime_new, mal_show.id, spice.get_medium(
                                    'anime'), mal_credentials)
                    break

            if(not found_result):
                print(Back.LIGHTRED_EX +
                      '[PLEX -> MAL] Failed to find %s on MAL' % (plex_title))

<<<<<<< HEAD