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)
Beispiel #2
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 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)
Beispiel #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)
Beispiel #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)
    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)
Beispiel #8
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 remove_library(self, library_id, dialog):
        ''' Remove library by their id from the Kodi database.
        '''
        MEDIA = self.library.MEDIA
        direct_path = self.library.direct_path

        with Database('emby') as embydb:

            db = emby_db.EmbyDatabase(embydb.cursor)
            library = db.get_view(library_id.replace('Mixed:', ""))
            items = db.get_item_by_media_folder(
                library_id.replace('Mixed:', ""))
            media = 'music' if library[1] == 'music' else 'video'

            if items:
                count = 0

                with self.library.music_database_lock if media == 'music' else self.library.database_lock:
                    with Database(media) as kodidb:

                        if library[1] == 'mixed':

                            movies = [x for x in items if x[1] == 'Movie']
                            tvshows = [x for x in items if x[1] == 'Series']

                            obj = MEDIA['Movie'](self.server, embydb, kodidb,
                                                 direct_path)['Remove']

                            for item in movies:

                                obj(item[0])
                                dialog.update(int(
                                    (float(count) / float(len(items)) * 100)),
                                              heading="%s: %s" %
                                              (_('addon_name'), library[0]))
                                count += 1

                            obj = MEDIA['Series'](self.server, embydb, kodidb,
                                                  direct_path)['Remove']

                            for item in tvshows:

                                obj(item[0])
                                dialog.update(int(
                                    (float(count) / float(len(items)) * 100)),
                                              heading="%s: %s" %
                                              (_('addon_name'), library[0]))
                                count += 1
                        else:
                            obj = MEDIA[items[0][1]](self.server, embydb,
                                                     kodidb,
                                                     direct_path)['Remove']

                            for item in items:

                                obj(item[0])
                                dialog.update(int(
                                    (float(count) / float(len(items)) * 100)),
                                              heading="%s: %s" %
                                              (_('addon_name'), library[0]))
                                count += 1

        self.sync = get_sync()

        if library_id in self.sync['Whitelist']:
            self.sync['Whitelist'].remove(library_id)

        elif 'Mixed:%s' % library_id in self.sync['Whitelist']:
            self.sync['Whitelist'].remove('Mixed:%s' % library_id)

        save_sync(self.sync)
Beispiel #10
0
    def remove_library(self, library_id, dialog):
        ''' Remove library by their id from the Kodi database.
        '''
        direct_path = self.library.direct_path

        with Database('jellyfin') as jellyfindb:

            db = jellyfin_db.JellyfinDatabase(jellyfindb.cursor)
            library = db.get_view(library_id.replace('Mixed:', ""))
            items = db.get_item_by_media_folder(
                library_id.replace('Mixed:', ""))
            media = 'music' if library[1] == 'music' else 'video'

            if media == 'music':
                settings('MusicRescan.bool', False)

            if items:
                count = 0

                with self.library.music_database_lock if media == 'music' else self.library.database_lock:
                    with Database(media) as kodidb:

                        if library[1] == 'mixed':

                            movies = [x for x in items if x[1] == 'Movie']
                            tvshows = [x for x in items if x[1] == 'Series']

                            obj = Movies(self.server, jellyfindb, kodidb,
                                         direct_path).remove

                            for item in movies:

                                obj(item[0])
                                dialog.update(
                                    int((float(count) / float(len(items)) *
                                         100)),
                                    heading="%s: %s" %
                                    (translate('addon_name'), library[0]))
                                count += 1

                            obj = TVShows(self.server, jellyfindb, kodidb,
                                          direct_path).remove

                            for item in tvshows:

                                obj(item[0])
                                dialog.update(
                                    int((float(count) / float(len(items)) *
                                         100)),
                                    heading="%s: %s" %
                                    (translate('addon_name'), library[0]))
                                count += 1
                        else:
                            default_args = (self.server, jellyfindb, kodidb,
                                            direct_path)
                            for item in items:
                                if item[1] in ('Series', 'Season', 'Episode'):
                                    TVShows(*default_args).remove(item[0])
                                elif item[1] in ('Movie', 'BoxSet'):
                                    Movies(*default_args).remove(item[0])
                                elif item[1] in ('MusicAlbum', 'MusicArtist',
                                                 'AlbumArtist', 'Audio'):
                                    Music(*default_args).remove(item[0])
                                elif item[1] == 'MusicVideo':
                                    MusicVideos(*default_args).remove(item[0])

                                dialog.update(
                                    int((float(count) / float(len(items)) *
                                         100)),
                                    heading="%s: %s" %
                                    (translate('addon_name'), library[0]))
                                count += 1

        self.sync = get_sync()

        if library_id in self.sync['Whitelist']:
            self.sync['Whitelist'].remove(library_id)

        elif 'Mixed:%s' % library_id in self.sync['Whitelist']:
            self.sync['Whitelist'].remove('Mixed:%s' % library_id)

        save_sync(self.sync)
Beispiel #11
0
    def remove_library(self, library_id, dialog):
        ''' Remove library by their id from the Kodi database.
        '''
        MEDIA = self.library.MEDIA
        direct_path = self.library.direct_path

        with Database('jellyfin') as jellyfindb:

            db = jellyfin_db.JellyfinDatabase(jellyfindb.cursor)
            library = db.get_view(library_id.replace('Mixed:', ""))
            items = db.get_item_by_media_folder(
                library_id.replace('Mixed:', ""))
            media = 'music' if library[1] == 'music' else 'video'

            if media == 'music':
                settings('MusicRescan.bool', False)

            if items:
                count = 0

                with self.library.music_database_lock if media == 'music' else self.library.database_lock:
                    with Database(media) as kodidb:

                        if library[1] == 'mixed':

                            movies = [x for x in items if x[1] == 'Movie']
                            tvshows = [x for x in items if x[1] == 'Series']

                            obj = Movies(self.server, jellyfindb, kodidb,
                                         direct_path).remove

                            for item in movies:

                                obj(item[0])
                                dialog.update(int(
                                    (float(count) / float(len(items)) * 100)),
                                              heading="%s: %s" %
                                              (_('addon_name'), library[0]))
                                count += 1

                            obj = TVShows(self.server, jellyfindb, kodidb,
                                          direct_path).remove

                            for item in tvshows:

                                obj(item[0])
                                dialog.update(int(
                                    (float(count) / float(len(items)) * 100)),
                                              heading="%s: %s" %
                                              (_('addon_name'), library[0]))
                                count += 1
                        else:
                            # from mcarlton: I'm not sure what triggers this.
                            # I've added and removed every media type except
                            # for music videos (because i don't have any) and
                            # can't find it, but I'm not comfortable
                            # removing it right now
                            LOG.info('Triggered the mystery function')
                            LOG.debug('Mystery function item type: {}'.format(
                                items[0][1]))
                            obj = MEDIA[items[0][1]](self.server, jellyfindb,
                                                     kodidb,
                                                     direct_path).remove

                            for item in items:

                                obj(item[0])
                                dialog.update(int(
                                    (float(count) / float(len(items)) * 100)),
                                              heading="%s: %s" %
                                              (_('addon_name'), library[0]))
                                count += 1

        self.sync = get_sync()

        if library_id in self.sync['Whitelist']:
            self.sync['Whitelist'].remove(library_id)

        elif 'Mixed:%s' % library_id in self.sync['Whitelist']:
            self.sync['Whitelist'].remove('Mixed:%s' % library_id)

        save_sync(self.sync)
Beispiel #12
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)
Beispiel #13
0
    def remove_library(self, library_id, dialog):

        try:
            with Database('emby') as embydb:

                db = emby_db.EmbyDatabase(embydb.cursor)
                library = db.get_view(library_id.replace('Mixed:', ""))
                items = db.get_item_by_media_folder(
                    library_id.replace('Mixed:', ""))
                media = 'music' if library[1] == 'music' else 'video'

                if media == 'music':
                    settings('MusicRescan.bool', False)

                if items:
                    count = 0

                    with self.music_database_lock if media == 'music' else self.database_lock:
                        with Database(media) as kodidb:

                            if library[1] == 'mixed':
                                movies = [x for x in items if x[1] == 'Movie']
                                tvshows = [
                                    x for x in items if x[1] == 'Series'
                                ]

                                obj = MEDIA['Movie'](
                                    self.server, embydb, kodidb,
                                    self.direct_path)['Remove']

                                for item in movies:
                                    obj(item[0])
                                    dialog.update(
                                        int((float(count) / float(len(items)) *
                                             100)),
                                        heading="%s: %s" %
                                        (_('addon_name'), library[0]))
                                    count += 1

                                obj = MEDIA['Series'](
                                    self.server, embydb, kodidb,
                                    self.direct_path)['Remove']

                                for item in tvshows:
                                    obj(item[0])
                                    dialog.update(
                                        int((float(count) / float(len(items)) *
                                             100)),
                                        heading="%s: %s" %
                                        (_('addon_name'), library[0]))
                                    count += 1
                            else:
                                obj = MEDIA[items[0][1]](
                                    self.server, embydb, kodidb,
                                    self.direct_path)['Remove']

                                for item in items:
                                    obj(item[0])
                                    dialog.update(
                                        int((float(count) / float(len(items)) *
                                             100)),
                                        heading="%s: %s" %
                                        (_('addon_name'), library[0]))
                                    count += 1

            sync = get_sync()

            if library_id in sync['Whitelist']:
                sync['Whitelist'].remove(library_id)
            elif 'Mixed:%s' % library_id in sync['Whitelist']:
                sync['Whitelist'].remove('Mixed:%s' % library_id)

            save_sync(sync)
            Views().remove_library(library_id)
        except Exception as error:

            LOG.exception(error)
            dialog.close()

            return False

        Views().get_views()
        Views().get_nodes()

        return True