Example #1
0
    def process_allvideos(self, shouldinclude_fn=None):
        allvideos = self.check_allepisodes
        if not shouldinclude_fn:
            allvideos = True
            shouldinclude_fn = lambda id, type, label: True
        items = []
        if not mediatypes.disabled(mediatypes.MOVIESET):
            items.extend(info.MediaItem(mset) for mset in chain.from_iterable(
                    quickjson.gen_chunked_item_list(mediatypes.MOVIESET))
                if shouldinclude_fn(mset['setid'], mediatypes.MOVIESET, mset['label']))
        if not mediatypes.disabled(mediatypes.MOVIE):
            items.extend(info.MediaItem(movie) for movie in chain.from_iterable(
                    quickjson.gen_chunked_item_list(mediatypes.MOVIE))
                if shouldinclude_fn(movie['movieid'], mediatypes.MOVIE, movie['label']))
        if not mediatypes.disabled(mediatypes.MUSICVIDEO):
            items.extend(info.MediaItem(mvid) for mvid in chain.from_iterable(
                    quickjson.gen_chunked_item_list(mediatypes.MUSICVIDEO))
                if shouldinclude_fn(mvid['musicvideoid'], mediatypes.MUSICVIDEO, info.build_music_label(mvid)))

        serieslist = quickjson.get_tvshows()
        if self.abortRequested():
            return False
        if not mediatypes.disabled(mediatypes.TVSHOW):
            for series in serieslist:
                processed_season = self.processed.get_data(series['tvshowid'], mediatypes.TVSHOW, series['label'])
                if not processed_season or series['season'] > int(processed_season) \
                or shouldinclude_fn(series['tvshowid'], mediatypes.TVSHOW, series['label']):
                    items.append(info.MediaItem(series))
                if self.abortRequested():
                    return False
        if include_any_episode():
            seriesmap = dict((s['tvshowid'], s['imdbnumber']) for s in serieslist)
            episodes = []
            for episodelist in (quickjson.gen_chunked_item_list(mediatypes.EPISODE)
                    if allvideos else [quickjson.get_episodes(limit=500)]):
                for episode in episodelist:
                    ep = info.MediaItem(episode)
                    if seriesmap.get(ep.tvshowid) in settings.autoadd_episodes or include_episode(ep):
                        episodes.append(ep)
                if self.abortRequested():
                    return False
            self.check_allepisodes = len(episodes) > 400
            for episode in episodes:
                if seriesmap.get(episode.tvshowid) not in settings.autoadd_episodes:
                    episode.skip_artwork = ['fanart']
                    items.append(episode)
                elif shouldinclude_fn(episode.dbid, mediatypes.EPISODE, episode.label):
                    items.append(episode)
                if self.abortRequested():
                    return False
        self.reset_recent()
        return self.processor.process_medialist(items)
Example #2
0
    def process_recentvideos(self):
        ignoreepisodesfrom = set()
        addepisodesfrom = set()
        seriesadded = set()
        newitems = []
        for mtype in ('movie', 'musicvideo', 'tvshow'):
            if mediatypes.disabled(mtype):
                continue
            for mediaid in self.recentvideos[mtype]:
                if mtype == 'tvshow':
                    seriesadded.add(mediaid)
                jsonitem = quickjson.get_item_details(mediaid, mtype)
                if jsonitem.get('setid'):
                    newitems.append(info.MediaItem(quickjson.get_item_details(jsonitem['setid'], mediatypes.MOVIESET)))
                newitems.append(info.MediaItem(jsonitem))
                if self.abortRequested():
                    return
        for episodeid in self.recentvideos['episode']:
            episode = info.MediaItem(quickjson.get_item_details(episodeid, mediatypes.EPISODE))
            series = None
            if not mediatypes.disabled(mediatypes.TVSHOW) and episode.tvshowid not in seriesadded \
            and episode.season > self.processed.get_data(episode.tvshowid, mediatypes.TVSHOW, episode.label):
                seriesadded.add(episode.tvshowid)
                series = info.MediaItem(quickjson.get_item_details(episode.tvshowid, mediatypes.TVSHOW))
                newitems.append(series)
            if not include_any_episode():
                if self.abortRequested():
                    return
                continue
            if episode.tvshowid in addepisodesfrom:
                newitems.append(episode)
            elif episode.tvshowid in ignoreepisodesfrom:
                if include_episode(episode):
                    episode.skip_artwork = ['fanart']
                    newitems.append(episode)
            else:
                if not series:
                    series = info.MediaItem(quickjson.get_item_details(episode.tvshowid, mediatypes.TVSHOW))
                if any(x for x in series.uniqueids.values() if x in settings.autoadd_episodes):
                    addepisodesfrom.add(episode.tvshowid)
                    newitems.append(episode)
                else:
                    ignoreepisodesfrom.add(episode.tvshowid)
                    if include_episode(episode):
                        episode.skip_artwork = ['fanart']
                        newitems.append(episode)
            if self.abortRequested():
                return

        self.reset_recent()
        self.processor.process_medialist(newitems)
Example #3
0
    def process_allmusic(self, shouldinclude_fn=None):
        if mediatypes.disabled(mediatypes.ALBUM) and mediatypes.disabled(mediatypes.ARTIST):
            return True
        if not shouldinclude_fn:
            shouldinclude_fn = lambda id, type, label: True
        albums = []
        if not mediatypes.disabled(mediatypes.ALBUM):
            albums.extend(info.MediaItem(album) for album in quickjson.get_albums()
                if shouldinclude_fn(album['albumid'], mediatypes.ALBUM, info.build_music_label(album)))
        if self.abortRequested():
            return False
        artists = []
        if not mediatypes.disabled(mediatypes.ARTIST):
            artists.extend(info.MediaItem(artist) for artist in quickjson.get_item_list(mediatypes.ARTIST)
                if shouldinclude_fn(artist['artistid'], mediatypes.ARTIST, artist['label']))
        if self.abortRequested():
            return False
        if not albums and not artists:
            return True
        chunkedalbums = [albums[x:x+ALBUM_CHUNK_SIZE] for x in range(0, len(albums), ALBUM_CHUNK_SIZE)]
        def chunk_filler():
            for albumgroup in chunkedalbums:
                songs = _buildsongs(albumgroup)
                if self.abortRequested():
                    yield False
                itemgroup = []
                for album in albumgroup:
                    if not mediatypes.disabled(mediatypes.ARTIST):
                        artist = next((a for a in artists if a.dbid == album.artistid), None)
                        if artist:
                            itemgroup.append(artist)
                            artists.remove(artist)
                    if not mediatypes.disabled(mediatypes.ALBUM):
                        itemgroup.append(album)
                    if not mediatypes.disabled(mediatypes.SONG) and album.dbid in songs:
                        itemgroup.extend(info.MediaItem(song) for song in songs[album.dbid])
                    if self.abortRequested():
                        yield False

                yield itemgroup
            if artists: # New artists that didn't match an album
                yield artists
        return self.processor.process_chunkedlist(chunk_filler(), len(chunkedalbums))
Example #4
0
def _buildsongs(albumgroup):
    result = {}
    if mediatypes.disabled(mediatypes.SONG):
        return result
    songfilter = {'field': 'album', 'operator': 'is',
        'value': [album.label for album in albumgroup]}
    for song in quickjson.get_songs(songfilter=songfilter):
        if song['albumid'] not in result:
            result[song['albumid']] = []
        result[song['albumid']].append(song)
    return result
Example #5
0
        def chunk_filler():
            for albumgroup in chunkedalbums:
                songs = _buildsongs(albumgroup)
                if self.abortRequested():
                    yield False
                itemgroup = []
                for album in albumgroup:
                    if not mediatypes.disabled(mediatypes.ARTIST):
                        artist = next((a for a in artists if a.dbid == album.artistid), None)
                        if artist:
                            itemgroup.append(artist)
                            artists.remove(artist)
                    if not mediatypes.disabled(mediatypes.ALBUM):
                        itemgroup.append(album)
                    if not mediatypes.disabled(mediatypes.SONG) and album.dbid in songs:
                        itemgroup.extend(info.MediaItem(song) for song in songs[album.dbid])
                    if self.abortRequested():
                        yield False

                yield itemgroup
            if artists: # New artists that didn't match an album
                yield artists
Example #6
0
    def process_item(self, mediatype, dbid, mode):
        if self.processor_busy:
            return
        if mode == MODE_DEBUG:
            mode = MODE_AUTO
            self.set_debug(True)
        if mode == MODE_GUI:
            busy = pykodi.get_busydialog()
            busy.create()
        if mediatype in mediatypes.artinfo and (mediatype
                                                not in mediatypes.audiotypes
                                                or get_kodi_version() >= 18):
            mediaitem = info.MediaItem(
                quickjson.get_item_details(dbid, mediatype))
            log("Processing {0} '{1}' {2}.".format(
                mediatype, mediaitem.label,
                'automatically' if mode == MODE_AUTO else 'manually'))
        else:
            if mode == MODE_GUI:
                busy.close()
            xbmcgui.Dialog().notification(
                "Artwork Beef",
                L(NOT_SUPPORTED_MESSAGE).format(mediatype), '-', 6500)
            return

        self.init_run()
        if mediatype == mediatypes.EPISODE:
            series = quickjson.get_item_details(mediaitem.tvshowid,
                                                mediatypes.TVSHOW)
            if not any(uniqueid in settings.autoadd_episodes
                       for uniqueid in series['uniqueid'].itervalues()):
                mediaitem.skip_artwork = ['fanart']

        info.add_additional_iteminfo(mediaitem, self.processed, search)
        if not mediaitem.uniqueids and not mediatypes.only_filesystem(
                mediaitem.mediatype):
            if mediatype in mediatypes.require_manualid:
                self.manual_id(mediaitem)
        if mode == MODE_GUI:
            self._manual_item_process(mediaitem, busy)
        else:
            medialist = [mediaitem]
            if mediatype == mediatypes.TVSHOW and not mediatypes.disabled(
                    mediatypes.EPISODE):
                gen_epthumb = mediatypes.generatethumb(mediatypes.EPISODE)
                download_ep = mediatypes.downloadanyartwork(mediatypes.EPISODE)
                if mediaitem.uniqueids and any(
                        x in mediaitem.uniqueids.values()
                        for x in settings.autoadd_episodes):
                    medialist.extend(
                        info.MediaItem(ep)
                        for ep in quickjson.get_episodes(dbid))
                elif gen_epthumb or download_ep:
                    for episode in quickjson.get_episodes(dbid):
                        if gen_epthumb and not info.has_generated_thumbnail(episode) \
                        or download_ep and info.has_art_todownload(episode['art'], mediatypes.EPISODE):
                            episode = info.MediaItem(episode)
                            episode.skip_artwork = ['fanart']
                            medialist.append(episode)
            elif mediatype == mediatypes.ARTIST and not mediatypes.disabled(
                    mediatypes.ALBUM):
                medialist.extend(
                    info.MediaItem(album) for album in quickjson.get_albums(
                        mediaitem.label, mediaitem.dbid))
            if mediatype in (mediatypes.ALBUM, mediatypes.ARTIST) and not mediatypes.disabled(mediatypes.ALBUM) \
            and not mediatypes.disabled(mediatypes.SONG):
                medialist.extend(
                    info.MediaItem(song) for song in quickjson.get_songs(
                        mediaitem.mediatype, mediaitem.dbid))
            self.process_medialist(medialist, True)
Example #7
0
def include_any_episode():
    return not mediatypes.disabled(mediatypes.EPISODE) \
        and (mediatypes.generatethumb(mediatypes.EPISODE) or mediatypes.downloadanyartwork(mediatypes.EPISODE) \
            or settings.autoadd_episodes)