Permalink
Browse files

Add better unicode handling

close dialog when finished using it
  • Loading branch information...
1 parent 4a115ba commit 2783fa31cfe5226eb7ab8748cf0d24e4b14e2b46 @Giftie committed Feb 11, 2013
Showing with 30 additions and 20 deletions.
  1. +21 −12 resources/lib/database.py
  2. +2 −2 resources/lib/download.py
  3. +1 −0 resources/lib/fanarttv_scraper.py
  4. +6 −6 resources/lib/gui.py
View
@@ -5,7 +5,11 @@
try:
from sqlite3 import dbapi2 as sqlite3
except:
- from pysqlite2 import dbapi2 as sqlite3
+ from pysqlite2 import dbapi2 as sqlite3
+if sys.version_info < (2, 7):
+ import simplejson
+else:
+ import json as simplejson
__language__ = sys.modules[ "__main__" ].__language__
__scriptname__ = sys.modules[ "__main__" ].__scriptname__
@@ -95,15 +99,18 @@ def user_updates( details, type ):
c.close()
def restore_user_updates():
- conn = sqlite3.connect(addon_db)
- c = conn.cursor()
- c.execute( '''UPDATE lalist SET musicbrainz_artistid = (SELECT artist_updates.musicbrainz_artistid FROM artist_updates WHERE artist_updates.local_id = lalist.local_id ) WHERE EXISTS ( SELECT * FROM artist_updates WHERE artist_updates.name = lalist.name )''' )
- c.execute( '''UPDATE local_artists SET musicbrainz_artistid = (SELECT artist_updates.musicbrainz_artistid FROM artist_updates WHERE artist_updates.local_id = local_artists.local_id ) WHERE EXISTS ( SELECT * FROM artist_updates WHERE artist_updates.name = local_artists.name )''' )
- c.execute( '''UPDATE alblist SET musicbrainz_artistid = (SELECT album_updates.musicbrainz_artistid FROM album_updates WHERE album_updates.album_id = alblist.album_id ) WHERE EXISTS ( SELECT * FROM album_updates WHERE album_updates.album_id = alblist.album_id )''' )
- c.execute( '''UPDATE alblist SET musicbrainz_albumid = (SELECT album_updates.musicbrainz_albumid FROM album_updates WHERE album_updates.album_id = alblist.album_id ) WHERE EXISTS ( SELECT * FROM album_updates WHERE album_updates.album_id = alblist.album_id )''' )
- conn.commit()
- c.close()
-
+ try:
+ conn = sqlite3.connect(addon_db)
+ c = conn.cursor()
+ c.execute( '''UPDATE lalist SET musicbrainz_artistid = (SELECT artist_updates.musicbrainz_artistid FROM artist_updates WHERE artist_updates.local_id = lalist.local_id ) WHERE EXISTS ( SELECT * FROM artist_updates WHERE artist_updates.name = lalist.name )''' )
+ c.execute( '''UPDATE local_artists SET musicbrainz_artistid = (SELECT artist_updates.musicbrainz_artistid FROM artist_updates WHERE artist_updates.local_id = local_artists.local_id ) WHERE EXISTS ( SELECT * FROM artist_updates WHERE artist_updates.name = local_artists.name )''' )
+ c.execute( '''UPDATE alblist SET musicbrainz_artistid = (SELECT album_updates.musicbrainz_artistid FROM album_updates WHERE album_updates.album_id = alblist.album_id ) WHERE EXISTS ( SELECT * FROM album_updates WHERE album_updates.album_id = alblist.album_id )''' )
+ c.execute( '''UPDATE alblist SET musicbrainz_albumid = (SELECT album_updates.musicbrainz_albumid FROM album_updates WHERE album_updates.album_id = alblist.album_id ) WHERE EXISTS ( SELECT * FROM album_updates WHERE album_updates.album_id = alblist.album_id )''' )
+ conn.commit()
+ c.close()
+ except:
+ traceback.print_exc()
+
def artist_list_to_string( artist ):
artist_string = ""
if not ( type( artist ) is list ):
@@ -376,6 +383,8 @@ def store_lalist( local_artist_list, count_artist_local ):
c.execute( '''insert into lalist(local_id, name, musicbrainz_artistid, fanarttv_has_art) values (?, ?, ?, ?)''', (artist["local_id"], unicode(artist["name"], 'utf-8', ), artist["musicbrainz_artistid"], artist[ "has_art" ] ))
except TypeError:
c.execute( '''insert into lalist(local_id, name, musicbrainz_artistid, fanarttv_has_art) values (?, ?, ?, ?)''', (artist["local_id"], get_unicode( artist["name"] ), artist["musicbrainz_artistid"], artist[ "has_art" ] ))
+ except:
+ traceback.print_exc()
artist_count += 1
percent = int(( artist_count / float( count_artist_local ) ) * 100)
except:
@@ -448,7 +457,6 @@ def check_local_albumartist( album_artist, local_artist_list, background=False )
found = False
local_album_artist_list = []
for artist in album_artist: # match album artist to local artist id
- #log( artist, xbmc.LOGDEBUG )
album_artist_1 = {}
name = ""
name = get_unicode( artist_list_to_string( artist["name"] ) )
@@ -468,8 +476,9 @@ def check_local_albumartist( album_artist, local_artist_list, background=False )
album_artist_1["has_art"] = "False"
local_album_artist_list.append( album_artist_1 )
else:
+ log( "Artist Not Found:", xbmc.LOGDEBUG )
try:
- print repr( artist_list_to_string( artist["name"] ) )
+ log( repr( artist_list_to_string( artist["name"] ) ), xbmc.LOGDEBUG )
except:
traceback.print_exc()
return local_album_artist_list, artist_count
@@ -33,7 +33,7 @@
from fanarttv_scraper import remote_banner_list, remote_hdlogo_list, get_recognized, remote_cdart_list, remote_coverart_list, remote_fanart_list, remote_clearlogo_list, remote_artistthumb_list
from database import get_local_artists_db, get_local_albums_db, artwork_search
-from utils import clear_image_cache, get_unicode, change_characters, log, dialog_msg
+from utils import clear_image_cache, get_unicode, change_characters, log, dialog_msg, smart_unicode, smart_utf8
from file_item import Thumbnails
from jsonrpc_calls import get_all_local_artists, retrieve_album_list, retrieve_album_details, get_album_path, get_thumbnail_path, get_fanart_path
from xbmcvfs import delete as delete_file
@@ -252,7 +252,7 @@ def auto_download( type, artist_list, background=False ):
auto_art["musicbrainz_artistid"] = artist["musicbrainz_artistid"]
temp_art["artist"] = artist["name"]
auto_art["artist"] = artist["name"]
- path = os.path.join( music_path, change_characters( artist["name"] ) )
+ path = os.path.join( music_path, change_characters( smart_unicode( artist["name"] ) ) )
if type == "fanart":
art = remote_fanart_list( auto_art )
elif type == "clearlogo":
@@ -353,6 +353,7 @@ def first_check( all_artists, album_artists, background=False, update_db = False
count += 1
store_local_artist_table( all_artists_matched, background = background )
store_fanarttv_datecode( present_datecode )
+ dialog_msg( "close", background = background )
log( "Finished First Check", xbmc.LOGDEBUG )
return
View
@@ -45,7 +45,7 @@
# script imports
from fanarttv_scraper import check_fanart_new_artwork, first_check, remote_banner_list, remote_hdlogo_list, get_recognized, remote_cdart_list, remote_fanart_list, remote_clearlogo_list, remote_coverart_list, remote_artistthumb_list
-from utils import get_html_source, clear_image_cache, get_unicode, change_characters, log, dialog_msg
+from utils import get_html_source, clear_image_cache, get_unicode, change_characters, log, dialog_msg, smart_unicode, smart_utf8
from download import download_art, auto_download
from database import user_updates, backup_database, store_alblist, store_lalist, retrieve_distinct_album_artists, store_counts, database_setup, get_local_albums_db, get_local_artists_db, new_local_count, refresh_db, artwork_search, update_database, check_album_mbid, check_artist_mbid, update_missing_artist_mbid, update_missing_album_mbid
from musicbrainz_utils import get_musicbrainz_artist_id, get_musicbrainz_album, update_musicbrainzid, get_musicbrainz_artists
@@ -1224,7 +1224,7 @@ def onClick( self, controlId ):
local_cdart = ( (self.getControl(122).getSelectedItem().getLabel2() ).split("&&&&")[1] ).split("&&")[0]
database_id = int( ( ( self.getControl(122).getSelectedItem().getLabel2() ).split("&&&&")[1] ).split("&&")[1] )
url = ((self.getControl( 122 ).getSelectedItem().getLabel2()).split("&&&&")[0]).split("&&")[0]
- cdart_path["path"] = ((self.getControl( 122 ).getSelectedItem().getLabel2()).split("&&&&")[0]).split("&&")[1]
+ cdart_path["path"] = ( (self.getControl( 122 ).getSelectedItem().getLabel2() ).split("&&&&")[0]).split("&&")[1]
try:
cdart_path["artist"] = get_unicode( self.getControl( 204 ).getLabel() ).replace( __language__(32038) + "[CR]","")
except:
@@ -1408,7 +1408,7 @@ def onClick( self, controlId ):
if self.menu_mode == 7:
url = ( self.getControl( 167 ).getSelectedItem().getLabel2() ).split("&&&&")[ 1 ]
artist["artist"] = ( self.getControl( 167 ).getSelectedItem().getLabel2() ).split("&&&&")[ 0 ]
- artist["path"] = os.path.join( music_path, change_characters( artist["artist"] ) )
+ artist["path"] = os.path.join( music_path, change_characters( smart_unicode( artist["artist"] ) ) )
selected_item = self.getControl( 167 ).getSelectedPosition()
if url:
message, success, is_canceled = download_art( url, artist, self.artist_menu["local_id"], "clearlogo", "manual", 0 )
@@ -1423,7 +1423,7 @@ def onClick( self, controlId ):
if self.menu_mode == 13:
url = ( self.getControl( 202 ).getSelectedItem().getLabel2() ).split("&&&&")[ 1 ]
artist["artist"] = ( self.getControl( 202 ).getSelectedItem().getLabel2() ).split("&&&&")[ 0 ]
- artist["path"] = os.path.join( music_path, change_characters( artist["artist"] ) )
+ artist["path"] = os.path.join( music_path, change_characters( smart_unicode( artist["artist"] ) ) )
selected_item = self.getControl( 202 ).getSelectedPosition()
if url:
message, success, is_canceled = download_art( url, artist, self.artist_menu["local_id"], "musicbanner", "manual", 0 )
@@ -1438,7 +1438,7 @@ def onClick( self, controlId ):
if self.menu_mode == 6:
url = ( self.getControl( 160 ).getSelectedItem().getLabel2() ).split("&&&&")[ 1 ]
artist["artist"] = ( self.getControl( 160 ).getSelectedItem().getLabel2() ).split("&&&&")[ 0 ]
- artist["path"] = os.path.join( music_path, change_characters( artist["artist"] ) )
+ artist["path"] = os.path.join( music_path, change_characters( smart_unicode( artist["artist"] ) ) )
selected_item = self.getControl( 160 ).getSelectedPosition()
if url:
message, success, is_canceled = download_art( url, artist, self.artist_menu["local_id"], "fanart", "manual", 0 )
@@ -1453,7 +1453,7 @@ def onClick( self, controlId ):
if self.menu_mode == 9:
url = ( self.getControl( 199 ).getSelectedItem().getLabel2() ).split("&&&&")[ 1 ]
artist["artist"] = ( self.getControl( 199 ).getSelectedItem().getLabel2() ).split("&&&&")[ 0 ]
- artist["path"] = os.path.join( music_path, change_characters( artist["artist"] ) )
+ artist["path"] = os.path.join( music_path, change_characters( smart_unicode( artist["artist"] ) ) )
selected_item = self.getControl( 199 ).getSelectedPosition()
if url:
message, success, is_canceled = download_art( url, artist, self.artist_menu["local_id"], "artistthumb", "manual", 0 )

0 comments on commit 2783fa3

Please sign in to comment.