def fast_sync(self, plugin):
        ''' Movie and userdata not provided by server yet.
        '''
        last_sync = settings('LastIncrementalSync')
        sync = get_sync()
        LOG.info("--[ retrieve changes ] %s", last_sync)

        for library in sync['Whitelist']:

            for data in server.get_items(
                    library.replace('Mixed:', ""),
                    "Series,Season,Episode,BoxSet,Movie,MusicVideo,MusicArtist,MusicAlbum,Audio",
                    False, {'MinDateLastSaved': last_sync}):

                for item in data['Items']:
                    if item['Type'] in self.updated_output:
                        self.updated_output[item['Type']].put(item)
                        self.total_updates += 1

            for data in server.get_items(
                    library.replace('Mixed:',
                                    ""), "Episode,Movie,MusicVideo,Audio",
                    False, {'MinDateLastSavedForUser': last_sync}):

                for item in data['Items']:
                    if item['Type'] in self.userdata_output:
                        self.userdata_output[item['Type']].put(item)
                        self.total_updates += 1
        """
        # temp fix for boxsets
        boxsets = {}
        with Database('emby') as embydb:
            boxsets = dict(emby_db.EmbyDatabase(embydb.cursor).get_items_by_media('set') or {})

        for items in server.get_items(None, "BoxSet"):

            start_index = items['RestorePoint']['params']['StartIndex']

            for index, boxset in enumerate(items['Items']):

                if not (boxset['Id'] in boxsets and boxset['Etag'] == boxsets[boxset['Id']]):
                    self.updated_output['BoxSet'].put(boxset)

                dialog.update(int(50 +
                                  (float(start_index + index) / float(items['TotalRecordCount'])) *
                                  50),
                              heading="%s: %s" % (_('addon_name'), boxset['Type']),
                              message=boxset['Name'])
        """

        if plugin:
            try:
                result = self.server['api'].get_sync_queue(last_sync)
                self.removed(result['ItemsRemoved'])

            except Exception as error:
                LOG.exception(error)

        return True
    def boxsets(self, library_id=None, dialog=None):
        ''' Process all boxsets.
        '''
        Movies = self.library.media['Movies']

        with self.library.database_lock:
            with Database() as videodb:
                with Database('emby') as embydb:
                    obj = Movies(self.server, embydb, videodb,
                                 self.direct_path)

                    for items in server.get_items(
                            library_id, "BoxSet", False,
                            self.sync['RestorePoint'].get('params')):

                        self._restore_point(items['RestorePoint'])
                        start_index = items['RestorePoint']['params'][
                            'StartIndex']

                        for index, boxset in enumerate(items['Items']):

                            dialog.update(int(
                                (float(start_index + index) /
                                 float(items['TotalRecordCount'])) * 100),
                                          heading="%s: %s" %
                                          (_('addon_name'), _('boxsets')),
                                          message=boxset['Name'])
                            obj.boxset(boxset)
    def musicvideos(self, library, dialog):
        ''' Process musicvideos from a single library.
        '''
        MusicVideos = self.library.media['MusicVideos']

        with self.library.database_lock:
            with Database() as videodb:
                with Database('emby') as embydb:
                    obj = MusicVideos(self.server, embydb, videodb,
                                      self.direct_path)

                    for items in server.get_items(
                            library['Id'], "MusicVideo", False,
                            self.sync['RestorePoint'].get('params')):

                        self._restore_point(items['RestorePoint'])
                        start_index = items['RestorePoint']['params'][
                            'StartIndex']

                        for index, mvideo in enumerate(items['Items']):

                            dialog.update(int(
                                (float(start_index + index) /
                                 float(items['TotalRecordCount'])) * 100),
                                          heading="%s: %s" %
                                          (_('addon_name'), library['Name']),
                                          message=mvideo['Name'])
                            obj.musicvideo(mvideo, library=library)

                    if self.update_library:
                        self.musicvideos_compare(library, obj, embydb)
Exemple #4
0
    def musicvideos(self, library, dialog):
        ''' Process musicvideos from a single library.
        '''
        processed_ids = []

        for items in server.get_items(library['Id'], "MusicVideo", False,
                                      self.sync['RestorePoint'].get('params')):

            with self.video_database_locks() as (videodb, jellyfindb):
                obj = MusicVideos(self.server, jellyfindb, videodb,
                                  self.direct_path)

                self.sync['RestorePoint'] = items['RestorePoint']
                start_index = items['RestorePoint']['params']['StartIndex']

                for index, mvideo in enumerate(items['Items']):

                    dialog.update(int(
                        (float(start_index + index) /
                         float(items['TotalRecordCount'])) * 100),
                                  heading="%s: %s" %
                                  (translate('addon_name'), library['Name']),
                                  message=mvideo['Name'])
                    obj.musicvideo(mvideo, library=library)
                    processed_ids.append(mvideo['Id'])

        with self.video_database_locks() as (videodb, jellyfindb):
            obj = MusicVideos(self.server, jellyfindb, videodb,
                              self.direct_path)
            obj.item_ids = processed_ids
            if self.update_library:
                self.musicvideos_compare(library, obj, jellyfindb)
Exemple #5
0
    def tvshows(self, library, dialog):

        ''' Process tvshows and episodes from a single library.
        '''
        processed_ids = []

        for items in server.get_items(library['Id'], "Series", False, self.sync['RestorePoint'].get('params')):

            with self.video_database_locks() as (videodb, jellyfindb):
                obj = TVShows(self.server, jellyfindb, videodb, self.direct_path, True)

                self.sync['RestorePoint'] = items['RestorePoint']
                start_index = items['RestorePoint']['params']['StartIndex']

                for index, show in enumerate(items['Items']):

                    percent = int((float(start_index + index) / float(items['TotalRecordCount'])) * 100)
                    message = show['Name']
                    dialog.update(percent, heading="%s: %s" % (translate('addon_name'), library['Name']), message=message)

                    if obj.tvshow(show, library=library) is not False:

                        for episodes in server.get_episode_by_show(show['Id']):
                            for episode in episodes['Items']:

                                dialog.update(percent, message="%s/%s" % (message, episode['Name'][:10]))
                                obj.episode(episode)
                    processed_ids.append(show['Id'])

        with self.video_database_locks() as (videodb, jellyfindb):
            obj = TVShows(self.server, jellyfindb, videodb, self.direct_path, True)
            obj.item_ids = processed_ids
            if self.update_library:
                self.tvshows_compare(library, obj, jellyfindb)
Exemple #6
0
    def movies(self, library, dialog):
        ''' Process movies from a single library.
        '''
        Movies = self.library.media['Movies']

        with self.library.database_lock:
            with Database() as videodb:
                with Database('jellyfin') as jellyfindb:

                    obj = Movies(self.server, jellyfindb, videodb,
                                 self.direct_path)

                    for items in server.get_items(
                            library['Id'], "Movie", False,
                            self.sync['RestorePoint'].get('params')):

                        self.sync['RestorePoint'] = items['RestorePoint']
                        start_index = items['RestorePoint']['params'][
                            'StartIndex']

                        for index, movie in enumerate(items['Items']):

                            dialog.update(int(
                                (float(start_index + index) /
                                 float(items['TotalRecordCount'])) * 100),
                                          heading="%s: %s" %
                                          (_('addon_name'), library['Name']),
                                          message=movie['Name'])
                            obj.movie(movie, library=library)

                    if self.update_library:
                        self.movies_compare(library, obj, jellyfindb)
    def music(self, library, dialog):

        ''' Process artists, album, songs from a single library.
        '''
        with self.library.music_database_lock:
            with Database('music') as musicdb:
                with Database('emby') as embydb:
                    obj = Music(self.server, embydb, musicdb, self.direct_path)

                    for items in server.get_artists(library['Id'], False, self.sync['RestorePoint'].get('params')):

                        self.sync['RestorePoint'] = items['RestorePoint']
                        start_index = items['RestorePoint']['params']['StartIndex']

                        for index, artist in enumerate(items['Items']):

                            percent = int((float(start_index + index) / float(items['TotalRecordCount']))*100)
                            message = artist['Name']
                            dialog.update(percent, heading="%s: %s" % (_('addon_name'), library['Name']), message=message)
                            obj.artist(artist, library=library)

                            for albums in server.get_albums_by_artist(artist['Id']):
                                
                                for album in albums['Items']:
                                    obj.album(album)

                                    for songs in server.get_items(album['Id'], "Audio"):
                                        for song in songs['Items']:

                                            dialog.update(percent,
                                                          message="%s/%s/%s" % (message, album['Name'][:7], song['Name'][:7]))
                                            obj.song(song)

                    if self.update_library:
                        self.music_compare(library, obj, embydb)
    def tvshows(self, library, dialog):

        ''' Process tvshows and episodes from a single library.
        '''
        with self.library.database_lock:
            with Database() as videodb:
                with Database('emby') as embydb:
                    obj = TVShows(self.server, embydb, videodb, self.direct_path, True)

                    for items in server.get_items(library['Id'], "Series", False, self.sync['RestorePoint'].get('params')):

                        self.sync['RestorePoint'] = items['RestorePoint']
                        start_index = items['RestorePoint']['params']['StartIndex']

                        for index, show in enumerate(items['Items']):

                            percent = int((float(start_index + index) / float(items['TotalRecordCount']))*100)
                            message = show['Name']
                            dialog.update(percent, heading="%s: %s" % (_('addon_name'), library['Name']), message=message)

                            if obj.tvshow(show, library=library) != False:

                                for episodes in server.get_episode_by_show(show['Id']):
                                    for episode in episodes['Items']:

                                        dialog.update(percent, message="%s/%s" % (message, episode['Name'][:10]))
                                        obj.episode(episode)

                    if self.update_library:
                        self.tvshows_compare(library, obj, embydb)
Exemple #9
0
    def boxsets(self, library_id=None, dialog=None):

        ''' Process all boxsets.
        '''
        for items in server.get_items(library_id, "BoxSet", False, self.sync['RestorePoint'].get('params')):

            with self.video_database_locks() as (videodb, jellyfindb):
                obj = Movies(self.server, jellyfindb, videodb, self.direct_path)

                self.sync['RestorePoint'] = items['RestorePoint']
                start_index = items['RestorePoint']['params']['StartIndex']

                for index, boxset in enumerate(items['Items']):

                    dialog.update(int((float(start_index + index) / float(items['TotalRecordCount'])) * 100),
                                  heading="%s: %s" % (translate('addon_name'), translate('boxsets')),
                                  message=boxset['Name'])
                    obj.boxset(boxset)
def get_themes():

    ''' Add theme media locally, via strm. This is only for tv tunes.
        If another script is used, adjust this code.
    '''
    from helper.utils import normalize_string
    from helper.playutils import PlayUtils
    from helper.xmls import tvtunes_nfo

    library = xbmc.translatePath("special://profile/addon_data/plugin.video.emby/library").decode('utf-8')
    play = settings('useDirectPaths') == "1"

    if not xbmcvfs.exists(library + '/'):
        xbmcvfs.mkdir(library)

    if xbmc.getCondVisibility('System.HasAddon(script.tvtunes)'):

        tvtunes = xbmcaddon.Addon(id="script.tvtunes")
        tvtunes.setSetting('custom_path_enable', "true")
        tvtunes.setSetting('custom_path', library)
        LOG.info("TV Tunes custom path is enabled and set.")

    elif xbmc.getCondVisibility('System.HasAddon(service.tvtunes)'):

        tvtunes = xbmcaddon.Addon(id="service.tvtunes")
        tvtunes.setSetting('custom_path_enable', "true")
        tvtunes.setSetting('custom_path', library)
        LOG.info("TV Tunes custom path is enabled and set.")
    else:
        dialog("ok", heading="{emby}", line1=_(33152))

        return

    with Database('emby') as embydb:
        all_views = emby_db.EmbyDatabase(embydb.cursor).get_views()
        views = [x[0] for x in all_views if x[2] in ('movies', 'tvshows', 'mixed')]

    get_server()
    items = {}
    server = EMBY['auth/server-address']
    token = EMBY['auth/token']

    for view in views:
        for result in downloader.get_items(view, params={'HasThemeVideo': True}):
            for item in result['Items']:

                folder = normalize_string(item['Name'].encode('utf-8'))
                items[item['Id']] = folder

        for result in downloader.get_items(view, params={'HasThemeSong': True}):
            for item in result['Items']:

                folder = normalize_string(item['Name'].encode('utf-8'))
                items[item['Id']] = folder

    for item in items:

        nfo_path = os.path.join(library, items[item]).decode('utf-8')
        nfo_file = os.path.join(nfo_path, "tvtunes.nfo").decode('utf-8')

        if not xbmcvfs.exists(nfo_path):
            xbmcvfs.mkdir(nfo_path)

        themes = EMBY['api'].get_themes(item)
        paths = []

        for theme in themes['ThemeVideosResult']['Items'] + themes['ThemeSongsResult']['Items']:
            putils = PlayUtils(theme, False, EMBY)

            if play:
                paths.append(putils.direct_play(theme['MediaSources'][0]))
            else:
                paths.append(putils.direct_url(theme['MediaSources'][0]))

        tvtunes_nfo(nfo_file, paths)

    dialog("notification", heading="{emby}", message=_(33153), icon="{emby}", time=1000, sound=False)
Exemple #11
0
    def music(self, library, dialog):
        ''' Process artists, album, songs from a single library.
        '''
        with self.library.music_database_lock:
            with Database('music') as musicdb:
                with Database('jellyfin') as jellyfindb:
                    obj = Music(self.server, jellyfindb, musicdb,
                                self.direct_path, library)

                    library_id = library['Id']

                    total_items = server.get_item_count(
                        library_id, 'MusicArtist,MusicAlbum,Audio')
                    count = 0
                    '''
                    Music database syncing.  Artists must be in the database
                    before albums, albums before songs.  Pulls batches of items
                    in sizes of setting "Paging - Max items".  'artists',
                    'albums', and 'songs' are generators containing a dict of
                    api responses
                    '''
                    artists = server.get_artists(library_id)
                    for batch in artists:
                        for item in batch['Items']:
                            LOG.debug('Artist: {}'.format(item.get('Name')))
                            percent = int(
                                (float(count) / float(total_items)) * 100)
                            dialog.update(percent,
                                          message='Artist: {}'.format(
                                              item.get('Name')))
                            obj.artist(item)
                            count += 1

                    albums = server.get_items(library_id,
                                              item_type='MusicAlbum',
                                              params={'SortBy': 'AlbumArtist'})
                    for batch in albums:
                        for item in batch['Items']:
                            LOG.debug('Album: {}'.format(item.get('Name')))
                            percent = int(
                                (float(count) / float(total_items)) * 100)
                            dialog.update(percent,
                                          message='Album: {} - {}'.format(
                                              item.get('AlbumArtist', ''),
                                              item.get('Name')))
                            obj.album(item)
                            count += 1

                    songs = server.get_items(library_id,
                                             item_type='Audio',
                                             params={'SortBy': 'AlbumArtist'})
                    for batch in songs:
                        for item in batch['Items']:
                            LOG.debug('Song: {}'.format(item.get('Name')))
                            percent = int(
                                (float(count) / float(total_items)) * 100)
                            dialog.update(percent,
                                          message='Track: {} - {}'.format(
                                              item.get('AlbumArtist', ''),
                                              item.get('Name')))
                            obj.song(item)
                            count += 1

                    if self.update_library:
                        self.music_compare(library, obj, jellyfindb)