Ejemplo n.º 1
0
    def process_recentitems(self):
        ignoreepisodesfrom = set()
        addepisodesfrom = set()
        seriesadded = set()
        newitems = []
        for movieid in self.recentitems["movie"]:
            newitems.append(quickjson.get_movie_details(movieid, movie_properties))
            if self.abortRequested():
                return
        for seriesid in self.recentitems["tvshow"]:
            seriesadded.add(seriesid)
            newitems.append(quickjson.get_tvshow_details(seriesid, tvshow_properties))
            if self.abortRequested():
                return
        autoaddepisodes = addon.get_setting("autoaddepisodes_list") if addon.get_setting("episode.fanart") else ()
        for episodeid in self.recentitems["episode"]:
            episode = quickjson.get_episode_details(episodeid, episode_properties)
            series = None
            if (
                episode["season"] > self.processed.tvshow.get(episode["tvshowid"])
                and episode["tvshowid"] not in seriesadded
            ):
                seriesadded.add(episode["tvshowid"])
                series = quickjson.get_tvshow_details(episode["tvshowid"], tvshow_properties)
                newitems.append(series)
            if episode["tvshowid"] in addepisodesfrom:
                newitems.append(episode)
            elif episode["tvshowid"] not in ignoreepisodesfrom:
                if not series:
                    series = quickjson.get_tvshow_details(episode["tvshowid"], tvshow_properties)
                if series["imdbnumber"] in autoaddepisodes:
                    addepisodesfrom.add(episode["tvshowid"])
                    newitems.append(episode)
                else:
                    ignoreepisodesfrom.add(episode["tvshowid"])
            if self.abortRequested():
                return

        self.reset_recent()
        processed = self.processor.process_medialist(newitems)
        self.processed.extend(processed)
        self.processed.save()
    def process_item(self, mediatype, dbid, mode):
        if self.processor_busy:
            return
        if mode == MODE_GUI:
            xbmc.executebuiltin('ActivateWindow(busydialog)')
        if mediatype == mediatypes.TVSHOW:
            mediaitem = quickjson.get_tvshow_details(dbid, tvshow_properties)
        elif mediatype == mediatypes.MOVIE:
            mediaitem = quickjson.get_movie_details(dbid, movie_properties)
        elif mediatype == mediatypes.EPISODE:
            mediaitem = quickjson.get_episode_details(dbid, episode_properties)
        else:
            xbmc.executebuiltin('Dialog.Close(busydialog)')
            xbmcgui.Dialog().notification("Artwork Beef", L(NOT_SUPPORTED_MESSAGE).format(mediatype), '-', 6500)
            return

        if mode == MODE_GUI:
            self.init_run()
            self.add_additional_iteminfo(mediaitem)
            gatherer = Gatherer(self.monitor, self.only_filesystem)
            forcedart, availableart, _, error = gatherer.getartwork(mediaitem, False)
            if error:
                header = L(PROVIDER_ERROR_MESSAGE).format(error['providername'])
                xbmcgui.Dialog().notification(header, error['message'], xbmcgui.NOTIFICATION_WARNING)
                log('{0}\n{1}'.format(header, error['message']))

            for arttype, imagelist in availableart.iteritems():
                self.sort_images(arttype, imagelist, mediaitem['file'])
            xbmc.executebuiltin('Dialog.Close(busydialog)')
            if availableart:
                if 'seasons' in mediaitem and 'fanart' in availableart:
                    for season in mediaitem['seasons'].keys():
                        unseasoned_backdrops = [dict(art) for art in availableart['fanart'] if not art.get('hasseason')]
                        key = 'season.{0}.fanart'.format(season)
                        if key in availableart:
                            availableart[key].extend(unseasoned_backdrops)
                        else:
                            availableart[key] = unseasoned_backdrops
                tag_forcedandexisting_art(availableart, forcedart, mediaitem['art'])
                selectedarttype, selectedart = prompt_for_artwork(mediaitem['mediatype'],
                    mediaitem['label'], availableart, self.monitor)
                if selectedarttype:
                    if selectedarttype.startswith('season.'):
                        gentype = selectedarttype.rsplit('.', 1)[1]
                        multiselect = mediatypes.artinfo[mediatypes.SEASON].get(gentype, {}).get('multiselect', False)
                    else:
                        multiselect = mediatypes.artinfo[mediaitem['mediatype']][selectedarttype]['multiselect']
                    if multiselect:
                        existingurls = [url for exacttype, url in mediaitem['art'].iteritems() \
                            if mediainfo.arttype_matches_base(exacttype, selectedarttype)]
                        urls_toset = [url for url in existingurls if url not in selectedart[1]]
                        urls_toset.extend([url for url in selectedart[0] if url not in urls_toset])
                        selectedart = dict(mediainfo.iter_renumbered_artlist(selectedart, selectedarttype, mediaitem['art'].keys()))
                    else:
                        selectedart = {selectedarttype: selectedart}

                    selectedart = mediainfo.get_artwork_updates(mediaitem['art'], selectedart)
                    if selectedart:
                        add_art_to_library(mediaitem['mediatype'], mediaitem.get('seasons'), mediaitem['dbid'], selectedart)
                    notifycount(len(selectedart))
            else:
                xbmcgui.Dialog().notification(L(NOT_AVAILABLE_MESSAGE),
                    L(SOMETHING_MISSING) + ' ' + L(FINAL_MESSAGE), '-', 8000)
            self.finish_run()
        else:
            medialist = [mediaitem]
            autoaddepisodes = addon.get_setting('autoaddepisodes_list') if addon.get_setting('episode.fanart') else ()
            if mediatype == mediatypes.TVSHOW and mediaitem['imdbnumber'] in autoaddepisodes:
                medialist.extend(quickjson.get_episodes(dbid, properties=episode_properties))
            self.process_medialist(medialist, True)