Skip to content
This repository has been archived by the owner on Jan 19, 2022. It is now read-only.

Commit

Permalink
UPDATE: change to xbmc.log() via a centralized function log()
Browse files Browse the repository at this point in the history
  • Loading branch information
rivy committed Jan 22, 2014
1 parent 9a35d3a commit a74cc77
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 27 deletions.
18 changes: 10 additions & 8 deletions default.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@

_NAME = _name.upper()

print _name+": Initializing v%s" % _version
print _name+": sys.platform = %s" % sys.platform
from utils import *

log( "Initializing v%s" % _version )
log( "sys.platform = %s" % sys.platform )

dlg = xbmcgui.DialogProgress()
dlg.create( _NAME, "Loading Script..." )
Expand All @@ -33,7 +35,7 @@
from pandaplayer import PandaPlayer

if _settings.getSetting( "firstrun" ) != "false":
print _name+": First run... showing settings dialog"
log( "First run... showing settings dialog" )
_settings.openSettings()
_settings.setSetting( "firstrun", "false" )

Expand Down Expand Up @@ -96,7 +98,7 @@ def __init__( self ):

#Proxy settings
if self.settings.getSetting( "proxy_enable" ) == "true":
print _name+": Proxy Enabled"
log( "Proxy Enabled" )
proxy_info = {
"host" : self.settings.getSetting( "proxy_server" ),
"port" : self.settings.getSetting( "proxy_port" ),
Expand Down Expand Up @@ -166,14 +168,14 @@ def getStations( self ):
return self.pandora.stations

def getMoreSongs( self ):
print _name+": getting more songs"
log( "getting more songs" )
if self.curStation == "":
raise PandaException()
items = []
station = self.pandora.get_station_by_id(self.curStation);
songs = station.get_playlist()
for song in songs:
print _name+": Adding song %s" % song.title
log( "Adding song %s" % song.title )
thumbnailArtwork = self.settings.getSetting( "thumbnailArtwork" )
thumbnail = song.artRadio

Expand All @@ -194,7 +196,7 @@ def getMoreSongs( self ):
if self.settings.getSetting( "scrobble_hack" ) == "true":
duration = 60 * ( int(self.settings.getSetting( "scrobble_hack_time" )) + 1 )
info["duration"] = duration
print _name+": item info = %s" % info
log( "item info = %s" % info )
item.setInfo( "music", info )
items.append( ( song.audioUrl, item, song ) )

Expand Down Expand Up @@ -227,7 +229,7 @@ def playNextSong( self ):
self.gui.getControl(BTN_THUMB_UP).setVisible(False)
self.gui.getControl(BTN_THUMBED_UP).setVisible(True)
else:
print _name+": !!!! Unrecognised rating"
log( "!!!! Unrecognised rating", xbmc.LOGWARNING )
except IndexError:
self.curSong = None
self.getMoreSongs()
Expand Down
2 changes: 1 addition & 1 deletion kb/ToDO.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@
* ? remove "Low" quality; currently, it looks like only "mediumQuality" and "highQuality" URLs are being sent for the song lists
- ! Pandora ONE == mediumQuality+ only -- missing 'lowQuality' in u'audioUrlMap'
- injected debug code into pithos/pandora/pandora.py @ Song.__init__()
print "pithos.pandora: song = %s" % d
log( "pithos.pandora: song = %s" % d )
27 changes: 18 additions & 9 deletions resources/lib/pandagui.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
import xbmc, xbmcgui

from threading import Timer
import xbmc
import xbmcaddon
import xbmcgui
import os, sys

_settings = xbmcaddon.Addon()
_name = _settings.getAddonInfo('name')
_version = _settings.getAddonInfo('version')
_path = xbmc.translatePath( _settings.getAddonInfo('path') ).decode('utf-8')
_lib = xbmc.translatePath( os.path.join( _path, 'resources', 'lib' ) )

sys.path.append (_lib)

from utils import *

_NAME = _name.upper()

Expand Down Expand Up @@ -40,7 +49,7 @@ def setPanda( self, panda ):
self.panda = panda

def onInit(self):
print _name+": Window Initalized!!!"
log( "Window Initalized" )
play_station_n = -1
last_station_id = self.panda.settings.getSetting('last_station_id')
auto_start = self.panda.settings.getSetting('auto_start')
Expand All @@ -53,7 +62,7 @@ def onInit(self):
for s in self.panda.getStations():
s.name = s.name.encode('utf-8')
s.id = s.id.encode('utf-8')
#print _name+": station[%s] = %s, %s" % ( s.name, s.id, s.isQuickMix )
#log( "station[%s] = %s, %s" % ( s.name, s.id, s.isQuickMix ), xbmc.LOGDEBUG )
if s.isQuickMix:
s.name = "* [ "+s.name+" ]"
tmp = xbmcgui.ListItem(s.name)
Expand All @@ -67,7 +76,7 @@ def onInit(self):
station_list.append( stations[name] )
if stations[name].getProperty('stationId') == last_station_id:
play_station_n = len(station_list) - 1
#print _name+": station_list[%s]{name, id} = {%s, %s}" % ( len(station_list)-1, station_list[len(station_list)-1].getLabel(), station_list[len(station_list)-1].getProperty('stationId'))
#log( "station_list[%s]{name, id} = {%s, %s}" % ( len(station_list)-1, station_list[len(station_list)-1].getLabel(), station_list[len(station_list)-1].getProperty('stationId')), xbmc.LOGDEBUG )
self.list.addItems( station_list )
dlg.close()
self.getControl(BTN_THUMBED_DN).setVisible(False)
Expand All @@ -82,9 +91,9 @@ def onInit(self):
dlg.update( 0 )
self.list.selectItem( play_station_n )
self.setFocusId( STATION_LIST_ID )
##print _name+": START: station_list[%s]{name, id} = {%s, %s}" % ( play_station_n, station_list[play_station_n].getLabel().encode('utf-8'), station_list[play_station_n].getProperty('stationId'))
##print _name+": START: station_list[%s]{name, id} = {%s, %s}" % ( play_station_n, self.list.getSelectedItem().getLabel().encode('utf-8'), self.list.getSelectedItem().getProperty('stationId'))
print _name+": START: station_id = %s" % last_station_id
##log( "START: station_list[%s]{name, id} = {%s, %s}" % ( play_station_n, station_list[play_station_n].getLabel().encode('utf-8'), station_list[play_station_n].getProperty('stationId')), xbmc.LOGDEBUG )
##log( "START: station_list[%s]{name, id} = {%s, %s}" % ( play_station_n, self.list.getSelectedItem().getLabel().encode('utf-8'), self.list.getSelectedItem().getProperty('stationId')), xbmc.LOGDEBUG )
log( "START: station_id = %s" % last_station_id )
self.panda.playStation( last_station_id )
dlg.close

Expand Down Expand Up @@ -129,7 +138,7 @@ def onClick(self, controlID):
elif controlID == BTN_TIRED:
#obj = self.getControl(BTN_TIRED)
#for attr in dir(obj):
# print _name+": >>> obj.%s = %s" % (attr, getattr(obj, attr))
# log( ">>> obj.%s = %s" % (attr, getattr(obj, attr)), xbmc.LOGDEBUG )
self.panda.addTiredSong()
self.panda.playNextSong()
elif controlID == BTN_HIDE:
Expand Down
25 changes: 16 additions & 9 deletions resources/lib/pandaplayer.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
import xbmc
from threading import Timer

import xbmc
import xbmcaddon
import os, sys

_settings = xbmcaddon.Addon()
_name = _settings.getAddonInfo('name')
_version = _settings.getAddonInfo('version')
_path = xbmc.translatePath( _settings.getAddonInfo('path') ).decode('utf-8')
_lib = xbmc.translatePath( os.path.join( _path, 'resources', 'lib' ) )

sys.path.append (_lib)

from utils import *

_NAME = _name.upper()

Expand All @@ -17,8 +24,8 @@ def __init__( self, core=None, panda=None ):
self.playNextSong_delay = 0.5

def playSong( self, item ):
print _name+": playSong: item[url] %s" % item[0]
print _name+": playSong: item[item] %s" % item[1]
log( "playSong: item[url] %s" % item[0], xbmc.LOGDEBUG )
log( "playSong: item[item] %s" % item[1], xbmc.LOGDEBUG )
self.play( item[0], item[1] )

def play( self, url, item ):
Expand All @@ -31,7 +38,7 @@ def play( self, url, item ):
# ToDO: discuss with the XBMC Team what the solution to this problem would be

def onPlayBackStarted( self ):
print _name+": onPlayBackStarted: %s" %self.getPlayingFile()
log( "onPlayBackStarted: %s" %self.getPlayingFile(), xbmc.LOGDEBUG )
if self.panda.playing:
# ToDO: ? remove checks for pandora.com / p-cdn.com (are they needed? could be a maintainence headache if the cdn changes...)
if not "pandora.com" in self.getPlayingFile():
Expand All @@ -43,9 +50,9 @@ def onPlayBackStarted( self ):
xbmc.executebuiltin( "ActivateWindow( 12006 )" )

def onPlayBackEnded( self ):
print _name+": onPlayBackEnded"
log( "onPlayBackEnded", xbmc.LOGDEBUG )
self.stop()
print _name+": playing = %s" %self.panda.playing
log( "playing = %s" %self.panda.playing, xbmc.LOGDEBUG )
if self.timer and self.timer.isAlive():
self.timer.cancel()
if self.panda.skip:
Expand All @@ -55,9 +62,9 @@ def onPlayBackEnded( self ):
self.timer.start()

def onPlayBackStopped( self ):
print _name+": onPlayBackStopped"
log( "onPlayBackStopped", xbmc.LOGDEBUG )
self.stop()
print _name+": playing = %s" %self.panda.playing
log( "playing = %s" %self.panda.playing, xbmc.LOGDEBUG )
if self.timer and self.timer.isAlive():
self.timer.cancel()
if self.panda.playing and self.panda.skip:
Expand Down
15 changes: 15 additions & 0 deletions resources/lib/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import xbmc
import xbmcaddon
import os, sys

_settings = xbmcaddon.Addon()
_name = _settings.getAddonInfo('name')

def log ( msg, log_level=xbmc.LOGNOTICE ):
# URLref: http://farmdev.com/talks/unicode , http://stackoverflow.com/a/11339995/43774
if isinstance( msg, basestring ):
if not isinstance( msg, unicode ):
# [str -> unicode] == msg.decode('utf-8')
msg = unicode( msg, 'utf-8' )
message = u'%s: %s' % (_name, msg)
xbmc.log(msg=message.encode("utf-8"), level=log_level)

0 comments on commit a74cc77

Please sign in to comment.