示例#1
0
def push_movie(all_movies, collected, rated, video):
    pms_metadata = None

    if Prefs['sync_collection'] is True:
        pms_metadata = PMS.metadata(video.get('ratingKey'))
        collected.append(pms_metadata)

    if video.get('viewCount') > 0:
        Log.Debug('You have seen %s', video.get('title'))
        if video.get('type') == 'movie':
            if pms_metadata is None:
                pms_metadata = PMS.metadata(video.get('ratingKey'))

            movie_dict = pms_metadata
            #movie_dict['plays'] = int(video.get('viewCount'))
            #movie_dict.pop('duration')

            all_movies.append(movie_dict)
        else:
            Log.Info('Unknown item %s' % video.get('ratingKey'))

    if video.get('userRating') is not None:
        if pms_metadata is None:
            pms_metadata = PMS.metadata(video.get('ratingKey'))

        rating_movie = pms_metadata
        rating_movie['rating'] = int(video.get('userRating'))

        rated.append(rating_movie)
    def create_session(self, session_key, state):
        """
        :type session_key: str
        :type state: str

        :rtype: WatchSession or None
        """

        Log.Debug("Creating a WatchSession for the current media")

        video_section = PMS.get_video_session(session_key)
        if not video_section:
            return None

        player_section = video_section.findall("Player")
        if len(player_section):
            player_section = player_section[0]

        session = WatchSession.from_section(
            video_section,
            state,
            PMS.metadata(video_section.get("ratingKey")),
            PMS.client(player_section.get("machineIdentifier")),
        )
        session.save()

        return session
示例#3
0
def pull_movie(watched, rated, video):
    key = video.get('ratingKey')

    # Pull metadata
    metadata = PMS.metadata(key)

    if not metadata:
        Log.Warn('Invalid metadata with key %s, network error' % key)
        return

    if 'imdb_id' not in metadata and 'tmdb_id' not in metadata:
        Log.Warn('Invalid metadata with key %s, no IMDB or TMDB id available' % key)
        return

    # Sync watched
    if Prefs['sync_watched'] is True:
        for movie in finditems(metadata, watched, ['imdb_id', 'tmdb_id']):
            Log.Debug('Found %s with id %s' % (metadata['title'], key))

            if not PMS.scrobble(video):
                Log.Debug('The movie %s is already marked as seen in the library.' % metadata['title'])

    # Sync ratings
    if Prefs['sync_ratings'] is True:
        for movie in finditems(metadata, rated, ['imdb_id', 'tmdb_id']):
            Log.Debug('Found %s with id %s' % (metadata['title'], key))
            PMS.rate(video, movie['rating_advanced'])
示例#4
0
def CollectionSync(itemID, do):
    metadata = PMS.metadata(itemID)
    if not metadata:
        Log.Warn('Unable to fetch metadata for media with id %s' % itemID)
        return

    #cancel, if metadata is not there yet
    if not 'tvdb_id' in metadata and not 'imdb_id' in metadata and not 'tmdb_id' in metadata:
        return

    if do == 'add':
        do_action = 'library'
    elif do == 'delete':
        do_action = 'unlibrary'
    else:
        return

    action = None
    if metadata['type'] == 'episode':
        action = 'show/episode/%s' % do_action
    elif metadata['type'] == 'movie':
        action = 'movie/%s' % do_action

    # Setup Data to send to Trakt
    values = {}

    if metadata['type'] == 'episode':
        if not metadata.get('tvdb_id'):
            Log.Info('Added episode has no tvdb_id')
            return

        values['tvdb_id'] = metadata['tvdb_id']
        values['title'] = metadata['title']

        if 'year' in metadata:
            values['year'] = metadata['year']

        values['episodes'] = [{'season': metadata['season'], 'episode': metadata['episode']}]

    elif metadata['type'] == 'movie':
        if not metadata.get('imdb_id') and not metadata.get('tmdb_id'):
            Log.Info('Added movie has no imdb_id and no tmdb_id')
            return

        movie = {'title': metadata['title'], 'year': metadata['year']}

        if metadata['imdb_id']:
            movie['imdb_id'] = metadata['imdb_id']
        elif metadata['tmdb_id']:
            movie['tmdb_id'] = metadata['tmdb_id']

        values['movies'] = [movie]

    if action:
        Trakt.request(action, values)
    def create_session(self, info):
        client = None
        if info.get('machineIdentifier'):
            client = PMS.client(info['machineIdentifier'])
        else:
            Log.Info('No machineIdentifier available, client filtering not available')

        return WatchSession.from_info(
            info,
            PMS.metadata(info['ratingKey']),
            client
        )
示例#6
0
def pull_movie(watched, rated, video):
    # Pull metadata
    metadata = PMS.metadata(video.get('ratingKey'))
    if not metadata or 'imdb_id' not in metadata:
        Log.Warn('Invalid metadata for movie with key %s (network error or missing IMDB ID)' % video.get('ratingKey'))
        return

    # Sync watched
    if Prefs['sync_watched'] is True:
        for movie in finditems(metadata, watched, 'imdb_id'):
            Log.Debug('Found %s with id %s' % (metadata['title'], video.get('ratingKey')))

            if not PMS.scrobble(video):
                Log.Debug('The movie %s is already marked as seen in the library.' % metadata['title'])

    # Sync ratings
    if Prefs['sync_ratings'] is True:
        for movie in finditems(metadata, rated, 'imdb_id'):
            Log.Debug('Found %s with id %s' % (metadata['title'], video.get('ratingKey')))
            PMS.rate(video, movie['rating_advanced'])