Esempio n. 1
0
    def onClick(self, controlID):
        try:
            if controlID == self.CONTROL_LIST_450:
                listitem = self.control_list.getSelectedItem()
                l2 = listitem.getLabel2()
                if l2 == "browse":
                    heading = (LangXBMC(20019),
                               LangXBMC(20437))[self.thumb_type == "fanart"]
                    ipath = xbmc.translatePath(
                        get_browse_dialog(heading=heading, dlg_type=2))
                    if ipath and xbmcvfs.exists(ipath):
                        listitem = self.control_list.getListItem(0)
                        listitem.setThumbnailImage(self.default_icon)
                        dpath = self.get_current_thumb()
                        OK = xbmcvfs.copy(ipath, dpath)
                        print "%s, FileCopy(%s,%s)" % (repr(OK), ipath, dpath)
                        if xbmcvfs.exists(dpath):
                            if self.getControl(
                                    self.CONTROL_RADIOBUTTON).isSelected():
                                dpath = metautils.flip_fanart(
                                    dpath, PIL_Image,
                                    ADDON.getSetting("flipquality"))
                            listitem.setThumbnailImage(dpath)
                            self.actor_update = True

                elif l2 == "current":
                    listitem.select(True)
                    icon = self.get_current_thumb()
                    ipath = icon.split("userdata")[-1].replace("\\",
                                                               "/").strip("/")
                    if icon and xbmcgui.Dialog().yesno(LangXBMC(122),
                                                       LangXBMC(125), ipath):
                        #try: os.remove( xbmc.translatePath( icon ) )
                        #except: print_exc()
                        #else:
                        xbmcvfs.delete(xbmc.translatePath(icon))
                        if not xbmcvfs.exists(icon):
                            listitem.setThumbnailImage(self.default_icon)
                    listitem.select(False)

                else:
                    listitem.select(not listitem.isSelected())

            elif controlID == self.CONTROL_BUTTON_CREATE:
                self.select_all = not self.select_all
                for listitem in self.listitems:
                    listitem.select(self.select_all)

            elif controlID == self.CONTROL_BUTTON_CANCEL:
                self._close_dialog()

            elif controlID == self.CONTROL_BUTTON_OK:
                self._download()

        except:
            print_exc()
Esempio n. 2
0
    def onClick( self, controlID ):
        try:
            if controlID == self.CONTROL_LIST_450:
                listitem = self.control_list.getSelectedItem()
                l2 = listitem.getLabel2()
                if l2 == "browse":
                    heading = ( LangXBMC( 20019 ), LangXBMC( 20437 ) )[ self.thumb_type == "fanart" ]
                    ipath = xbmc.translatePath( get_browse_dialog( heading=heading, dlg_type=2 ) )
                    if ipath and xbmcvfs.exists( ipath ):
                        listitem = self.control_list.getListItem( 0 )
                        listitem.setThumbnailImage( self.default_icon )
                        dpath = self.get_current_thumb()
                        OK = xbmcvfs.copy( ipath, dpath )
                        print  "%s, FileCopy(%s,%s)" % ( repr( OK ), ipath, dpath )
                        if xbmcvfs.exists( dpath ):
                            if self.getControl( self.CONTROL_RADIOBUTTON ).isSelected():
                                dpath = metautils.flip_fanart( dpath, PIL_Image, ADDON.getSetting( "flipquality" ) )
                            listitem.setThumbnailImage( dpath )
                            self.actor_update = True

                elif l2 == "current":
                    listitem.select( True )
                    icon = self.get_current_thumb()
                    ipath = icon.split( "userdata" )[ -1 ].replace( "\\", "/" ).strip( "/" )
                    if icon and xbmcgui.Dialog().yesno( LangXBMC( 122 ), LangXBMC( 125 ), ipath ):
                        #try: os.remove( xbmc.translatePath( icon ) )
                        #except: print_exc()
                        #else:
                        xbmcvfs.delete( xbmc.translatePath( icon ) )
                        if not xbmcvfs.exists( icon ):
                            listitem.setThumbnailImage( self.default_icon )
                    listitem.select( False )

                else:
                    listitem.select( not listitem.isSelected() )

            elif controlID == self.CONTROL_BUTTON_CREATE:
                self.select_all = not self.select_all
                for listitem in self.listitems:
                    listitem.select( self.select_all )

            elif controlID == self.CONTROL_BUTTON_CANCEL:
                self._close_dialog()

            elif controlID == self.CONTROL_BUTTON_OK:
                self._download()

        except:
            print_exc()
Esempio n. 3
0
    def _download(self):
        try:
            selected = [l for l in self.listitems if l.isSelected()]
            t_selected, t_movies = len(selected), len(self.listitems)
            if selected and xbmcgui.Dialog().yesno(
                    self.heading, Language(32122),
                    Language(32123) % (t_selected, t_movies), Language(32124)):
                is_cached_thumb = False
                if t_selected > 1:
                    # if multi download to user folder
                    heading = Language(32126) + (Language(
                        32127), Language(32128))[self.thumb_type == "thumb"]
                    overwrite = xbmcgui.Dialog().yesno(Language(32135),
                                                       Language(32136))
                    # make cached actor thumb
                    cached_actor_thumb = "special://thumbnails/Actors/" + self.search_name + "/extra" + self.thumb_type
                    metautils.xbmcvfs_makedirs(cached_actor_thumb)
                    dpath = xbmc.translatePath(cached_actor_thumb)
                    #print repr( dpath )
                else:
                    # otherwise, download to cached thumb
                    overwrite = True
                    is_cached_thumb = True
                    dpath = self.get_current_thumb()
                    cached_actor_thumb = dpath
                    self.control_list.getListItem(0).setThumbnailImage(
                        self.default_icon)

                def _pbhook(numblocks, blocksize, filesize, ratio=1.0):
                    try:
                        pct = int(
                            min((numblocks * blocksize * 100) / filesize, 100)
                            * ratio)
                    except:
                        pct = 100
                    DIALOG_PROGRESS.update(pct)
                    if DIALOG_PROGRESS.iscanceled():
                        raise IOError

                DIALOG_PROGRESS.create(self.heading)
                diff = 100.0 / t_selected
                percent = 0

                flipfanart = self.getControl(
                    self.CONTROL_RADIOBUTTON).isSelected()

                for count, listitem in enumerate(selected):
                    self.control_list.selectItem(
                        int(listitem.getProperty("indexItem")))
                    url = listitem.getLabel2()
                    if is_cached_thumb: dest = TEMP_DIR + os.path.basename(url)
                    else:
                        dest = _unicode(
                            os.path.join(dpath, os.path.basename(url)))
                    percent += diff
                    line1 = Language(32125) % (count + 1, t_selected, percent)
                    line3 = cached_actor_thumb + "/" + os.path.basename(url)
                    DIALOG_PROGRESS.update(0, line1, url, line3)

                    if not overwrite and xbmcvfs.exists(dest):
                        listitem.select(False)
                        continue
                    # download file
                    try:
                        fp, h = urllib.urlretrieve(
                            url, dest, lambda nb, bs, fs: _pbhook(nb, bs, fs))
                        if h["Content-Type"] == "text/html":
                            raise Exception("bad thumb: %r" % fp)
                    except:
                        self.delete_files.add(dest)
                        dest = None
                        print_exc()
                    listitem.select(False)
                    if DIALOG_PROGRESS.iscanceled():
                        break
                    #flip source
                    if dest and flipfanart:
                        dest = metautils.flip_fanart(
                            dest, PIL_Image, ADDON.getSetting("flipquality"))

                    if is_cached_thumb and dest:
                        self.delete_files.add(dest)
                        OK = xbmcvfs.copy(dest, dpath)
                        print "%s, FileCopy(%s,%s)" % (repr(OK), dest, dpath)
                        if xbmcvfs.exists(dpath):
                            listitem = self.control_list.getListItem(0)
                            listitem.setThumbnailImage(dpath)
                            self.actor_update = True

            self.delete_files = _delete_files(self.delete_files)
        except:
            print_exc()
        if xbmc.getCondVisibility("Window.IsVisible(progressdialog)"):
            xbmc.executebuiltin("Dialog.Close(progressdialog)")
        #try: DIALOG_PROGRESS.close()
        #except: pass
        self.setFocusId(self.CONTROL_BUTTON_CANCEL)
Esempio n. 4
0
    def _download( self ):
        try:
            selected = [ l for l in self.listitems if l.isSelected() ]
            t_selected, t_movies = len( selected ), len( self.listitems )
            if selected and xbmcgui.Dialog().yesno( self.heading, Language( 32122 ), Language( 32123 ) % ( t_selected, t_movies ), Language( 32124 ) ):
                is_cached_thumb = False
                if t_selected > 1:
                    # if multi download to user folder
                    heading = Language( 32126 ) + ( Language( 32127 ), Language( 32128 ) )[ self.thumb_type == "thumb" ]
                    overwrite = xbmcgui.Dialog().yesno( Language( 32135 ), Language( 32136 ) )
                    # make cached actor thumb
                    cached_actor_thumb = "special://thumbnails/Actors/" + self.search_name + "/extra" + self.thumb_type
                    metautils.xbmcvfs_makedirs( cached_actor_thumb )
                    dpath = xbmc.translatePath( cached_actor_thumb )
                    #print repr( dpath )
                else:
                    # otherwise, download to cached thumb
                    overwrite = True
                    is_cached_thumb = True
                    dpath = self.get_current_thumb()
                    cached_actor_thumb = dpath
                    self.control_list.getListItem( 0 ).setThumbnailImage( self.default_icon )

                def _pbhook( numblocks, blocksize, filesize, ratio=1.0 ):
                    try: pct = int( min( ( numblocks * blocksize * 100 ) / filesize, 100 ) * ratio )
                    except: pct = 100
                    DIALOG_PROGRESS.update( pct )
                    if DIALOG_PROGRESS.iscanceled():
                        raise IOError

                DIALOG_PROGRESS.create( self.heading )
                diff = 100.0 / t_selected
                percent = 0

                flipfanart = self.getControl( self.CONTROL_RADIOBUTTON ).isSelected()

                for count, listitem in enumerate( selected ):
                    self.control_list.selectItem( int( listitem.getProperty( "indexItem" ) ) )
                    url = listitem.getLabel2()
                    if is_cached_thumb: dest = TEMP_DIR + os.path.basename( url )
                    else: dest = _unicode( os.path.join( dpath, os.path.basename( url ) ) )
                    percent += diff
                    line1 = Language( 32125 ) % ( count+1, t_selected, percent )
                    line3 = cached_actor_thumb + "/" + os.path.basename( url )
                    DIALOG_PROGRESS.update( 0, line1, url, line3 )

                    if not overwrite and xbmcvfs.exists( dest ):
                        listitem.select( False )
                        continue
                    # download file
                    try:
                        fp, h = urllib.urlretrieve( url, dest, lambda nb, bs, fs: _pbhook( nb, bs, fs ) )
                        if h[ "Content-Type" ] == "text/html":
                            raise Exception( "bad thumb: %r" % fp )
                    except:
                        self.delete_files.add( dest )
                        dest = None
                        print_exc()
                    listitem.select( False )
                    if DIALOG_PROGRESS.iscanceled():
                        break
                    #flip source
                    if dest and flipfanart:
                        dest = metautils.flip_fanart( dest, PIL_Image, ADDON.getSetting( "flipquality" ) )

                    if is_cached_thumb and dest:
                        self.delete_files.add( dest )
                        OK = xbmcvfs.copy( dest, dpath )
                        print "%s, FileCopy(%s,%s)" %( repr( OK ), dest, dpath )
                        if xbmcvfs.exists( dpath ):
                            listitem = self.control_list.getListItem( 0 )
                            listitem.setThumbnailImage( dpath )
                            self.actor_update = True

            self.delete_files = _delete_files( self.delete_files )
        except:
            print_exc()
        if xbmc.getCondVisibility( "Window.IsVisible(progressdialog)" ):
            xbmc.executebuiltin( "Dialog.Close(progressdialog)" )
        #try: DIALOG_PROGRESS.close()
        #except: pass
        self.setFocusId( self.CONTROL_BUTTON_CANCEL )