Esempio n. 1
0
def identify_unmatched(mediatype):
    busy = pykodi.get_busydialog()
    busy.create()
    processed = ProcessedItems()
    ulist = quickjson.get_item_list(mediatype)
    if mediatype == mediatypes.MUSICVIDEO:
        for item in ulist:
            item['label'] = info.build_music_label(item)
    unmatched = [
        item for item in ulist
        if not processed.get_data(item[mediatype +
                                       'id'], mediatype, item['label'])
    ]
    busy.close()
    if unmatched:
        selected = xbmcgui.Dialog().select(L(
            M.UNMATCHED_ITEMS), [item['label'] for item in unmatched])
        if selected < 0:
            return  # Cancelled
        mediaitem = info.MediaItem(unmatched[selected])
        info.add_additional_iteminfo(mediaitem, processed, search)
        processor = ArtworkProcessor()
        if processor.manual_id(mediaitem):
            processor.process_item(mediatype, mediaitem.dbid, 'auto')
    else:
        xbmcgui.Dialog().notification("Artwork Beef", L(M.NO_UNMATCHED_ITEMS),
                                      xbmcgui.NOTIFICATION_INFO)
Esempio n. 2
0
def remove_specific_arttypes():
    options = [
        (L(M.MOVIES), lambda: quickjson.get_item_list(mediatypes.MOVIE),
         mediatypes.MOVIE),
        (L(M.SERIES), quickjson.get_tvshows, mediatypes.TVSHOW),
        (L(M.SEASONS), quickjson.get_seasons, mediatypes.SEASON),
        (L(M.MOVIESETS), lambda: quickjson.get_item_list(mediatypes.MOVIESET),
         mediatypes.MOVIESET),
        (L(M.EPISODES), quickjson.get_episodes, mediatypes.EPISODE),
        (L(M.MUSICVIDEOS),
         lambda: quickjson.get_item_list(mediatypes.MUSICVIDEO),
         mediatypes.MUSICVIDEO)
    ]
    if get_kodi_version() >= 18:
        options.extend(
            ((L(M.ARTISTS), lambda: quickjson.get_item_list(mediatypes.ARTIST),
              mediatypes.ARTIST),
             (L(M.ALBUMS), lambda: quickjson.get_item_list(mediatypes.ALBUM),
              mediatypes.ALBUM),
             (L(M.SONGS), lambda: quickjson.get_item_list(mediatypes.SONG),
              mediatypes.SONG)))

    selected = xbmcgui.Dialog().select(L(
        M.REMOVE_SPECIFIC_TYPES), [option[0] + " ..." for option in options])
    if selected < 0 or selected >= len(options):
        return
    busy = pykodi.get_busydialog()
    busy.create()
    allitems = options[selected][1]()
    counter = {}
    types_to_remove = set()
    for arttype, url in chain.from_iterable(
            d.get('art', {}).iteritems() for d in allitems):
        if '.' in arttype: continue
        counter['* all'] = counter.get('* all', 0) + 1
        counter[arttype] = counter.get(arttype, 0) + 1
        if not info.keep_arttype(options[selected][2], arttype, url):
            types_to_remove.add(arttype)
            counter['* nowhitelist'] = counter.get('* nowhitelist', 0) + 1

    arttypes = sorted(counter.keys())
    busy.close()
    ftype = lambda intype: '* ' + ', '.join(sorted(
        types_to_remove)) if intype == '* nowhitelist' else intype
    selectedarttype = xbmcgui.Dialog().select(options[selected][0], [
        "{0}: {1}".format(ftype(arttype), counter[arttype])
        for arttype in arttypes
    ])
    if selectedarttype >= 0 and selectedarttype < len(arttypes):

        def removetypes(mediaitem):
            changedart = cleaner.remove_specific_arttype(
                mediaitem, arttypes[selectedarttype])
            info.remove_local_from_texturecache(
                (mediaitem.art[arttype] for arttype in changedart), True)
            return changedart

        fixcount = runon_medialist(removetypes, L(M.REMOVE_SPECIFIC_TYPES),
                                   allitems, options[selected][0])
        notify_count(L(M.REMOVED_ART_COUNT), fixcount)
Esempio n. 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))
Esempio n. 4
0
def get_cached_tvshows():
    return quickjson.get_item_list(mediatypes.TVSHOW)
Esempio n. 5
0
def runon_medialist(function,
                    heading,
                    medialist='videos',
                    typelabel=None,
                    fg=False):
    progress = xbmcgui.DialogProgress() if fg else xbmcgui.DialogProgressBG()
    progress.create(heading)
    monitor = xbmc.Monitor()

    if medialist == 'videos':
        steps_to_run = [
            (lambda: quickjson.get_item_list(mediatypes.MOVIE), L(M.MOVIES)),
            (info.get_cached_tvshows, L(M.SERIES)),
            (quickjson.get_seasons, L(M.SEASONS)),
            (lambda: quickjson.get_item_list(mediatypes.MOVIESET),
             L(M.MOVIESETS)), (quickjson.get_episodes, L(M.EPISODES)),
            (lambda: quickjson.get_item_list(mediatypes.MUSICVIDEO),
             L(M.MUSICVIDEOS))
        ]
    elif medialist == 'music' and get_kodi_version() >= 18:
        steps_to_run = [
            (lambda: quickjson.get_item_list(mediatypes.ARTIST), L(M.ARTISTS)),
            (lambda: quickjson.get_item_list(mediatypes.ALBUM), L(M.ALBUMS)),
            (lambda: quickjson.get_item_list(mediatypes.SONG), L(M.SONGS))
        ]
    else:
        steps_to_run = ((lambda: medialist, typelabel), )
    stepsize = 100 // len(steps_to_run)

    def update_art_for_items(items, start):
        changedcount = 0
        for i, item in enumerate(items):
            if fg:
                progress.update(start + i * stepsize // len(items),
                                item['label'])
            else:
                progress.update(start + i * stepsize // len(items))
            item = info.MediaItem(item)
            if item.mediatype == mediatypes.SEASON:
                item.file = info.get_cached_tvshow(item.tvshowid)['file']
            updates = function(item)
            if isinstance(updates, int):
                changedcount += updates
            else:
                processed = utils.get_simpledict_updates(item.art, updates)
                if processed:
                    info.update_art_in_library(item.mediatype, item.dbid,
                                               processed)
                    changedcount += len(processed)
            if monitor.abortRequested() or fg and progress.iscanceled():
                break
        return changedcount

    fixcount = 0
    for i, (list_fn, listtype) in enumerate(steps_to_run):
        start = i * stepsize
        if fg:
            progress.update(start, line1=L(M.LISTING_ALL).format(listtype))
        else:
            progress.update(start, message=L(M.LISTING_ALL).format(listtype))
        fixcount += update_art_for_items(list_fn(), start)
        if monitor.abortRequested() or fg and progress.iscanceled():
            break

    info.clear_cache()
    progress.close()
    return fixcount