class GrooveClass(object):
    #INIT FUNCTIONS
    def __init__(self):
        mc.ShowDialogWait()
        self.useCoverArt = True
        self.player = mc.GetPlayer()
        self.defaultCoverArt = 'default-cover.png'
        self.xbmcPlaylist = mc.PlayList(mc.PlayList.PLAYLIST_MUSIC)
        self.gs = GrooveAPI(enableDebug = __debugging__, cwd = __cwd__ ,clientUuid = None, clientVersion = None)
        username = __settings__.GetValue("username")
        password = __settings__.GetValue("password")
        self.gs.startSession(username, password)
        self.gs.setRemoveDuplicates(True)
        self._search = None

        self.start()
        mc.HideDialogWait()

    def start(self):
        try:
            searchLabel = 'Found ' + str(self._search.countResults()) + ' for "' + self._search.queryText + '"'
        except:
            searchLabel = 'Start a new search in the menu'
            traceback.print_exc()
        dict = [\
                {'label':__language__(128), 'label2':searchLabel, 'thumbnail':'gs_search.png', 'action':'searchshow'},\
                {'label':__language__(108), 'label2':__language__(3041), 'thumbnail':'gs_popular.png', 'action':'popular'},\
                {'label':__language__(129), 'label2':'Your favorites', 'thumbnail':'gs_favorites.png', 'action':'favorites'},\
                {'label':__language__(117), 'label2':__language__(3039), 'thumbnail':'gs_playlist.png', 'action':'playlist'},\
                {'label':__language__(107), 'label2':'Have a look at the tunes you\'re playing', 'thumbnail':'gs_song.png', 'action':'playing'}\
              ]
        listItems = mc.ListItems()
        for item in dict:
            listItem = createItem(item)
            listItems.append(listItem)
        __windowlist__.SetItems(listItems)

    def windowCheck(self):
        try:
            mc.GetActiveWindow().GetList(50)
            return False
        except: return True
    #NAV FUNCTIONS
    def action(self, id, list):
        mc.ShowDialogWait()
        listitems = __window__.GetList(list).GetItems()
        action = listitems[id].GetProperty('action')
        action_id = id
        
        handle_id = __windowlist__.GetFocusedItem()
        listItems = __windowlist__.GetItems()
        try: handle = pickle.loads(listItems[handle_id].GetProperty('handle'))
        except: handle = ''
        
        if list == 500:
            __window__.GetControl(50).SetFocus()
            __windowlist__.SetFocusedItem(handle_id)

        print 'Grooveshark::Navigation: '+action
        self.setStateLabel(action.upper())
        __window__.GetControl(300011).SetVisible(False)

        #MAIN MENU
        if action == 'searchshow':
            self.searchshow()
        elif action == 'popular':
            mc.GetActiveWindow().ClearStateStack(True)
            mc.GetActiveWindow().PushState()
            api = GS_PopularSongs()
            data = api._getPopular(self.gs)
            songs = Songs(data, defaultCoverArt = self.defaultCoverArt)
            [obj, listItems] = songs._list(self, self.gs)
            __windowlist__.SetItems(listItems)
        elif action == 'favorites':
            try:
                mc.GetActiveWindow().ClearStateStack(True)
                mc.GetActiveWindow().PushState()
                api = Favorites(gui = self, gsapi = self.gs, defaultCoverArt = self.defaultCoverArt)
                [obj, listItems] = api._list(self, self.gs)
                __windowlist__.SetItems(listItems)
            except:
                mc.HideDialogWait()
                self.notification(__language__(3027)) #checkpass
                mc.GetActiveWindow().ClearStateStack(True)
                return
        elif action == 'playlist':
            try:
                mc.GetActiveWindow().ClearStateStack(True)
                mc.GetActiveWindow().PushState()
                api = Playlists(gui = self, defaultCoverArt = self.defaultCoverArt)
                [obj, listItems] = api._list(self, self.gs)
                __windowlist__.SetItems(listItems)
            except:
                mc.HideDialogWait()
                self.notification(__language__(3027)) #checkpass
                mc.GetActiveWindow().ClearStateStack(True)
                return
        elif action == 'playing':
            mc.GetActiveWindow().ClearStateStack(True)
            mc.GetActiveWindow().PushState()
            obj, listItems = self.NowPlaying()
            __windowlist__.SetItems(listItems)

        #LEFTMENU
        elif action == 'search':
            self.search()

        elif action == 'settings':
            print 'settings called'
            mc.ActivateWindow(16000)

        elif action == 'exit':
            mc.GetApp().Close()

        #RIGHTMENU
        #navigate down
        elif action == 'down':
            obj = handle.get(action_id)
            mc.GetActiveWindow().PushState()
            [obj, listItems] = obj._list(self, self.gs)
            __windowlist__.SetItems(listItems)

        elif action == 'addSongToPlaylistExec':
            [playlist, song] = pickle.loads(listitems[action_id].GetProperty('handle'))
            self.addSongToPlaylistExec(playlist, song)


        #Song Parameters
        elif action == 'play':
            handle.play(handle_id, self.gs)
        elif action == 'queueSong':
            self.queueSong(handle_id, handle)
        elif action == 'queueAllSongs':
            self.queueAllSongs(handle)
        elif action == 'addSongToPlaylist':
            self.addSongToPlaylist(handle_id, handle)
        elif action == 'findSimilarFromSong':
            self.findSimilarFromSong(handle_id, handle)
        elif action == 'songsOnAlbum':
            self.songsOnAlbum(handle_id, handle)

        #album
        elif action == 'playAlbum':
            self.playAlbum(handle_id, handle)
        elif action == 'queueAlbum':
            self.queueAlbum(handle_id, handle)
        elif action == 'saveAlbumAsPlaylist':
            self.saveAlbumAsPlaylist(handle_id, handle)
        elif action == 'findSimilarFromAlbum':
            self.findSimilarFromAlbum(handle_id, handle)

        #PLaylist
        elif action == 'renamePlaylist':
            self.renamePlaylist(handle_id, handle)
        elif action == 'deletePlaylist':
            self.deletePlaylist(handle_id, handle)

        #Artist
        elif action == 'playSongsByArtist':
            self.playSongsByArtist(handle_id, handle)
        elif action == 'findSimilarFromArtist':
            self.findSimilarFromArtist(handle_id, handle)

        mc.HideDialogWait()

    def search(self):
        setMain()
        result = mc.ShowDialogKeyboard(__language__(1000), "", False)
        if len(result) > 0:
            try:
                self._search = Search(self, defaultCoverArt = self.defaultCoverArt)
                self._search.search(self.gs, result)
                self.start()
                self.searchshow()
            except:
                self.notification('Sorry')
                traceback.print_exc()

    def searchshow(self):
        if int(self._search.countResults()) > 0:
            mc.GetActiveWindow().ClearStateStack(True)
            mc.GetActiveWindow().PushState()
            [obj, listItems] = self._search._list(self, self.gs)
            __windowlist__.SetItems(listItems)

    def queueSong(self, selected, obj = None):
	try:
            song = obj.get(selected)
            obj.queue(self.gs, song, playlist = self.xbmcPlaylist)
            checkPlayback(self.xbmcPlaylist)
            self.notification('Queued')
	except:
            self.notification('Sorry')
            traceback.print_exc()

    def queueAllSongs(self, obj = None):
	try:
            obj.queueAll(self.gs, playlist = self.xbmcPlaylist, append = True)
            checkPlayback(self.xbmcPlaylist)
            self.notification('Queued')
	except:
            self.notification('Sorry')

    def playAlbum(self, selected = 0, obj = None):
	try:
            album = obj.get(selected)
            songs = album.getSongs(self.gs)
            songs.queueAll(playlist = self.xbmcPlaylist, append = False)
            checkPlayback(self.xbmcPlaylist)
	except:
            traceback.print_exc()
            self.notification('Sorry')

    def queueAlbum(self, selected = 0, obj = None):
    	try:
            album = obj.get(selected)
            songs = album.getSongs(self.gs)
            songs.queueAll(playlist = self.xbmcPlaylist, append = True)
            checkPlayback(self.xbmcPlaylist)
            self.notification('Queued')
	except:
            self.notification('Sorry')

    def playSongsByArtist(self, selected = 0, obj = None):
	try:
            artist = obj.get(selected)
            songs = artist.getSongs(self.gs)
            songs.play(selected = 0, gsapi = self.gs, playlist = self.xbmcPlaylist)
	except:
            self.notification('Sorry')

    def findSimilarFromSong(self, selected = 0, obj = None):
        try:
            song = obj.get(selected)
            artist = Artist(song.artistID)
            artists = artist.similar(gsapi = self.gs)
            mc.GetActiveWindow().PushState()
            [obj, listItems] = artists._list(self, self.gs)
            __windowlist__.SetItems(listItems)
	except:
            self.notification('Sorry')

    def songsOnAlbum(self, selected = 0, obj = None):
        try:
            song = obj.get(selected)
            albumId = song.albumID
            songs = Album(albumId, defaultCoverArt = self.defaultCoverArt).getSongs(gsapi = self.gs)
            mc.GetActiveWindow().PushState()
            [obj, listItems] = songs._list(self, self.gs)
            __windowlist__.SetItems(listItems)

        except:
            self.notification('Sorry')

    def findSimilarFromAlbum(self, selected = 0, obj = None):
        try:
            album = obj.get(selected)
            artist = Artist(album.artistID)
            artists = artist.similar(gsapi = self.gs)
            mc.GetActiveWindow().PushState()
            [obj, listItems] = artists._list(self, self.gs)
            __windowlist__.SetItems(listItems)
	except:
            self.notification('Sorry')

    def findSimilarFromArtist(self, selected = 0, obj = None):
	try:
            artist = obj.get(selected)
            artists = artist.similar(gsapi = self.gs)
            mc.GetActiveWindow().PushState()
            [obj, listItems] = artists._list(self, self.gs)
            __windowlist__.SetItems(listItems)
	except:
            self.notification('Sorry')

    def addSongToPlaylist(self, selected = 0, obj = None):
        try:
            song = obj.get(selected)
            setOptionsPlaylists(self, song)
	except:
            self.notification('Sorry')
            traceback.print_exc()

    def addSongToPlaylistExec(self, playlist = None, song = None):
	playlist.getSongs(self.gs)
	playlist.addSong(song)
	playlist.save(self.gs)
	self.notification('Added')

    def saveAlbumAsPlaylist(self, selected = 0, obj = None):
	album = obj.get(selected)
	name = album.artistName + ' - ' + album.name
	name = self.getInput('Name for playlist', default=name)
	if name == None:
            return
        if name != '':
            try:
                songs = album.getSongs(self.gs)
		info = {'Name': name, 'PlaylistID': -1, 'About': ''}
		Playlist(info, songs = songs).saveAs(self.gs)
		self.notification('Saved')
            except:
                self.notification('Sorry')
	else:
            self.notification('Type a name')

    def deletePlaylist(self, selected = 0, obj = None):
	try:
            playlist = obj.get(selected)
            playlist.delete(self.gs)
            api = Playlists(gui = self, defaultCoverArt = self.defaultCoverArt)
            [obj, listItems] = api._list(self, self.gs)
            __windowlist__.SetItems(listItems)
            self.notification('Deleted')
	except:
            self.notification('Sorry')

    def renamePlaylist(self, selected = 0, obj = None):
	playlist = obj.get(selected)
	name = self.getInput(__language__(111), default=playlist.name)
	if name != '' and name != None:
            try:
                playlist.rename(self.gs, name)
                api = Playlists(gui = self, defaultCoverArt = self.defaultCoverArt)
                [obj, listItems] = api._list(self, self.gs)
                __windowlist__.SetItems(listItems)
		self.notification('Renamed')
            except:
		self.notification('Sorry')




    #GUI Functions
    def notification(self, message):
        cnt = __window__.GetControl(7001)
	label = __window__.GetLabel(7003)
        label.SetLabel(message)
	cnt.SetFocus()
	xbmc.sleep(100)
	setMain()

    def setStateLabel(self, msg):
	__window__.GetLabel(3000).SetLabel(msg)

    def setInfoLabel(self, msg):
	cnt = __window__.GetLabel(300011)
	cnt.SetLabel(msg)
	__window__.GetControl(300011).SetVisible(True)

    def getInput(self, title, default="", hidden=False):
	response  = mc.ShowDialogKeyboard(str(title), str(default), hidden)
	if response != '':
            return response
	else:
            return None



    #OTHER FUNCTIONS
    def NowPlaying(self):
	playlist = mc.PlayList(mc.PlayList.PLAYLIST_MUSIC)
	n = playlist.Size()
	data = []
	songs = []
	for i in range(n):
            song = playlist.GetItem(i)
            name = song.GetProperty('info')
            if 'play?' in name:
                name = name.split('?')[1]
                parts = name.split('&')
                songId = parts[0].split('=')[1]
                artistId = parts[1].split('=')[1]
                albumId = parts[2].split('=')[1]
                image = decode(parts[3].split('=')[1])
                songName = decode(parts[4].split('=')[1])
                artistName = decode(parts[5].split('=')[1])
                albumName = decode(parts[6].split('=')[1])
                options = parts[7].split('=')[1]
                item = {'SongID': songId, 'Name': songName, 'AlbumName':albumName, 'ArtistName':artistName, 'ArtistID':artistId, 'AlbumID':albumId, 'ArtistID':artistId, 'CoverArt':image}
                data.append(item)
            else: print 'Song passed'
	songs = Songs(data, defaultCoverArt = self.defaultCoverArt)
	return songs._list(self, self.gs)
Esempio n. 2
0
__parameters__ = mc.GetApp().GetLaunchedScriptParameters()
sys.path.append(os.path.join(__cwd__, 'libs'))


print 'GrooveShark: play script started'

org_url = ''
for i in sys.argv:
    org_url += str(i).replace('.py','?')
for var in __parameters__.keys():
    vars()[var] = __parameters__[var]

from GrooveAPI import *
try:
    gs = GrooveAPI(enableDebug = __debugging__, cwd = __cwd__,clientUuid = None, clientVersion = None)
    gs.startSession('','')

    if (playSong != None):
        print 'GrooveShark: Song ID: ' + str(playSong)
        url = gs.getStreamURL(str(playSong))
        if url != "":
            listItem = mc.ListItem(mc.ListItem.MEDIA_AUDIO_MUSIC)
            listItem.SetPath(str(url))
            listItem.SetProperty('info', str(org_url))
            listItem.SetContentType('audio/mpeg')
            listItem.SetTitle(songName)
            listItem.SetThumbnail(image)
            listItem.SetIcon(image)
            listItem.SetAlbum(albumName)
            listItem.SetArtist(artistName)
Esempio n. 3
0
class GrooveClass(object):
    #INIT FUNCTIONS
    def __init__(self):
        mc.ShowDialogWait()
        self.useCoverArt = True
        self.player = mc.GetPlayer()
        self.defaultCoverArt = 'default-cover.png'
        self.xbmcPlaylist = mc.PlayList(mc.PlayList.PLAYLIST_MUSIC)
        self.gs = GrooveAPI(enableDebug=__debugging__,
                            cwd=__cwd__,
                            clientUuid=None,
                            clientVersion=None)
        username = __settings__.GetValue("username")
        password = __settings__.GetValue("password")
        self.gs.startSession(username, password)
        self.gs.setRemoveDuplicates(True)
        self._search = None

        self.start()
        mc.HideDialogWait()

    def start(self):
        try:
            searchLabel = 'Found ' + str(self._search.countResults(
            )) + ' for "' + self._search.queryText + '"'
        except:
            searchLabel = 'Start a new search in the menu'
            traceback.print_exc()
        dict = [\
                {'label':__language__(128), 'label2':searchLabel, 'thumbnail':'gs_search.png', 'action':'searchshow'},\
                {'label':__language__(108), 'label2':__language__(3041), 'thumbnail':'gs_popular.png', 'action':'popular'},\
                {'label':__language__(129), 'label2':'Your favorites', 'thumbnail':'gs_favorites.png', 'action':'favorites'},\
                {'label':__language__(117), 'label2':__language__(3039), 'thumbnail':'gs_playlist.png', 'action':'playlist'},\
                {'label':__language__(107), 'label2':'Have a look at the tunes you\'re playing', 'thumbnail':'gs_song.png', 'action':'playing'}\
              ]
        listItems = mc.ListItems()
        for item in dict:
            listItem = createItem(item)
            listItems.append(listItem)
        __windowlist__.SetItems(listItems)

    def windowCheck(self):
        try:
            mc.GetActiveWindow().GetList(50)
            return False
        except:
            return True

    #NAV FUNCTIONS
    def action(self, id, list):
        mc.ShowDialogWait()
        listitems = __window__.GetList(list).GetItems()
        action = listitems[id].GetProperty('action')
        action_id = id

        handle_id = __windowlist__.GetFocusedItem()
        listItems = __windowlist__.GetItems()
        try:
            handle = pickle.loads(listItems[handle_id].GetProperty('handle'))
        except:
            handle = ''

        if list == 500:
            __window__.GetControl(50).SetFocus()
            __windowlist__.SetFocusedItem(handle_id)

        print 'Grooveshark::Navigation: ' + action
        self.setStateLabel(action.upper())
        __window__.GetControl(300011).SetVisible(False)

        #MAIN MENU
        if action == 'searchshow':
            self.searchshow()
        elif action == 'popular':
            mc.GetActiveWindow().ClearStateStack(True)
            mc.GetActiveWindow().PushState()
            api = GS_PopularSongs()
            data = api._getPopular(self.gs)
            songs = Songs(data, defaultCoverArt=self.defaultCoverArt)
            [obj, listItems] = songs._list(self, self.gs)
            __windowlist__.SetItems(listItems)
        elif action == 'favorites':
            try:
                mc.GetActiveWindow().ClearStateStack(True)
                mc.GetActiveWindow().PushState()
                api = Favorites(gui=self,
                                gsapi=self.gs,
                                defaultCoverArt=self.defaultCoverArt)
                [obj, listItems] = api._list(self, self.gs)
                __windowlist__.SetItems(listItems)
            except:
                mc.HideDialogWait()
                self.notification(__language__(3027))  #checkpass
                mc.GetActiveWindow().ClearStateStack(True)
                return
        elif action == 'playlist':
            try:
                mc.GetActiveWindow().ClearStateStack(True)
                mc.GetActiveWindow().PushState()
                api = Playlists(gui=self, defaultCoverArt=self.defaultCoverArt)
                [obj, listItems] = api._list(self, self.gs)
                __windowlist__.SetItems(listItems)
            except:
                mc.HideDialogWait()
                self.notification(__language__(3027))  #checkpass
                mc.GetActiveWindow().ClearStateStack(True)
                return
        elif action == 'playing':
            mc.GetActiveWindow().ClearStateStack(True)
            mc.GetActiveWindow().PushState()
            obj, listItems = self.NowPlaying()
            __windowlist__.SetItems(listItems)

        #LEFTMENU
        elif action == 'search':
            self.search()

        elif action == 'settings':
            print 'settings called'
            mc.ActivateWindow(16000)

        elif action == 'exit':
            mc.GetApp().Close()

        #RIGHTMENU
        #navigate down
        elif action == 'down':
            obj = handle.get(action_id)
            mc.GetActiveWindow().PushState()
            [obj, listItems] = obj._list(self, self.gs)
            __windowlist__.SetItems(listItems)

        elif action == 'addSongToPlaylistExec':
            [playlist,
             song] = pickle.loads(listitems[action_id].GetProperty('handle'))
            self.addSongToPlaylistExec(playlist, song)

        #Song Parameters
        elif action == 'play':
            handle.play(handle_id, self.gs)
        elif action == 'queueSong':
            self.queueSong(handle_id, handle)
        elif action == 'queueAllSongs':
            self.queueAllSongs(handle)
        elif action == 'addSongToPlaylist':
            self.addSongToPlaylist(handle_id, handle)
        elif action == 'findSimilarFromSong':
            self.findSimilarFromSong(handle_id, handle)
        elif action == 'songsOnAlbum':
            self.songsOnAlbum(handle_id, handle)

        #album
        elif action == 'playAlbum':
            self.playAlbum(handle_id, handle)
        elif action == 'queueAlbum':
            self.queueAlbum(handle_id, handle)
        elif action == 'saveAlbumAsPlaylist':
            self.saveAlbumAsPlaylist(handle_id, handle)
        elif action == 'findSimilarFromAlbum':
            self.findSimilarFromAlbum(handle_id, handle)

        #PLaylist
        elif action == 'renamePlaylist':
            self.renamePlaylist(handle_id, handle)
        elif action == 'deletePlaylist':
            self.deletePlaylist(handle_id, handle)

        #Artist
        elif action == 'playSongsByArtist':
            self.playSongsByArtist(handle_id, handle)
        elif action == 'findSimilarFromArtist':
            self.findSimilarFromArtist(handle_id, handle)

        mc.HideDialogWait()

    def search(self):
        setMain()
        result = mc.ShowDialogKeyboard(__language__(1000), "", False)
        if len(result) > 0:
            try:
                self._search = Search(self,
                                      defaultCoverArt=self.defaultCoverArt)
                self._search.search(self.gs, result)
                self.start()
                self.searchshow()
            except:
                self.notification('Sorry')
                traceback.print_exc()

    def searchshow(self):
        if int(self._search.countResults()) > 0:
            mc.GetActiveWindow().ClearStateStack(True)
            mc.GetActiveWindow().PushState()
            [obj, listItems] = self._search._list(self, self.gs)
            __windowlist__.SetItems(listItems)

    def queueSong(self, selected, obj=None):
        try:
            song = obj.get(selected)
            obj.queue(self.gs, song, playlist=self.xbmcPlaylist)
            checkPlayback(self.xbmcPlaylist)
            self.notification('Queued')
        except:
            self.notification('Sorry')
            traceback.print_exc()

    def queueAllSongs(self, obj=None):
        try:
            obj.queueAll(self.gs, playlist=self.xbmcPlaylist, append=True)
            checkPlayback(self.xbmcPlaylist)
            self.notification('Queued')
        except:
            self.notification('Sorry')

    def playAlbum(self, selected=0, obj=None):
        try:
            album = obj.get(selected)
            songs = album.getSongs(self.gs)
            songs.queueAll(playlist=self.xbmcPlaylist, append=False)
            checkPlayback(self.xbmcPlaylist)
        except:
            traceback.print_exc()
            self.notification('Sorry')

    def queueAlbum(self, selected=0, obj=None):
        try:
            album = obj.get(selected)
            songs = album.getSongs(self.gs)
            songs.queueAll(playlist=self.xbmcPlaylist, append=True)
            checkPlayback(self.xbmcPlaylist)
            self.notification('Queued')
        except:
            self.notification('Sorry')

    def playSongsByArtist(self, selected=0, obj=None):
        try:
            artist = obj.get(selected)
            songs = artist.getSongs(self.gs)
            songs.play(selected=0, gsapi=self.gs, playlist=self.xbmcPlaylist)
        except:
            self.notification('Sorry')

    def findSimilarFromSong(self, selected=0, obj=None):
        try:
            song = obj.get(selected)
            artist = Artist(song.artistID)
            artists = artist.similar(gsapi=self.gs)
            mc.GetActiveWindow().PushState()
            [obj, listItems] = artists._list(self, self.gs)
            __windowlist__.SetItems(listItems)
        except:
            self.notification('Sorry')

    def songsOnAlbum(self, selected=0, obj=None):
        try:
            song = obj.get(selected)
            albumId = song.albumID
            songs = Album(
                albumId,
                defaultCoverArt=self.defaultCoverArt).getSongs(gsapi=self.gs)
            mc.GetActiveWindow().PushState()
            [obj, listItems] = songs._list(self, self.gs)
            __windowlist__.SetItems(listItems)

        except:
            self.notification('Sorry')

    def findSimilarFromAlbum(self, selected=0, obj=None):
        try:
            album = obj.get(selected)
            artist = Artist(album.artistID)
            artists = artist.similar(gsapi=self.gs)
            mc.GetActiveWindow().PushState()
            [obj, listItems] = artists._list(self, self.gs)
            __windowlist__.SetItems(listItems)
        except:
            self.notification('Sorry')

    def findSimilarFromArtist(self, selected=0, obj=None):
        try:
            artist = obj.get(selected)
            artists = artist.similar(gsapi=self.gs)
            mc.GetActiveWindow().PushState()
            [obj, listItems] = artists._list(self, self.gs)
            __windowlist__.SetItems(listItems)
        except:
            self.notification('Sorry')

    def addSongToPlaylist(self, selected=0, obj=None):
        try:
            song = obj.get(selected)
            setOptionsPlaylists(self, song)
        except:
            self.notification('Sorry')
            traceback.print_exc()

    def addSongToPlaylistExec(self, playlist=None, song=None):
        playlist.getSongs(self.gs)
        playlist.addSong(song)
        playlist.save(self.gs)
        self.notification('Added')

    def saveAlbumAsPlaylist(self, selected=0, obj=None):
        album = obj.get(selected)
        name = album.artistName + ' - ' + album.name
        name = self.getInput('Name for playlist', default=name)
        if name == None:
            return
        if name != '':
            try:
                songs = album.getSongs(self.gs)
                info = {'Name': name, 'PlaylistID': -1, 'About': ''}
                Playlist(info, songs=songs).saveAs(self.gs)
                self.notification('Saved')
            except:
                self.notification('Sorry')
        else:
            self.notification('Type a name')

    def deletePlaylist(self, selected=0, obj=None):
        try:
            playlist = obj.get(selected)
            playlist.delete(self.gs)
            api = Playlists(gui=self, defaultCoverArt=self.defaultCoverArt)
            [obj, listItems] = api._list(self, self.gs)
            __windowlist__.SetItems(listItems)
            self.notification('Deleted')
        except:
            self.notification('Sorry')

    def renamePlaylist(self, selected=0, obj=None):
        playlist = obj.get(selected)
        name = self.getInput(__language__(111), default=playlist.name)
        if name != '' and name != None:
            try:
                playlist.rename(self.gs, name)
                api = Playlists(gui=self, defaultCoverArt=self.defaultCoverArt)
                [obj, listItems] = api._list(self, self.gs)
                __windowlist__.SetItems(listItems)
                self.notification('Renamed')
            except:
                self.notification('Sorry')

    #GUI Functions
    def notification(self, message):
        cnt = __window__.GetControl(7001)
        label = __window__.GetLabel(7003)
        label.SetLabel(message)
        cnt.SetFocus()
        xbmc.sleep(100)
        setMain()

    def setStateLabel(self, msg):
        __window__.GetLabel(3000).SetLabel(msg)

    def setInfoLabel(self, msg):
        cnt = __window__.GetLabel(300011)
        cnt.SetLabel(msg)
        __window__.GetControl(300011).SetVisible(True)

    def getInput(self, title, default="", hidden=False):
        response = mc.ShowDialogKeyboard(str(title), str(default), hidden)
        if response != '':
            return response
        else:
            return None

    #OTHER FUNCTIONS
    def NowPlaying(self):
        playlist = mc.PlayList(mc.PlayList.PLAYLIST_MUSIC)
        n = playlist.Size()
        data = []
        songs = []
        for i in range(n):
            song = playlist.GetItem(i)
            name = song.GetProperty('info')
            if 'play?' in name:
                name = name.split('?')[1]
                parts = name.split('&')
                songId = parts[0].split('=')[1]
                artistId = parts[1].split('=')[1]
                albumId = parts[2].split('=')[1]
                image = decode(parts[3].split('=')[1])
                songName = decode(parts[4].split('=')[1])
                artistName = decode(parts[5].split('=')[1])
                albumName = decode(parts[6].split('=')[1])
                options = parts[7].split('=')[1]
                item = {
                    'SongID': songId,
                    'Name': songName,
                    'AlbumName': albumName,
                    'ArtistName': artistName,
                    'ArtistID': artistId,
                    'AlbumID': albumId,
                    'ArtistID': artistId,
                    'CoverArt': image
                }
                data.append(item)
            else:
                print 'Song passed'
        songs = Songs(data, defaultCoverArt=self.defaultCoverArt)
        return songs._list(self, self.gs)