Esempio n. 1
0
    # test json
    json.loads( "[null]" )
except:
    import simplejson as json


USER_AGENT = "XBMC Metadata Actors/Dev"
try:
    import xbmc, xbmcvfs
    from xbmcaddon import Addon
    ADDON = Addon( "script.metadata.actors" )
    USER_AGENT = USER_AGENT.replace( "Dev", ADDON.getAddonInfo( "version" ), 1 )
    USER_AGENT += " (XBMC for %s %s; %s)" % ( sys.platform, xbmc.getInfoLabel( "System.BuildVersion" ), xbmc.getInfoLabel( "System.BuildDate" ) )
    ADDON_CACHE = xbmc.translatePath( "%smovies/" % ADDON.getAddonInfo( "profile" ) )
    from metautils import xbmcvfs_makedirs
    xbmcvfs_makedirs( ADDON_CACHE )
    USER_TIME_FORMAT  = xbmc.getRegion( "time" ).replace( ':%S', '', 1 )
    DATE_SHORT_FORMAT = xbmc.getRegion( "dateshort" )
except:
    USER_AGENT += " (Python %s on %s)" % ( sys.version, sys.platform )
    ADDON_CACHE = "movies"
    if not os.path.exists( ADDON_CACHE ): os.makedirs( ADDON_CACHE )
    USER_TIME_FORMAT  = '%H:%M'
    DATE_SHORT_FORMAT = '%Y-%m-%d'


class _urlopener( urllib.FancyURLopener ):
    version = os.environ.get( "HTTP_USER_AGENT" ) or USER_AGENT
urllib._urlopener = _urlopener()

Esempio n. 2
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. 3
0
import re
import sys
import random
import urllib
from datetime import datetime

try:
    import xbmc, xbmcvfs
    from xbmcgui import Window
    from xbmcaddon import Addon
    Addon = Addon( "script.metadata.actors" )
    HOME_WINDOW = Window( 10000 )
    JSON_FILE   = xbmc.translatePath( Addon.getAddonInfo( "profile" ).rstrip( "/" ) + "/mostpopularpeopleborn.json" )
    import metautils
    from actorsdb import get_actors_for_backend
    metautils.xbmcvfs_makedirs( os.path.dirname( JSON_FILE ) )
    ACTORSDB = get_actors_for_backend()
    ACTORS   = metautils.getXBMCActors( busy=False )
    TBN      = metautils.Thumbnails()
    STR_ONLINE_INFO = metautils.Language( 32050 )
    clean_bio = metautils.clean_bio
except:
    # NOT RUNNING ON XBMC, ON DEV
    def clean_bio( bio ): return bio
    HOME_WINDOW = None
    JSON_FILE   = "mostpopularpeopleborn.json"
    ACTORSDB    = {}
    ACTORS      = []
    TBN         = None
    STR_ONLINE_INFO = 'Show Info on IMDB (require a web browser)'
Esempio n. 4
0
# Modules Custom
import metautils
import googleAPI
import actorsdb
import tmdbAPI


# constants
ADDON      = metautils.ADDON
Language   = metautils.Language  # ADDON strings
LangXBMC   = metautils.LangXBMC  # XBMC strings
TBN        = metautils.Thumbnails()
RELOAD_ACTORS_BACKEND = False

TEMP_DIR = xbmc.translatePath( "%scache/" % metautils.ADDON_DATA )
metautils.xbmcvfs_makedirs( TEMP_DIR )

DIALOG_PROGRESS = xbmcgui.DialogProgress()

html_to_xbmc = {
    "<b>":    "[B]",
    "</b>":   "[/B]",
    "<i>":    "[I]",
    "</i>":   "[/I]",
    "&amp;":  "&",
    "&quot;": '"',
    "&#39;":  "'"
    }

def _html_to_xbmc( s ):
    # Replace html formatting to xbmc formatting