コード例 #1
0
def modifyServer():
    jsStorServer = json_storage.JsonStorage("servers.json")
    serverData = jsStorServer.getData()
    i = serversDialog(serverData, 'Modify a server')
    if i == False:
        return
    while True:
        key = showServerData(serverData["servers"][i])
        print key
        if key == False:
            break
        elif key == "use_api_key":
            dialog = xbmcgui.Dialog()
            value_int = dialog.yesno('Use api Key?',
                                     'Do you want to use an api-key?')
            value = utils.int_to_strBool(value_int)
        elif key == "enable_password":
            dialog = xbmcgui.Dialog()
            value_int = dialog.yesno('Use password?',
                                     'The server needs a password?')
            value = utils.int_to_strBool(value_int)
        else:
            value = gui.getFilterFromUser(key)
        if value <> False:
            serverData["servers"][i][key] = value
    xbmc.executebuiltin("PlayerControl(Stop)")
    jsStorServer.save(serverData)
    #just to be sure, having potentially changed default server
    try:
        ampacheConnect = ampache_connect.AmpacheConnect()
        ampacheConnect.AMPACHECONNECT()
    except:
        pass
コード例 #2
0
def switchServer():
    jsStorServer = json_storage.JsonStorage("servers.json")
    serverData = jsStorServer.getData()
    i_curr = serversDialog(serverData, 'Choose a default server')
    if i_curr == False:
        return
    xbmc.executebuiltin("PlayerControl(Stop)")
    serverData["current_server"] = i_curr
    jsStorServer.save(serverData)
    #if we switch, reconnect
    try:
        ampacheConnect = ampache_connect.AmpacheConnect()
        ampacheConnect.AMPACHECONNECT()
    except:
        pass
コード例 #3
0
def play_track(song_url):
    #check if the connection is expired, initialise the connect class only if
    #refresh is needed to speed up the play
    if utils.check_tokenexp():
        ampConn = ampache_connect.AmpacheConnect()
        xbmc.log("refreshing token...", xbmc.LOGNOTICE)
        try:
            #elem non used
            elem = ampConn.AMPACHECONNECT()
        except:
            return
    liz = xbmcgui.ListItem()
    liz.setPath(song_url)
    xbmcplugin.setResolvedUrl(handle=int(sys.argv[1]),
                              succeeded=True,
                              listitem=liz)
コード例 #4
0
def play_track(object_id, song_url):
    if song_url == None or object_id == None:
        xbmc.log("AmpachePlugin::play_track object or song null",
                 xbmc.LOGNOTICE)
        return

    old_object_id = None

    #check if we need the song infolabels ( object_id cached is different from
    #object_id of the song, for instance as kore app call the song
    try:
        plugin_url = xbmc.getInfoLabel('ListItem.FileNameAndPath')
        params = ut.get_params(plugin_url)
        old_object_id = int(params["object_id"])
        xbmc.log(
            "AmpachePlugin::play_track old_object_id " + str(old_object_id),
            xbmc.LOGDEBUG)
    except:
        pass

    liz = xbmcgui.ListItem()
    try:
        if old_object_id == None or old_object_id != object_id:
            ampConn = ampache_connect.AmpacheConnect()
            xbmc.log("AmpachePlugin::play_track refresh infoLabels",
                     xbmc.LOGDEBUG)
            ampConn.filter = object_id
            elem = ampConn.ampache_http_request("song")
            for thisnode in elem:
                node = thisnode
            fillListItemWithSongInfo(liz, node)
            liz.setProperty("IsPlayable", "true")
    except:
        pass

    liz.setPath(song_url)
    #rating = xbmc.getInfoLabel('ListItem.UserRating')
    xbmcplugin.setResolvedUrl(handle=int(sys.argv[1]),
                              succeeded=True,
                              listitem=liz)
コード例 #5
0
def get_stats(object_type, object_subtype=None, limit=5000):

    ampConn = ampache_connect.AmpacheConnect()

    xbmc.log("AmpachePlugin::get_stats ", xbmc.LOGDEBUG)
    mode = None
    if object_type == 'artists':
        mode = 2
    elif object_type == 'albums':
        mode = 3

    xbmcplugin.setContent(int(sys.argv[1]), object_type)

    action = 'stats'
    if (ampache.getSetting("api-version")) < 400001:
        amtype = object_subtype
        thisFilter = None
    else:
        if object_type == 'albums':
            amtype = 'album'
        elif object_type == 'artists':
            amtype = 'artist'
        elif object_type == 'songs':
            amtype = 'song'
        thisFilter = object_subtype

    try:
        ampConn.filter = thisFilter
        ampConn.limit = limit
        ampConn.type = amtype

        elem = ampConn.ampache_http_request(action)
    except:
        return

    addItem(object_type, mode, elem)
コード例 #6
0
def cacheArt(url):
    ampacheConnect = ampache_connect.AmpacheConnect()
    strippedAuth = url.split('&')
    imageID = re.search(r"id=(\d+)", strippedAuth[0])
    #security check:
    #also nexcloud server doesn't send images
    if imageID == None:
        raise NameError

    imageNamePng = imageID.group(1) + ".png"
    imageNameJpg = imageID.group(1) + ".jpg"
    pathPng = os.path.join(cacheDir, imageNamePng)
    pathJpg = os.path.join(cacheDir, imageNameJpg)
    if os.path.exists(pathPng):
        #xbmc.log("AmpachePlugin::CacheArt: png cached",xbmc.LOGDEBUG)
        return pathPng
    elif os.path.exists(pathJpg):
        #xbmc.log("AmpachePlugin::CacheArt: jpg cached",xbmc.LOGDEBUG)
        return pathJpg
    else:
        #xbmc.log("AmpachePlugin::CacheArt: File needs fetching ",xbmc.LOGDEBUG)
        headers, contents = ampacheConnect.handle_request(url)
        if headers.maintype == 'image':
            extension = headers['content-type']
            tmpExt = extension.split("/")
            if tmpExt[1] == "jpeg":
                fname = imageNameJpg
            else:
                fname = imageID.group(1) + '.' + tmpExt[1]
            pathJpg = os.path.join(cacheDir, fname)
            open(pathJpg, 'wb').write(contents)
            #xbmc.log("AmpachePlugin::CacheArt: Cached " + str(fname), xbmc.LOGDEBUG )
            return pathJpg
        else:
            xbmc.log("AmpachePlugin::CacheArt: It didnt work", xbmc.LOGDEBUG)
            raise NameError
コード例 #7
0
def get_random(object_type):
    xbmc.log("AmpachePlugin::get_random: object_type " + object_type,
             xbmc.LOGDEBUG)
    mode = None
    #object type can be : albums, artists, songs, playlists

    ampConn = ampache_connect.AmpacheConnect()

    if object_type == 'albums':
        amtype = 'album'
        mode = 3
    elif object_type == 'artists':
        amtype = 'artist'
        mode = 2
    elif object_type == 'playlists':
        amtype = 'playlist'
        mode = 14
    elif object_type == 'songs':
        amtype = 'song'

    xbmcplugin.setContent(int(sys.argv[1]), object_type)

    random_items = (int(ampache.getSetting("random_items")) * 3) + 3
    xbmc.log("AmpachePlugin::get_random: random_items " + str(random_items),
             xbmc.LOGDEBUG)
    items = int(ampache.getSetting(object_type))
    xbmc.log(
        "AmpachePlugin::get_random: total items in the catalog " + str(items),
        xbmc.LOGDEBUG)
    if random_items > items:
        #if items are less than random_itmes, return all items
        get_items(object_type, limit=items)
        return
    #playlists are not in the new stats api, so, use the old mode
    if (int(ampache.getSetting("api-version"))
        ) >= 400001 and object_type != 'playlists':
        action = 'stats'
        thisFilter = 'random'
        try:
            ampConn.filter = thisFilter
            ampConn.limit = random_items
            ampConn.type = amtype

            elem = ampConn.ampache_http_request(action)
            addItem(object_type, mode, elem)
        except:
            return

    else:
        seq = random.sample(xrange(items), random_items)
        xbmc.log("AmpachePlugin::get_random: seq " + str(seq), xbmc.LOGDEBUG)
        elements = []
        for item_id in seq:
            try:
                ampConn.offset = item_id
                ampConn.limit = 1
                elem = ampConn.ampache_http_request(object_type)
                elements.append(elem)
            except:
                pass

        for el in elements:
            addItem(object_type, mode, el)
コード例 #8
0
def get_items(object_type,
              object_id=None,
              add=None,
              thisFilter=None,
              limit=5000,
              useCacheArt=True,
              object_subtype=None,
              exact=None):

    if object_type:
        xbmc.log("AmpachePlugin::get_items: object_type " + object_type,
                 xbmc.LOGDEBUG)
    else:
        #should be not possible
        xbmc.log("AmpachePlugin::get_items: object_type set to None",
                 xbmc.LOGDEBUG)
        return

    if object_subtype:
        xbmc.log("AmpachePlugin::get_items: object_subtype " + object_subtype,
                 xbmc.LOGDEBUG)
    if object_id:
        xbmc.log("AmpachePlugin::get_items: object_id " + str(object_id),
                 xbmc.LOGDEBUG)

    if limit == None:
        limit = int(ampache.getSetting(object_type))
    mode = None

    xbmcplugin.setContent(int(sys.argv[1]), object_type)
    #default: object_type is the action,otherwise see the if list below
    action = object_type

    #do not use action = object_subtype cause in tags it is used only to
    #discriminate between subtypes
    if object_type == 'albums':
        if object_subtype == 'artist_albums':
            action = 'artist_albums'
            addDir("All Songs", object_id, 12)
        elif object_subtype == 'tag_albums':
            action = 'tag_albums'
        elif object_subtype == 'album':
            action = 'album'
    elif object_type == 'artists':
        if object_subtype == 'tag_artists':
            action = 'tag_artists'
        if object_subtype == 'artist':
            action = 'artist'
    elif object_type == 'songs':
        if object_subtype == 'tag_songs':
            action = 'tag_songs'
        elif object_subtype == 'playlist_songs':
            action = 'playlist_songs'
        elif object_subtype == 'album_songs':
            action = 'album_songs'
        elif object_subtype == 'artist_songs':
            action = 'artist_songs'
        elif object_subtype == 'search_songs':
            action = 'search_songs'

    if object_id:
        thisFilter = object_id

    try:
        ampConn = ampache_connect.AmpacheConnect()
        ampConn.add = add
        ampConn.filter = thisFilter
        ampConn.limit = limit
        ampConn.exact = exact

        elem = ampConn.ampache_http_request(action)
    except:
        return

    #after the request, set the mode

    if object_type == 'artists':
        mode = 2
    elif object_type == 'albums':
        mode = 3
    elif object_type == 'playlists':
        mode = 14
    if object_type == 'tags':
        if object_subtype == 'tag_artists':
            mode = 19
        elif object_subtype == 'tag_albums':
            mode = 20
        elif object_subtype == 'tag_songs':
            mode = 21

    addItem(object_type, mode, elem, useCacheArt)
コード例 #9
0
    except:
        pass
    try:
        title = urllib.unquote_plus(params["title"])
        xbmc.log("AmpachePlugin::title " + title, xbmc.LOGDEBUG)
    except:
        pass
    try:
        song_url = urllib.unquote_plus(params["song_url"])
        xbmc.log("AmpachePlugin::song_url " + song_url, xbmc.LOGDEBUG)
    except:
        pass

    servers_manager.initialiseServer()

    ampacheConnect = ampache_connect.AmpacheConnect()

    if mode == None:
        try:
            elem = ampacheConnect.AMPACHECONNECT()
        except:
            elem = ET.Element("")

        addDir("Search...", None, 4, "DefaultFolder.png")
        addDir("Quick access...", None, 25, "DefaultFolder.png")
        addDir("Explore...", None, 23, "DefaultFolder.png")
        addDir("Library...", None, 24, "DefaultFolder.png")
        addDir("Switch server", None, 44, "DefaultFolder.png")
        addDir("Settings", None, 40, "DefaultFolder.png")

    #   artist list ( called from main screen  ( mode None ) , search