예제 #1
0
def show_photos(scraper_id, album_url):
    scraper_manager = ScraperManager()
    scraper_manager.switch(scraper_id)
    for photo in scraper_manager.get_photos(album_url):
        li = xbmcgui.ListItem(
            label=photo['title'],
            thumbnailImage=photo['pic']
        )
        li.setInfo(type='image', infoLabels={'Title': photo['title']})
        xbmcplugin.addDirectoryItem(
            handle=int(sys.argv[1]),
            url=photo['pic'],
            listitem=li,
            isFolder=False
        )
    xbmcplugin.endOfDirectory(int(sys.argv[1]))
def set_random_album():
    clear_properties()
    scraper_manager = ScraperManager()

    scraper_manager.shuffle()
    scraper_manager.next()
    albums = scraper_manager.get_albums()
    album = random.choice(albums)
    photos = scraper_manager.get_photos(album['album_url'])

    set_property('scraper.title', scraper_manager.current_scraper.title)
    set_property('scraper.id', str(scraper_manager.current_scraper._id))
    set_property('album.title', album['title'])
    set_property('album.url', album['album_url'])
    set_property('album.photo_count', str(min(len(photos), MAX_ITEMS)))
    for i, photo in enumerate(photos):
        for key in ('pic', 'description', 'title'):
            set_property('photo.%d.%s' % (i, key), photo[key])
        if i + 1 == MAX_ITEMS:
            break
    if DEBUG:
        xbmc.executebuiltin('XBMC.Notification("Done", "TBP Widget", 1000)')
예제 #3
0
class GUI(xbmcgui.WindowXML):

    CONTROL_MAIN_IMAGE = 100
    CONTROL_VISIBLE = 102
    CONTROL_ASPECT_KEEP = 103
    CONTROL_ARROWS = 104
    CONTROL_BG = 105
    ACTION_CONTEXT_MENU = [117]
    ACTION_PREVIOUS_MENU = [9, 92, 10]
    ACTION_SHOW_INFO = [11]
    ACTION_EXIT_SCRIPT = [13]
    ACTION_DOWN = [4]
    ACTION_UP = [3]
    ACTION_0 = [58, 18]
    ACTION_PLAY = [79]

    def __init__(self, skin_file, addon_path):
        self.log("__init__")
        self.getScrapers()

    def getScrapers(self):
        enabled_scrapers = []
        for scraper in ALL_SCRAPERS:
            if addon.getSetting("enable_%s" % scraper) == "true":
                enabled_scrapers.append(scraper)
        self.scraper_manager = ScraperManager(enabled_scrapers)

    def onInit(self):
        self.log("onInit")
        self.show_info = True
        self.aspect_keep = True
        self.last_seen_album_id = 0

        self.getControls()

        if addon.getSetting("show_arrows") == "false":
            self.arrows_controller.setVisible(False)
        if addon.getSetting("aspect_ratio2") == "0":
            self.aspect_controller.setVisible(False)
        if addon.getSetting("black_background") == "true":
            if self.bg_controller:
                self.bg_controller.setVisible(False)

        self.showHelp()
        self.showAlbums()

        self.setFocus(self.image_list)
        self.log("onInit finished")

    def getControls(self):
        self.window = xbmcgui.Window(xbmcgui.getCurrentWindowId())
        self.image_list = self.getControl(self.CONTROL_MAIN_IMAGE)
        self.arrows_controller = self.getControl(self.CONTROL_ARROWS)
        self.aspect_controller = self.getControl(self.CONTROL_ASPECT_KEEP)
        self.info_controller = self.getControl(self.CONTROL_VISIBLE)
        try:
            self.bg_controller = self.getControl(self.CONTROL_BG)
        except RuntimeError:
            # catch exception with skins which override the xml
            # but are not up2date like Aeon Nox
            self.bg_controller = None

    def onAction(self, action):
        action_id = action.getId()
        if action_id in self.ACTION_SHOW_INFO:
            self.toggleInfo()
        elif action_id in self.ACTION_CONTEXT_MENU:
            self.download_album()
        elif action_id in self.ACTION_PREVIOUS_MENU:
            if self.getWindowProperty("Category") == "Album":
                self.close()
            elif self.getWindowProperty("Category") == "Photo":
                self.showAlbums(self.last_seen_album_id)
        elif action_id in self.ACTION_EXIT_SCRIPT:
            self.close()
        elif action_id in self.ACTION_DOWN:
            if self.getWindowProperty("Category") == "Album":
                self.scraper_manager.next()
                self.showAlbums()
        elif action_id in self.ACTION_UP:
            if self.getWindowProperty("Category") == "Album":
                self.scraper_manager.previous()
                self.showAlbums()
        elif action_id in self.ACTION_0:
            self.toggleAspect()
        elif action_id in self.ACTION_PLAY:
            self.startSlideshow()

    def onClick(self, controlId):
        if controlId == self.CONTROL_MAIN_IMAGE:
            if self.getWindowProperty("Category") == "Album":
                self.showPhotos()
            elif self.getWindowProperty("Category") == "Photo":
                self.toggleInfo()

    def showPhotos(self):
        self.log("showPhotos")
        self.last_seen_album_id = int(self.getItemProperty("album_id"))
        album_url = self.getItemProperty("album_url")
        self.addItems(self.scraper_manager.get_photos(album_url))
        self.setWindowProperty("Category", "Photo")
        self.log("showPhotos finished")

    def showAlbums(self, switch_to_album_id=0):
        self.log("showAlbums started with switch to album_id: %s" % switch_to_album_id)
        self.addItems(self.scraper_manager.get_albums())
        if switch_to_album_id:
            self.image_list.selectItem(switch_to_album_id)
        self.setWindowProperty("Category", "Album")
        self.log("showAlbums finished")

    def addItems(self, items):
        self.log("addItems")
        self.image_list.reset()
        for item in items:
            li = xbmcgui.ListItem(label=item["title"], label2=item["description"], iconImage=item["pic"])
            li.setProperty("album_title", self.scraper_manager.current_scraper.title)
            li.setProperty("album_url", item.get("album_url"))
            li.setProperty("album_id", str(item.get("album_id")))
            self.image_list.addItem(li)

    def getItemProperty(self, key):
        return self.image_list.getSelectedItem().getProperty(key)

    def getWindowProperty(self, key):
        return self.window.getProperty(key)

    def setWindowProperty(self, key, value):
        return self.window.setProperty(key, value)

    def toggleInfo(self):
        self.show_info = not self.show_info
        self.info_controller.setVisible(self.show_info)

    def toggleAspect(self):
        self.aspect_keep = not self.aspect_keep
        self.aspect_controller.setVisible(self.aspect_keep)

    def startSlideshow(self):
        self.log("startSlideshow")
        params = {"scraper_id": self.scraper_manager._current_index, "album_url": self.getItemProperty("album_url")}
        if addon.getSetting("random_slideshow") == "true":
            random = "random"
        else:
            random = "notrandom"
        url = "plugin://%s/?%s" % (addon.getAddonInfo("id"), urllib.urlencode(params))
        self.log("startSlideshow using url=%s" % url)
        xbmc.executebuiltin("Slideshow(%s, recursive, %s)" % (url, random))
        self.log("startSlideshow finished")

    def download_album(self):
        self.log("download_album")
        download_path = addon.getSetting("download_path")
        if not download_path:
            s = addon.getLocalizedString(32300)  # Choose default download path
            new_path = xbmcgui.Dialog().browse(3, s, "pictures")
            if not new_path:
                return
            else:
                download_path = new_path
                addon.setSetting("download_path", download_path)
        self.log('download_album using download_path="%s"' % download_path)
        downloader = Downloader(download_path)
        album_url = self.getItemProperty("album_url")
        items = self.scraper_manager.get_photos(album_url)
        downloader.download(items)
        del downloader
        self.log("download_album finished")

    def showHelp(self):
        if not addon.getSetting("dont_show_help") == "true":
            addon.openSettings()

    def log(self, msg):
        xbmc.log("TheBigPictures GUI: %s" % msg)
예제 #4
0
 def getScrapers(self):
     enabled_scrapers = []
     for scraper in ALL_SCRAPERS:
         if addon.getSetting("enable_%s" % scraper) == "true":
             enabled_scrapers.append(scraper)
     self.scraper_manager = ScraperManager(enabled_scrapers)
예제 #5
0
 def get_scrapers(self):
     enabled_scrapers = []
     for scraper in ALL_SCRAPERS:
         if addon.getSetting('enable_%s' % scraper) == 'true':
             enabled_scrapers.append(scraper)
     self.scraper_manager = ScraperManager(enabled_scrapers)
예제 #6
0
class Screensaver(xbmcgui.WindowXMLDialog):
    class ExitMonitor(xbmc.Monitor):
        def __init__(self, exit_callback):
            self.exit_callback = exit_callback

        def onScreensaverDeactivated(self):
            self.exit_callback()

    def onInit(self):
        self.abort_requested = False
        self.started = False
        self.exit_monitor = self.ExitMonitor(self.exit)

        self.picture_control = self.getControl(30001)
        self.loader_control = self.getControl(30002)
        self.source_control = self.getControl(30003)
        self.title_control = self.getControl(30004)
        self.next_picture_control = self.getControl(30006)

        self.picture_duration = (int(addon.getSetting('picture_duration')) *
                                 1000)

        if int(addon.getSetting('choose_view')) == 0:
            self.description_control = self.getControl(30005)
        elif int(addon.getSetting('choose_view')) == 1:
            self.picture_control.setWidth(self.getWidth())
            self.picture_control.setHeight(self.getHeight())
        self.get_scrapers()
        self.slideshow()

    def get_scrapers(self):
        enabled_scrapers = []
        for scraper in ALL_SCRAPERS:
            if addon.getSetting('enable_%s' % scraper) == 'true':
                enabled_scrapers.append(scraper)
        self.scraper_manager = ScraperManager(enabled_scrapers)

    def slideshow(self):
        self.scraper_manager.shuffle()
        while not self.abort_requested:
            self.scraper_manager.next()
            albums = self.scraper_manager.get_albums()
            random.shuffle(albums)
            for album in albums:
                photos = self.scraper_manager.get_photos(album['album_url'])
                random.shuffle(photos)
                for i, photo in enumerate(photos):
                    photo['source'] = (
                        self.scraper_manager.current_scraper.title)
                    self.set_photo(photo)
                    if i + 1 < len(photos):
                        next_photo = photos[i + 1]
                        self.preload_next_photo(next_photo)
                    for i in xrange(self.picture_duration / 500):
                        #self.log('check abort %d' % (i + 1))
                        if self.abort_requested:
                            self.log('slideshow abort_requested')
                            self.exit()
                            return
                        xbmc.sleep(500)

    def set_photo(self, photo):
        if not self.started:
            self.loader_control.setVisible(False)
            self.started = True
        picture_url = photo['pic']
        #self.log('photo: %s' % picture_url)
        self.picture_control.setImage(picture_url)
        self.source_control.setLabel(photo['source'])
        self.title_control.setLabel(photo['title'])
        if int(addon.getSetting('choose_view')) == 0:
            self.description_control.setText(photo['description'])

    def preload_next_photo(self, photo):
        picture_url = photo['pic']
        self.next_picture_control.setImage(picture_url)

    def exit(self):
        self.abort_requested = True
        self.exit_monitor = None
        self.log('exit')
        self.close()

    def log(self, msg):
        xbmc.log(u'TheBigPictures Screensaver: %s' % msg)
class Screensaver(xbmcgui.WindowXMLDialog):
    class ExitMonitor(xbmc.Monitor):
        def __init__(self, exit_callback):
            self.exit_callback = exit_callback

        def onScreensaverDeactivated(self):
            self.exit_callback()

    def onInit(self):
        self.abort_requested = False
        self.started = False
        self.exit_monitor = self.ExitMonitor(self.exit)

        self.picture_control = self.getControl(30001)
        self.loader_control = self.getControl(30002)
        self.source_control = self.getControl(30003)
        self.title_control = self.getControl(30004)
        self.description_control = self.getControl(30005)
        self.next_picture_control = self.getControl(30006)

        self.picture_duration = int(addon.getSetting("picture_duration")) * 1000

        self.get_scrapers()
        self.slideshow()

    def get_scrapers(self):
        enabled_scrapers = []
        for scraper in ALL_SCRAPERS:
            if addon.getSetting("enable_%s" % scraper) == "true":
                enabled_scrapers.append(scraper)
        self.scraper_manager = ScraperManager(enabled_scrapers)

    def slideshow(self):
        self.scraper_manager.shuffle()
        while not self.abort_requested:
            self.scraper_manager.next()
            albums = self.scraper_manager.get_albums()
            random.shuffle(albums)
            for album in albums:
                photos = self.scraper_manager.get_photos(album["album_url"])
                random.shuffle(photos)
                for i, photo in enumerate(photos):
                    photo["source"] = self.scraper_manager.current_scraper.title
                    self.set_photo(photo)
                    if i + 1 < len(photos):
                        next_photo = photos[i + 1]
                        self.preload_next_photo(next_photo)
                    for i in xrange(self.picture_duration / 500):
                        # self.log('check abort %d' % (i + 1))
                        if self.abort_requested:
                            self.log("slideshow abort_requested")
                            self.exit()
                            return
                        xbmc.sleep(500)

    def set_photo(self, photo):
        if not self.started:
            self.loader_control.setVisible(False)
            self.started = True
        picture_url = photo["pic"]
        # self.log('photo: %s' % picture_url)
        self.picture_control.setImage(picture_url)
        self.source_control.setLabel(photo["source"])
        self.title_control.setLabel(photo["title"])
        self.description_control.setText(photo["description"])

    def preload_next_photo(self, photo):
        picture_url = photo["pic"]
        self.next_picture_control.setImage(picture_url)

    def exit(self):
        self.abort_requested = True
        self.exit_monitor = None
        self.log("exit")
        self.close()

    def log(self, msg):
        xbmc.log(u"TheBigPictures Screensaver: %s" % msg)
예제 #8
0
class GUI(xbmcgui.WindowXML):

    CONTROL_MAIN_IMAGE = 100
    CONTROL_VISIBLE = 102
    CONTROL_ASPECT_KEEP = 103
    CONTROL_ARROWS = 104
    CONTROL_BG = 105
    ACTION_CONTEXT_MENU = [117]
    ACTION_PREVIOUS_MENU = [9, 92, 10]
    ACTION_SHOW_INFO = [11]
    ACTION_EXIT_SCRIPT = [13]
    ACTION_DOWN = [4]
    ACTION_UP = [3]
    ACTION_0 = [58, 18]
    ACTION_PLAY = [79]

    def __init__(self, skin_file, addon_path):
        self.log('__init__')
        self.getScrapers()

    def getScrapers(self):
        enabled_scrapers = []
        for scraper in ALL_SCRAPERS:
            if addon.getSetting('enable_%s' % scraper) == 'true':
                enabled_scrapers.append(scraper)
        self.scraper_manager = ScraperManager(enabled_scrapers)

    def onInit(self):
        self.log('onInit')
        self.show_info = True
        self.aspect_keep = True
        self.last_seen_album_id = 0

        self.getControls()

        if addon.getSetting('show_arrows') == 'false':
            self.arrows_controller.setVisible(False)
        if addon.getSetting('aspect_ratio2') == '0':
            self.aspect_controller.setVisible(False)
        if addon.getSetting('black_background') == 'true':
            if self.bg_controller:
                self.bg_controller.setVisible(False)

        self.showHelp()
        self.showAlbums()

        self.setFocus(self.image_list)
        self.log('onInit finished')

    def getControls(self):
        self.window = xbmcgui.Window(xbmcgui.getCurrentWindowId())
        self.image_list = self.getControl(self.CONTROL_MAIN_IMAGE)
        self.arrows_controller = self.getControl(self.CONTROL_ARROWS)
        self.aspect_controller = self.getControl(self.CONTROL_ASPECT_KEEP)
        self.info_controller = self.getControl(self.CONTROL_VISIBLE)
        try:
            self.bg_controller = self.getControl(self.CONTROL_BG)
        except RuntimeError:
            # catch exception with skins which override the xml
            # but are not up2date like Aeon Nox
            self.bg_controller = None

    def onAction(self, action):
        action_id = action.getId()
        if action_id in self.ACTION_SHOW_INFO:
            self.toggleInfo()
        elif action_id in self.ACTION_CONTEXT_MENU:
            self.download_album()
        elif action_id in self.ACTION_PREVIOUS_MENU:
            if self.getWindowProperty('Category') == 'Album':
                self.close()
            elif self.getWindowProperty('Category') == 'Photo':
                self.showAlbums(self.last_seen_album_id)
        elif action_id in self.ACTION_EXIT_SCRIPT:
            self.close()
        elif action_id in self.ACTION_DOWN:
            if self.getWindowProperty('Category') == 'Album':
                self.scraper_manager.next()
                self.showAlbums()
        elif action_id in self.ACTION_UP:
            if self.getWindowProperty('Category') == 'Album':
                self.scraper_manager.previous()
                self.showAlbums()
        elif action_id in self.ACTION_0:
            self.toggleAspect()
        elif action_id in self.ACTION_PLAY:
            self.startSlideshow()

    def onClick(self, controlId):
        if controlId == self.CONTROL_MAIN_IMAGE:
            if self.getWindowProperty('Category') == 'Album':
                self.showPhotos()
            elif self.getWindowProperty('Category') == 'Photo':
                self.toggleInfo()

    def showPhotos(self):
        self.log('showPhotos')
        self.last_seen_album_id = int(self.getItemProperty('album_id'))
        album_url = self.getItemProperty('album_url')
        self.addItems(self.scraper_manager.get_photos(album_url))
        self.setWindowProperty('Category', 'Photo')
        self.log('showPhotos finished')

    def showAlbums(self, switch_to_album_id=0):
        self.log('showAlbums started with switch to album_id: %s' %
                 switch_to_album_id)
        self.addItems(self.scraper_manager.get_albums())
        if switch_to_album_id:
            self.image_list.selectItem(switch_to_album_id)
        self.setWindowProperty('Category', 'Album')
        self.log('showAlbums finished')

    def addItems(self, items):
        self.log('addItems')
        self.image_list.reset()
        for item in items:
            li = xbmcgui.ListItem(label=item['title'],
                                  label2=item['description'],
                                  iconImage=item['pic'])
            li.setProperty('album_title',
                           self.scraper_manager.current_scraper.title)
            li.setProperty('album_url', item.get('album_url'))
            li.setProperty('album_id', str(item.get('album_id')))
            self.image_list.addItem(li)

    def getItemProperty(self, key):
        return self.image_list.getSelectedItem().getProperty(key)

    def getWindowProperty(self, key):
        return self.window.getProperty(key)

    def setWindowProperty(self, key, value):
        return self.window.setProperty(key, value)

    def toggleInfo(self):
        self.show_info = not self.show_info
        self.info_controller.setVisible(self.show_info)

    def toggleAspect(self):
        self.aspect_keep = not self.aspect_keep
        self.aspect_controller.setVisible(self.aspect_keep)

    def startSlideshow(self):
        self.log('startSlideshow')
        params = {
            'scraper_id': self.scraper_manager._current_index,
            'album_url': self.getItemProperty('album_url')
        }
        if addon.getSetting('random_slideshow') == 'true':
            random = 'random'
        else:
            random = 'notrandom'
        url = 'plugin://%s/?%s' % (addon.getAddonInfo('id'),
                                   urllib.urlencode(params))
        self.log('startSlideshow using url=%s' % url)
        xbmc.executebuiltin('Slideshow(%s, recursive, %s)' % (url, random))
        self.log('startSlideshow finished')

    def download_album(self):
        self.log('download_album')
        download_path = addon.getSetting('download_path')
        if not download_path:
            s = addon.getLocalizedString(32300)  # Choose default download path
            new_path = xbmcgui.Dialog().browse(3, s, 'pictures')
            if not new_path:
                return
            else:
                download_path = new_path
                addon.setSetting('download_path', download_path)
        self.log('download_album using download_path="%s"' % download_path)
        downloader = Downloader(download_path)
        album_url = self.getItemProperty('album_url')
        items = self.scraper_manager.get_photos(album_url)
        downloader.download(items)
        del downloader
        self.log('download_album finished')

    def showHelp(self):
        if not addon.getSetting('dont_show_help') == 'true':
            addon.openSettings()

    def log(self, msg):
        xbmc.log('TheBigPictures GUI: %s' % msg)