Example #1
0
def check_size( path, type, size_w, size_h ):
    # first copy from source to work directory since Python does not support SMB://
    file_name = get_filename( type, path, "auto" )
    destination = os.path.join( addon_work_folder, "temp", file_name )
    source = os.path.join( path, file_name )
    log( "Checking Size", xbmc.LOGDEBUG )
    if exists( source ):
        file_copy( source, destination )
    else:
        return True
    try:
        # Helix: not really a Helix problem but file cannot be removed after Image.open locking it
        with open(str(destination), 'rb') as destf:
            artwork = Image.open( destf )
        log( "Image Size: %s px(W) X %s px(H)" % ( artwork.size[ 0 ], artwork.size[ 1 ] ), xbmc.LOGDEBUG )
        if artwork.size[0] < size_w and artwork.size[1] < size_h:  # if image is smaller than 1000 x 1000 and the image on fanart.tv = 1000
            delete_file( destination )
            log( "Image is smaller", xbmc.LOGDEBUG )
            return True
        else:
            delete_file( destination )
            log( "Image is same size or larger", xbmc.LOGDEBUG )
            return False
    except:
        log( "artwork does not exist. Source: %s" % source, xbmc.LOGDEBUG )
        return True
Example #2
0
def empty_tempxml_folder():
    #Helix: paths MUST end with trailing slash
    if exists(os.path.join(tempxml_folder, '')):
        for file_name in os.listdir(os.path.join(tempxml_folder, '')):
            delete_file(os.path.join(tempxml_folder, file_name))
    else:
        pass
def _clear_watched_items( clear_type ):
    xbmc.log( "[ script.cinema.experience ] - _clear_watched_items( %s )" % ( clear_type ), level=xbmc.LOGNOTICE )
    # initialize base_path
    base_paths = []
    # clear trivia or trailers
    if ( clear_type == "ClearWatchedTrailers" ):
        # trailer settings, grab them here so we don't need another _S_() object
        settings = { "trailer_amt_db_file":  xbmc.translatePath( _S_( "trailer_amt_db_file" ) ) }
        # handle AMT db special
        sys.path.append( os.path.join( BASE_RESOURCE_PATH, "lib", "scrapers") )
        from amt_database import scraper as scraper
        Scraper = scraper.Main( settings=settings )
        # update trailers
        Scraper.clear_watched()
        # set base watched file path
        base_paths += [ os.path.join( BASE_CURRENT_SOURCE_PATH, "amt_current_watched.txt" ) ]
        base_paths += [ os.path.join( BASE_CURRENT_SOURCE_PATH, "local_watched.txt" ) ]
    else:
        # set base watched file path
        base_paths = [ os.path.join( BASE_CURRENT_SOURCE_PATH, "trivia_watched.txt" ) ]
    try:
        # set proper message
        message = ( 32531, 32541, )[ sys.argv[ 1 ] == "ClearWatchedTrailers" ]
        # remove watched status file(s)
        for base_path in base_paths:
            # remove file if it exists
            if ( exists( base_path ) ):
                delete_file( base_path )
    except:
        # set proper message
        message = ( 32532, 32542, )[ sys.argv[ 1 ] == "ClearWatchedTrailers" ]
    # inform user of result
    ok = xbmcgui.Dialog().ok( _L_( 32000 ), _L_( message ) )
Example #4
0
def empty_tempxml_folder():
    #Helix: paths MUST end with trailing slash
    if exists( os.path.join(tempxml_folder, '') ):
        for file_name in os.listdir( os.path.join(tempxml_folder, '') ):
            delete_file( os.path.join( tempxml_folder, file_name ) )
    else:
        pass
def _get_slides_xml( path ):
    source = os.path.join( path, "slides.xml" ).replace("\\\\","\\")
    destination = os.path.join( BASE_CURRENT_SOURCE_PATH, "slides.xml" ).replace("\\\\","\\")
    # if no slides.xml exists return false
    if not exists( source ):
        return False, "", "", "", ""
    # fetch data
    file_copy( source, destination )
    xml = open( destination ).read()
    # parse info
    mpaa, theme, question_format, clue_format, answer_format = re.search( "<slides?(?:.+?rating=\"([^\"]*)\")?(?:.+?theme=\"([^\"]*)\")?.*?>.+?<question.+?format=\"([^\"]*)\".*?/>.+?<clue.+?format=\"([^\"]*)\".*?/>.+?<answer.+?format=\"([^\"]*)\".*?/>", xml, re.DOTALL ).groups()
    delete_file ( destination )
    return True, mpaa, question_format, clue_format, answer_format
Example #6
0
def clear_image_cache(url):
    thumb = Thumbnails().get_cached_picture_thumb(url)
    png = os.path.splitext(thumb)[0] + ".png"
    dds = os.path.splitext(thumb)[0] + ".dds"
    jpg = os.path.splitext(thumb)[0] + ".jpg"
    if exists(thumb):
        delete_file(thumb)
    if exists(png):
        delete_file(png)
    if exists(jpg):
        delete_file(jpg)
    if exists(dds):
        delete_file(dds)
Example #7
0
def clear_image_cache( url ):
    thumb = Thumbnails().get_cached_picture_thumb( url )
    png = os.path.splitext( thumb )[0] + ".png"
    dds = os.path.splitext( thumb )[0] + ".dds"
    jpg = os.path.splitext( thumb )[0] + ".jpg"
    if exists( thumb ):
        delete_file( thumb )
    if exists( png ):
        delete_file( png )
    if exists( jpg ):
        delete_file( jpg )
    if exists( dds ):
        delete_file( dds )
 def _reset_watched( self ):
     base_path = os.path.join( self.BASE_CURRENT_SOURCE_PATH, "trivia_watched.txt" )
     if exists( base_path ):
         delete_file( base_path )
         self.watched = []
Example #9
0
def download_art( url_cdart, album, database_id, type, mode, size, background = False ):
    log( "Downloading artwork... ", xbmc.LOGDEBUG )
    download_success = False 
    thumb_path = ""
    percent = 1
    is_canceled = False
    if mode == "auto":
        dialog_msg( "update", percent = percent, background = background )
    else:
        dialog_msg( "create", heading = __language__(32047), background = background )
        #Onscreen Dialog - "Downloading...."
    file_name = get_filename( type, url_cdart, mode )
    #Helix: paths MUST end with trailing slash
    path = os.path.join(album["path"].replace( "\\\\" , "\\" ), '')
    if file_name == "unknown":
        log( "Unknown Type ", xbmc.LOGDEBUG )
        message = [ __language__(32026), __language__(32025), "File: %s" % get_unicode( path ), "Url: %s" % get_unicode( url_cdart ) ]
        return message, download_success
    if type in ( "artistthumb", "cover" ):
        thumbnail_path = get_thumbnail_path( database_id, type )
    else:
        thumbnail_path = ""
    if type == "fanart" and mode in ( "manual", "single" ):
        thumbnail_path = get_fanart_path( database_id, type )
    if not exists( path ):
        try:
            pathsuccess = _makedirs( album["path"].replace( "\\\\" , "\\" ) )
        except:
            pass
    log( "Path: %s" % path, xbmc.LOGDEBUG )
    log( "Filename: %s" % file_name, xbmc.LOGDEBUG )
    log( "url: %s" % url_cdart, xbmc.LOGDEBUG )
    
    # cosmetic: use subfolder for downloading instead of work folder
    if not exists( os.path.join(tempgfx_folder, '').replace( "\\\\","\\" )):
        _makedirs(os.path.join(tempgfx_folder, '').replace( "\\\\","\\" ))
    destination = os.path.join(tempgfx_folder, file_name).replace( "\\\\","\\" ) # download to work folder first
    final_destination = os.path.join( path, file_name ).replace( "\\\\","\\" )
    try:
        #this give the ability to use the progress bar by retrieving the downloading information
        #and calculating the percentage
        def _report_hook( count, blocksize, totalsize ):
            try:
                percent = int( float( count * blocksize * 100 ) / totalsize )
                if percent < 1:
                    percent = 1
                if percent > 100:
                    percent = 100
            except:
                percent = 1
            if type in ( "fanart", "clearlogo", "artistthumb", "musicbanner" ):
                dialog_msg( "update", percent = percent, line1 = "%s%s" % ( __language__(32038) , get_unicode( album["artist"] ) ), background = background )
            else:
                dialog_msg( "update", percent = percent, line1 = "%s%s" % ( __language__(32038) , get_unicode( album["artist"] ) ), line2 = "%s%s" % ( __language__(32039) , get_unicode( album["title"] ) ), background = background )
            if mode == "auto":
                if dialog_msg( "iscanceled", background = background ):
                    is_canceled = True  
        if exists( path ):
            fp, h = urllib.urlretrieve(url_cdart, destination, _report_hook)
            #message = ["Download Sucessful!"]
            message = [__language__(32023), __language__(32024), "File: %s" % get_unicode( path ), "Url: %s" % get_unicode( url_cdart )]
            success = file_copy( destination, final_destination ) # copy it to album folder
            # update database
            try:
                conn = sqlite3.connect(addon_db)
                c = conn.cursor()
                if type == "cdart":
                    c.execute('''UPDATE alblist SET cdart="True" WHERE path="%s"''' % ( get_unicode( album["path"] ) ) )
                elif type == "cover":
                    c.execute('''UPDATE alblist SET cover="True" WHERE path="%s"''' % ( get_unicode( album["path"] ) ) )
                conn.commit()
                c.close()
            except:
                log( "Error updating database", xbmc.LOGDEBUG )
                print_exc()
            download_success = True
        else:
            log( "Path error", xbmc.LOGDEBUG )
            log( "    file path: %s" % repr( destination ), xbmc.LOGDEBUG )
            message = [ __language__(32026),  __language__(32025) , "File: %s" % get_unicode( path ), "Url: %s" % get_unicode( url_cdart ) ]
            #message = Download Problem, Check file paths - Artwork Not Downloaded]           
        # always cleanup downloaded files
        #if type == "fanart":
        delete_file( destination )
    except:
        log( "General download error", xbmc.LOGDEBUG )
        message = [ __language__(32026), __language__(32025), "File: %s" % get_unicode( path ), "Url: %s" % get_unicode( url_cdart ) ]
        #message = [Download Problem, Check file paths - Artwork Not Downloaded]           
        print_exc()
    if mode == "auto" or mode == "single":
        return message, download_success, final_destination, is_canceled  # returns one of the messages built based on success or lack of
    else:
        dialog_msg( "close", background = background )
        return message, download_success, is_canceled
def _reset_watched():
    base_path = os.path.join( BASE_CURRENT_SOURCE_PATH, "trivia_watched.txt" ).replace("\\\\","\\")
    if exists( base_path ):
        delete_file( base_path )
        watched = []
    return watched
Example #11
0
         background_db = True
         # message "cdART Manager, Background Database building in progress...  Exiting Script..."
         dialog_msg( "okdialog", heading = __language__(32042), line1 = __language__(32118) )
         log( "Background Database Building in Progress, exiting", xbmc.LOGNOTICE )
         xbmcgui.Window( 10000 ).setProperty("cdartmanager_update", "False")
 if not background_db and not soft_exit: # If Settings exists and not in background_db mode, continue on
     log( "Addon Work Folder Found, Checking For Database", xbmc.LOGNOTICE )
 if not exists(addon_db) and not background_db: # if l_cdart.db missing, must be first run
     log( "Addon Db not found, Must Be First Run", xbmc.LOGNOTICE )
     first_run = True
 elif not background_db and not soft_exit:
     log( "Addon Db Found, Checking Database Version", xbmc.LOGNOTICE )
 if exists(addon_db_crash) and not first_run and not background_db and not soft_exit: # if l_cdart.db.journal exists, creating database must have crashed at some point, delete and start over
     log( "Detected Database Crash, Trying to delete", xbmc.LOGNOTICE )
     try:
         delete_file(addon_db)
         delete_file(addon_db_crash)
     except StandardError, e:
         log( "Error Occurred: %s " % e.__class__.__name__, xbmc.LOGNOTICE )
         traceback.print_exc()
         script_fail = True
 elif not first_run and not background_db and not soft_exit and not script_fail: # Test database version
     log( "Looking for database version: %s" % __dbversion__, xbmc.LOGNOTICE )
     try:
         conn_l = sqlite3.connect(addon_db)
         c = conn_l.cursor()
         c.execute(query)
         version=c.fetchall()
         c.close
         if version[0][0] == __dbversion__:
             log( "Database matched", xbmc.LOGNOTICE )
Example #12
0
def empty_tempxml_folder():
    if exists( tempxml_folder ):
        for file_name in os.listdir( tempxml_folder ):
            delete_file( os.path.join( tempxml_folder, file_name ) )
    else:
        pass
Example #13
0
 if not exists(
         addon_db
 ) and not background_db:  # if l_cdart.db missing, must be first run
     log("Addon Db not found, Must Be First Run",
         xbmc.LOGNOTICE)
     first_run = True
 elif not background_db and not soft_exit:
     log("Addon Db Found, Checking Database Version",
         xbmc.LOGNOTICE)
 if exists(
         addon_db_crash
 ) and not first_run and not background_db and not soft_exit:  # if l_cdart.db.journal exists, creating database must have crashed at some point, delete and start over
     log("Detected Database Crash, Trying to delete",
         xbmc.LOGNOTICE)
     try:
         delete_file(addon_db)
         delete_file(addon_db_crash)
     except StandardError, e:
         log("Error Occurred: %s " % e.__class__.__name__,
             xbmc.LOGNOTICE)
         traceback.print_exc()
         script_fail = True
 elif not first_run and not background_db and not soft_exit and not script_fail:  # Test database version
     log("Looking for database version: %s" % __dbversion__,
         xbmc.LOGNOTICE)
     try:
         conn_l = sqlite3.connect(addon_db)
         c = conn_l.cursor()
         c.execute(query)
         version = c.fetchall()
         c.close
Example #14
0
def empty_tempxml_folder():
    if exists(tempxml_folder):
        for file_name in os.listdir(tempxml_folder):
            delete_file(os.path.join(tempxml_folder, file_name))
    else:
        pass