def download_cache_hook(count, blockSize, totalSize):
	global pDialog
	global fn
	global start_time
	global downloaded
	if not (pDialog.iscanceled()):
		downloaded = downloaded + blockSize
		if downloaded > totalSize:
			downloaded = totalSize
		try:
			percent = int(min((count*blockSize*100)/totalSize, 100))
		except:
			 percent = 100
		if count != 0:
			time_elapsed = time.time() - start_time
			kbs = downloaded / time_elapsed
			dl_left = totalSize - downloaded
			time_remaining = int(dl_left) / int(kbs)
			time_total = time_remaining + time_elapsed
			kbs = common.convert_bytes(kbs)
			dia_l1 = common.get_lstring(50026) + ": " + fn
			dia_l2 = common.get_lstring(50027) + ": " + str(common.convert_bytes(downloaded)) + "/" + str(common.convert_bytes(totalSize)) + " @ " + str(kbs) + "/s"
			dia_l3 = common.get_lstring(50028) + ": " + str(datetime.timedelta(seconds=int(time_elapsed))) + "/" + str(datetime.timedelta(seconds=int(time_total))) + " (" + common.get_lstring(50029) + ": " + str(datetime.timedelta(seconds=int(time_remaining))) + ")"
			pDialog.update(percent, dia_l1, dia_l2, dia_l3)
	else:
		if not percent==100:
			raise "Cancelled"
def download(url, dir):
	global pDialog
	global start_time
	global downloaded
	downloaded = 0
	error = 0
	start_time = time.time()
	pDialog = xbmcgui.DialogProgress()
	dia_title = common.get_lstring(50016)
	dia_l1 = common.get_lstring(50030)
	ret = pDialog.create(dia_title, dia_l1)
	global fn
	fn = url.rsplit("/")[-1]
	filename = xbmc.translatePath(os.path.join(dir, fn))
	remoteaddr = url

	try:
		urllib.urlretrieve(remoteaddr,filename, reporthook=download_cache_hook)
	except:
		error = 1
		dialog = xbmcgui.Dialog()
		dia_title = common.get_lstring(50016)
		dia_l1 = common.get_lstring(50031)
		ok = dialog.ok(dia_title, dia_l1)
	
	if not error==1:
		unzip_downloaded_cache(filename)
Example #3
0
def add_song(db_filename, db_artist, db_title, db_year, db_comment, sort_letter, db_songlength, total, isfav):

	odb_filename = db_filename
	global set_stream_source
	global set_source
	if set_stream_source=="1":
		rootdir = set_source.replace("\\", "/")
	else:
		rootdir = set_source
	rootdir = rootdir + db_filename
	db_filename = xbmc.translatePath(rootdir)

	
	global set_slmode
	if set_slmode=="0":
		db_songlength = common.get_song_length(db_songlength, 1)
	else:
		global set_slcustom
		db_songlength = set_slcustom

	db_year = str(db_year).replace("?", "0")
	db_year = int(db_year[:4])
	url = db_filename
	
	u = odb_filename
	mode = 7
	name = "1"
	db_filename = odb_filename
	url=sys.argv[0]+"?url="+urllib.quote_plus(u)+"&mode="+str(mode)+"&name="+urllib.quote_plus(name)
	
	ok=True
	liz=xbmcgui.ListItem(db_filename, iconImage="DefaultAudio.png", thumbnailImage="")
	liz.setInfo( type="Music", infoLabels={ "Duration": db_songlength, "Title": db_artist + " - " + db_title, "Artist": db_artist, "Year": db_year, "Genre": "SID", "TrackNumber": 1, "Comment": "None" } )
	liz.setProperty("IsPlayable","true")
	
	# Context Menu
	global path
	script = xbmc.translatePath(os.path.join( path , 'hvscAPI', 'fav.py'))
	param = odb_filename
	if isfav==1:
		l_remsid = common.get_lstring(50015)
		cm = [(l_remsid, 'XBMC.RunScript(' + script + ', rem , ' + param + ')',)]
	else:
		l_addsid = common.get_lstring(50014)
		cm = [(l_addsid, 'XBMC.RunScript(' + script + ', add , ' + param + ')',)]
	liz.addContextMenuItems(cm)
			
	
	ok=xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]),url=url,listitem=liz,totalItems=total,isFolder=False)
	return ok
def unzip_downloaded_cache(archive):
	outdir = xbmc.translatePath(os.path.join( addonsavepath, 'temp'))
	pDialog = xbmcgui.DialogProgress()
	dia_title = common.get_lstring(50016)
	dia_l1 = common.get_lstring(50032)
	ret = pDialog.create(dia_title, dia_l1)
	count = 0
	zfobj = zipfile.ZipFile(archive)
	ico_total = len(zfobj.namelist())
	for name in zfobj.namelist():
		count = count + 1
		percent = int(((float(count) / ico_total) * 100))
		outfilename = xbmc.translatePath(os.path.join(outdir, name))
		outfile = open(os.path.join(outdir, name), 'wb')
		outfile.write(zfobj.read(name))
		outfile.close()
		dia_l1 = common.get_lstring(50026) + ": " + str(name)
		pDialog.update(int(percent), dia_l1)
	zfobj.close()
	os.remove(archive)
	dbcreate(outfilename)
	return
Example #5
0
def Generate_Index():
	global set_fview_musicians
	global set_fview_games
	global set_fview_demos
	
	root_path = xbmc.translatePath(__settings__.getAddonInfo('path'))
	img_path = xbmc.translatePath(os.path.join( root_path, 'resources', 'images'))
			
	# Strings 
	
	l_bookmarks = common.get_lstring(50000)
	l_musicians = common.get_lstring(50001)
	l_games = common.get_lstring(50002)
	l_demos = common.get_lstring(50003)
	l_top = common.get_lstring(50004)
	l_search = common.get_lstring(50005)
	l_addonutilities = common.get_lstring(50006)
	
	# Define Images
	
	i_bookmarks = xbmc.translatePath(os.path.join(img_path, "bookmarks.png"))
	i_musicians = xbmc.translatePath(os.path.join(img_path, "musicians.png"))
	i_games = xbmc.translatePath(os.path.join(img_path, "games.png"))
	i_demos = xbmc.translatePath(os.path.join(img_path, "demos.png"))
	i_top = xbmc.translatePath(os.path.join(img_path, "top.png"))
	i_search = xbmc.translatePath(os.path.join(img_path, "search.png"))
	i_addonutilities = xbmc.translatePath(os.path.join(img_path, "utilities.png"))
	i_bonus = xbmc.translatePath(os.path.join(img_path, "bonus.png"))

	
	addDir(l_bookmarks,'getindex.php?&category=FAV' , 10, i_bookmarks)
	addDir(l_musicians,'getindex.php?&category=MUSICIANS&fview=' + set_fview_musicians, 2, i_musicians)
	addDir(l_games,'getindex.php?&category=GAMES&fview=' + set_fview_games , 2, i_games)
	addDir(l_demos,'getindex.php?&category=DEMOS&fview=' + set_fview_demos , 2, i_demos)
	addDir(l_top,'getindex.php?&category=TOP' , 9, i_top)
	addDir(l_search,'getindex.php?&category=SEARCH&fview=1' , 8, i_search)

	easteregg = xbmc.translatePath(os.path.join('special://profile/addon_data/plugin.audio.hvsc/' , 'easteregg.txt'))
	filecheck = os.path.isfile(easteregg)
	if filecheck==True:
		addDir("Bonus", "plugin://plugin.audio.hvsc/mode=13", 13, i_bonus)

	addDir(l_addonutilities, "none", 11, i_addonutilities)
def dbcreate(csv_db):

	start = time.time()
	
	pDialog = xbmcgui.DialogProgress()
	dia_title = common.get_lstring(50016)
	dia_l1 = common.get_lstring(50020)
	ret = pDialog.create(dia_title, dia_l1)
	
	# Remove old Database
	filecheck = os.path.isfile(databasefile)
	if filecheck==True:
		os.unlink(databasefile)
	
				
	# Define the input list CSV File

	csv_filename = xbmc.translatePath(xbmc.translatePath(csv_db))
	
	# Establish an SQL connection
	connection = sqlite.connect(databasefile)
	cursor = connection.cursor()

	# Create the main table
	cursor.execute('CREATE TABLE siddb (id INTEGER PRIMARY KEY, category TEXT, filename TEXT, format TEXT, version NUMERIC, dataoffset TEXT, md5 TEXT, title TEXT, artist TEXT, release_date NUMERIC, release_name TEXT, songs NUMERIC, startsong NUMERIC, songlength TEXT, size NUMERIC, initaddr TEXT, playaddr TEXT, loadrange TEXT, speed TEXT, musplayer TEXT, playsid_basic NUMERIC, clock TEXT, sidmodel TEXT, startpage TEXT, pagelen TEXT, stil TEXT, stilentry TEXT, playcount NUMERIC, fav NUMERIC)')

	# Here we open the file and create the content variable
	# This is just to count it

	csvfile = open(csv_filename, 'rb')
	csvfile_content = csv.reader(csvfile, delimiter=',', quotechar='"')
	count = 0
	total = len(list(csvfile_content))

	#Now that we got the total Count, it is time to reopen the file, else it will not work
	csvfile.close()
	csvfile = open(csv_filename, 'rb')
	csvfile_content = csv.reader(csvfile, delimiter=',', quotechar='"')

	# Now we go through it

	for row in csvfile_content:
		count += 1

		# CSV Variables (Reading Rows)

		csv_filename = row[0].decode('iso-8859-1')
		csv_format = row[1].decode('iso-8859-1')
		csv_version = row[2].decode('iso-8859-1')
		csv_dataoffset = row[3].decode('iso-8859-1')
		csv_md5 = row[4].decode('iso-8859-1')
		csv_title = row[5].decode('iso-8859-1')
		csv_artist = row[6].decode('iso-8859-1')
		csv_released = row[7].decode('iso-8859-1')
		csv_releasednum = csv_released.split(" ")[0]
		csv_releasedname = csv_released.replace(csv_releasednum, "")
		csv_songs = row[8].decode('iso-8859-1')
		csv_startsong = row[9].decode('iso-8859-1')
		csv_songlength = row[10].decode('iso-8859-1')
		csv_size = row[11].decode('iso-8859-1')
		csv_initaddr = row[12].decode('iso-8859-1')
		csv_playaddr = row[13].decode('iso-8859-1')
		csv_loadrange = row[14].decode('iso-8859-1')
		csv_speed = row[15].decode('iso-8859-1')
		csv_musplayer = row[16].decode('iso-8859-1')
		csv_playsid_basic = row[17].decode('iso-8859-1')
		csv_clock = row[18].decode('iso-8859-1')
		csv_sidmodel = row[19].decode('iso-8859-1')
		csv_startpage = row[20].decode('iso-8859-1')
		csv_pagelen = row[21].decode('iso-8859-1')
		csv_stil = row[22].decode('iso-8859-1')
		#csv_stilentry = row[23].decode('iso-8859-1')
		csv_stilentry = ""
		csv_playcount = 0
		csv_fav = 0

		# Error Checking
		if (csv_stilentry == ""): csv_stilentry = "0"

		if (count!=1):
			csv_category = csv_filename.split("/")[1]
			cursor.execute('INSERT INTO siddb VALUES (null, ?, ?, ?, ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ?, ?, ?, ?)', (csv_category, csv_filename, csv_format, csv_version, csv_dataoffset, csv_md5, csv_title, csv_artist, csv_releasednum, csv_releasedname, csv_songs, csv_startsong, csv_songlength, csv_size, csv_initaddr, csv_playaddr, csv_loadrange, csv_speed, csv_musplayer, csv_playsid_basic, csv_clock, csv_sidmodel, csv_startpage, csv_pagelen, csv_stil, csv_stilentry, csv_playcount, csv_fav ))
			ips_time = time.time() - start
			ips = count / ips_time
			dia_l1 = common.get_lstring(50021)
			dia_l2 = common.get_lstring(50022) + " " + str(count) + "/" + str(total)
			dia_l3 = common.get_lstring(50023) + " " + str(int(round(ips)))
			percent = (float(count) / float(total)) * 100
			print percent
			pDialog.update(int(percent), dia_l1, dia_l2, dia_l3)
			

	connection.commit()
	global global_start_time
	end = time.time()
	elapsed = end - global_start_time
	
	
	dialog = xbmcgui.Dialog()
	dia_title = common.get_lstring(50016)
	dia_l1 = common.get_lstring(50024) + " " + str(datetime.timedelta(seconds=int(elapsed)))
	dia_l2 = common.get_lstring(50025)
	ok = dialog.ok(dia_title, dia_l1)
Example #7
0
if mode==None or url==None or len(url)<1:
	init_addon()
	Generate_Index()
	xbmcplugin.endOfDirectory(int(sys.argv[1]))

	
# Mode 1:
# This Mode runs the Database Creator - it is called by the tool
elif mode==1:
	global dbcon
	global dbcursor
	global path
	if url=="createdb":
	
		dia_title = common.get_lstring(50016)
		dia_l1 = common.get_lstring(50017)
		dia_l2 = common.get_lstring(50018)
		dialog = xbmcgui.Dialog()
		ret = dialog.yesno(dia_title, dia_l1, dia_l2)
		if ret==1:		
			script = xbmc.translatePath(os.path.join(path, "hvscAPI", "dbcreator.py"))
			xbmc.executebuiltin("XBMC.RunScript(" + script + ")")
		else:
			dialog = xbmcgui.Dialog()
			
			dia_title = common.get_lstring(50016)
			dia_l1 = common.get_lstring(50019)
			ok = dialog.ok(dia_title, dia_l1)	
			
	
		
	except:
		error = 1
		dialog = xbmcgui.Dialog()
		dia_title = common.get_lstring(32000)
		dia_l1 = common.get_lstring(32015)
		ok = dialog.ok(dia_title, dia_l1)
	
	if not error==1:
		dialog = xbmcgui.Dialog()
		dia_title = common.get_lstring(32000)
		dia_l1 = common.get_lstring(32016)
		ok = dialog.ok(dia_title, dia_l1)
	

# Logic Handler :)
if not sys.argv[1]=="":

	if sys.argv[1]=="nofolder":
		dialog = xbmcgui.Dialog()
		dia_title = common.get_lstring(32000)
		dia_l1 = common.get_lstring(30907)
		dia_l2 = common.get_lstring(30908)
		ret = dialog.yesno(dia_title, dia_l1, dia_l2)
		if ret==1:
			__settings__.openSettings(url=sys.argv[0])
		
	else:
		if not sys.argv[2]=="":
			download(sys.argv[1], sys.argv[2])
	
Example #9
0
	dbfilename = xbmc.translatePath(os.path.join( 'special://profile/addon_data/plugin.audio.hvsc/db/', 'database.db'  ))
	
	if sys.argv[1]=="add":
		dbcon = sqlite.connect(dbfilename)
		dbcursor = dbcon.cursor()
		query = 'SELECT * FROM siddb where filename="' + sys.argv[2] + '"'
		dbcursor.execute(query)
		row = dbcursor.fetchone()
		id = row[0]
		query = 'UPDATE siddb SET fav=1 WHERE (id=\'' + str(id) + '\')'
		dbcursor.execute(query)
		dbcon.commit()
		
		if set_bcdialogs=="true":
			dialog = xbmcgui.Dialog()
			dia_title = common.get_lstring(50033)
			dia_l1 = common.get_lstring(51000)
			ok = dialog.ok(dia_title, dia_l1)	
			
	
	if sys.argv[1]=="rem":
		dbcon = sqlite.connect(dbfilename)
		dbcursor = dbcon.cursor()
		query = 'SELECT * FROM siddb where filename="' + sys.argv[2] + '"'
		dbcursor.execute(query)
		row = dbcursor.fetchone()
		id = row[0]
		query = 'UPDATE siddb SET fav=0 WHERE (id=\'' + str(id) + '\')'
		dbcursor.execute(query)
		dbcon.commit()