Beispiel #1
0
    def handshake(self):
        """ Log into Ampache """
        encrypted_key = ampache.encrypt_string(self.ampache_apikey,
                                               self.ampache_user)

        # handshake
        self.ampache_session = ampache.handshake(self.ampache_url,
                                                 encrypted_key, False, False,
                                                 '430000', self.api_format)
        # if you didn't get a sessoin there's nothing you can do
        if not self.ampache_session:
            print()
            sys.exit('ERROR: Failed to connect to ' + self.ampache_url)

        # did all this work?
        my_ping = ampache.ping(self.ampache_url, self.ampache_session,
                               self.api_format)
        if not my_ping:
            print()
            sys.exit('ERROR: Failed to ping ' + self.ampache_url)

        # save the last session key so you don't have to keep shaking each run
        self.conf.read(CONFIG)
        self.conf.set('conf', 'ampache_session', self.ampache_session)

        # write to conf file
        conffile = open(CONFIG, "w")
        self.conf.write(conffile)
        conffile.close()
Beispiel #2
0
def get_sessionkey(url, user, api_key, format='json'):
    """ Returns session key
        url:        Adress of the Ampache server
        user:       User to login with
        api_key:    API key, manualy generated by admin
        format:     json or xml
    """
    encrypted_key = ampache.encrypt_string(api_key, user)
    if encrypted_key:
        try:
            sessionkey = ampache.handshake(url, encrypted_key, api_format=format)
            if sessionkey:
                return sessionkey
            else:
                showerror("Details incorrect", "Some or all of your details are incorrect!")
                return False
        except ValueError:
            showerror("Invalid URL", "The entered URL is invalid!")
            return False
    else:
        showerror("Encrytion failed", "Encryption of username and API key went wrong!\n(However that happened...)")
        return False
import sys

# user variables
ampache_url = 'https://music.server'
ampache_api = 'mysuperapikey'
ampache_user = '******'
"""
encrypt_string
"""
encrypted_key = ampache.encrypt_string(ampache_api, ampache_user)
"""
handshake
"""
print('Connecting to:\n    ', ampache_url)
src_api = ampache_api
ampache_api = ampache.handshake(ampache_url, encrypted_key, False, False,
                                '420000', 'xml')

print('\nThe ampache handshake for:\n    ', src_api,
      '\n\nReturned the following session key:\n    ', ampache_api)
if not ampache_api:
    print()
    sys.exit('ERROR: Failed to connect to ' + ampache_url)

print('\nPing returned:\n    ', ampache.ping(ampache_url, ampache_api, 'json'))
print()
"""
advanced_search
"""
print('\nadvanced_search\nmetadata, BPM, is greater than, 200\n')
search_rules = [['metadata', 8, 200, 9]]
search_song = ampache.advanced_search(ampache_url, ampache_api, search_rules,
Beispiel #4
0
# user variables
ampache_url = 'https://music.server'
ampache_api = 'mysuperapikey'
ampache_user = '******'
"""
encrypt_string
"""
encrypted_key = ampache.encrypt_string(ampache_api, ampache_user)
"""
handshake
"""
# processed details
print('Connecting to:\n    ', ampache_url)
src_api = ampache_api
ampache_api = ampache.handshake(ampache_url, encrypted_key)
print('\nThe ampache handshake for:\n    ', src_api,
      '\n\nReturned the following session key:\n    ', ampache_api)
if not ampache_api:
    print()
    sys.exit('ERROR: Failed to connect to ' + ampache_url)
"""
ping
"""
# did all this work?
my_ping = ampache.ping(ampache_url, ampache_api)
print(
    '\nif your handshake was correct, ping will return your session key and extend the session.'
)
print('\nPing returned:\n    ', my_ping)
if not my_ping:
        sys.exit('ERROR: get your arguments correct')

limit = 4
offset = 0
api_version = '5.0.0'
api_format = 'json'
song_url = 'https://music.com.au/play/index.php?ssid=eeb9f1b6056246a7d563f479f518bb34&type=song&oid=164215&uid=2&player=api&name=Hellyeah%20-%20-.mp3'
"""
encrypt_string
"""
encrypted_key = ampache.encrypt_string(api, user)
"""
handshake
"""
print('Connecting to:\n    ', url)
ampache_session = ampache.handshake(url, encrypted_key)
print('\nThe ampache handshake for:\n    ', api,
      '\n\nReturned the following session key:\n    ', ampache_session)
"""
if you didn't connect you can't do anything
"""
if not ampache_session:
    print()
    sys.exit('ERROR: Failed to connect to ' + ampache_url)

#list to update
artist_list = [9, 10, 13, 14, 15, 16, 18, 19, 20]
"""
update_from_tags
"""
if ampache_session:
Beispiel #6
0
def build_docs(ampache_url, ampache_api, ampache_user, api_format):
    """TODO
    def update_art(ampache_url, ampache_api, ampache_type, ampache_id, overwrite = False, api_format = 'xml'):
    def update_artist_info(ampache_url, ampache_api, id, api_format = 'xml'):
    def stream(ampache_url, ampache_api, id, type, destination, api_format = 'xml'):
    def download(ampache_url, ampache_api, id, type, destination, format = 'raw', api_format = 'xml'):
    def get_art(ampache_url, ampache_api, id, type, api_format = 'xml'):
    """
    """ encrypt_string
    def encrypt_string(ampache_api, user):
    """
    encrypted_key = ampache.encrypt_string(ampache_api, ampache_user)
    """ handshake
    def handshake(ampache_url, ampache_api, user = False, timestamp = False, version = '400004', api_format = 'xml'):
    """
    # processed details
    ampache_api = ampache.handshake(ampache_url, encrypted_key, False, False,
                                    '400004', api_format)
    if not ampache_api:
        print()
        sys.exit('ERROR: Failed to connect to ' + ampache_url)
    """ ping
    def ping(ampache_url, ampache_api, api_format = 'xml'):
    """
    # did all this work?
    my_ping = ampache.ping(ampache_url, ampache_api, api_format)
    if not my_ping:
        print()
        sys.exit('ERROR: Failed to ping ' + ampache_url)
    """ set_debug
    def set_debug(mybool):
    """
    ampache.set_debug(True)
    """ url_to_song
    def url_to_song(ampache_url, ampache_api, url, api_format = 'xml'):
    """
    url_to_song = ampache.url_to_song(ampache_url, ampache_api, song_url,
                                      api_format)
    """ user_create
        def user_create(ampache_url, ampache_api, username, password, email, fullname = False, disable = False, api_format = 'xml'):
    """
    tempusername = '******'
    createuser = ampache.user_create(ampache_url, ampache_api, tempusername,
                                     'supoersecretpassword', '*****@*****.**',
                                     False, False, api_format)
    tmpuser = ampache.user(ampache_url, ampache_api, tempusername, api_format)
    """ user_edit
        def user_update(ampache_url, ampache_api, username, password = False, fullname = False, email = False, website = False, state = False, city = False, disable = False, maxbitrate = False, api_format = 'xml'):
    """
    edituser = ampache.user_update(ampache_url, ampache_api, tempusername,
                                   False, False, False, False, False, False,
                                   True, False, api_format)
    tmpuser = ampache.user(ampache_url, ampache_api, tempusername, api_format)
    shutil.move(api_format + "-responses/user." + api_format,
                api_format + "-responses/user (disabled)." + api_format)
    """ user_delete
        def user_delete(ampache_url, ampache_api, username, api_format = 'xml'):
    """
    deleteuser = ampache.user_delete(ampache_url, ampache_api, tempusername,
                                     api_format)
    """ user
    def user(ampache_url, ampache_api, username, api_format = 'xml'):
    """
    myuser = ampache.user(ampache_url, ampache_api, 'missing_user', api_format)
    shutil.move(api_format + "-responses/user." + api_format,
                api_format + "-responses/user (error)." + api_format)

    myuser = ampache.user(ampache_url, ampache_api, ampache_user, api_format)
    """ get_indexes
    def get_indexes(ampache_url, ampache_api, type, filter = False, add = False, update = False, offset = 0, limit = 0, api_format = 'xml'):

    'song'|'album'|'artist'|'playlist'
    """
    songs = ampache.get_indexes(ampache_url, ampache_api, 'song', '', '', '',
                                '', limit, api_format)
    shutil.move(api_format + "-responses/get_indexes." + api_format,
                api_format + "-responses/get_indexes (songs)." + api_format)
    if api_format == 'xml':
        for child in songs:
            if child.tag == 'total_count':
                print('total_count', child.text)
                if int(child.text) > int(limit):
                    print()
                    sys.exit('ERROR: songs ' + child.text +
                             ' found more items than the limit ' + str(limit))
                else:
                    continue

    albums = ampache.get_indexes(ampache_url, ampache_api, 'album', '', '', '',
                                 '', limit, api_format)
    shutil.move(api_format + "-responses/get_indexes." + api_format,
                api_format + "-responses/get_indexes (albums)." + api_format)
    if api_format == 'xml':
        for child in albums:
            if child.tag == 'total_count':
                print('total_count', child.text)
                if int(child.text) > int(limit):
                    print()
                    sys.exit('ERROR: albums ' + child.text +
                             ' found more items than the limit ' + str(limit))
                else:
                    continue

    artists = ampache.get_indexes(ampache_url, ampache_api, 'artist', '', '',
                                  '', '', limit, api_format)
    shutil.move(api_format + "-responses/get_indexes." + api_format,
                api_format + "-responses/get_indexes (artist)." + api_format)
    if api_format == 'xml':
        for child in artists:
            if child.tag == 'total_count':
                print('total_count', child.text)
                if int(child.text) > int(limit):
                    print()
                    sys.exit('ERROR: artists ' + child.text +
                             ' found more items than the limit ' + str(limit))
                else:
                    continue

    playlists = ampache.get_indexes(ampache_url, ampache_api, 'playlist', '',
                                    '', '', '', limit, api_format)
    shutil.move(
        api_format + "-responses/get_indexes." + api_format,
        api_format + "-responses/get_indexes (playlists)." + api_format)
    if api_format == 'xml':
        for child in playlists:
            if child.tag == 'total_count':
                print('total_count', child.text)
                if int(child.text) > int(limit):
                    print()
                    sys.exit('ERROR: playlists ' + child.text +
                             ' found more items than the limit ' + str(limit))
                else:
                    continue

    if api_format == 'xml':
        for child in songs:
            if child.tag == 'song':
                single_song = child.attrib['id']
        for child in albums:
            if child.tag == 'album':
                single_album = child.attrib['id']
        for child in artists:
            if child.tag == 'artist':
                single_artist = child.attrib['id']
        for child in playlists:
            if child.tag == 'playlist':
                single_playlist = child.attrib['id']
    else:
        single_song = songs[0]['id']
        single_album = albums[0]['id']
        single_artist = artists[0]['id']
        single_playlist = playlists[0]['id']
    """ advanced_search
    def advanced_search(ampache_url, ampache_api, rules, operator = 'and', type = 'song', offset = 0, limit = 0, api_format = 'xml'):
    """
    search_rules = [['favorite', 0, '%'], ['artist', 3, 'Prodigy']]
    search_song = ampache.advanced_search(ampache_url, ampache_api,
                                          search_rules, 'or', 'song', 0, limit,
                                          api_format)
    shutil.move(api_format + "-responses/advanced_search." + api_format,
                api_format + "-responses/advanced_search (song)." + api_format)

    if api_format == 'xml':
        for child in search_song:
            if child.tag == 'total_count':
                print('total_count', child.text)
                if int(child.text) > int(limit):
                    print()
                    sys.exit('ERROR: advanced_search (song) ' + child.text +
                             ' found more items than the limit ' + str(limit))
                else:
                    continue
            print(child.tag, child.attrib)
            for subchildren in child:
                print(str(subchildren.tag) + ': ' + str(subchildren.text))
            song_title = child.find('title').text
    else:
        song_title = search_song[0]['title']

    search_rules = [['favorite', 0, '%'], ['artist', 0, 'Men']]
    search_album = ampache.advanced_search(ampache_url, ampache_api,
                                           search_rules, 'or', 'album', 0,
                                           limit, api_format)
    shutil.move(
        api_format + "-responses/advanced_search." + api_format,
        api_format + "-responses/advanced_search (album)." + api_format)

    if api_format == 'xml':
        for child in search_album:
            if child.tag == 'total_count':
                print('total_count', child.text)
                if int(child.text) > int(limit):
                    print()
                    sys.exit('ERROR: advanced_search (album) ' + child.text +
                             ' found more items than the limit ' + str(limit))
                else:
                    continue
            print(child.tag, child.attrib)
            for subchildren in child:
                print(str(subchildren.tag) + ': ' + str(subchildren.text))
            album_title = child.find('name').text
    else:
        album_title = search_album[0]['name']

    search_rules = [['favorite', 0, '%'], ['artist', limit, 'Prodigy']]
    search_artist = ampache.advanced_search(ampache_url, ampache_api,
                                            search_rules, 'or', 'artist', 0,
                                            limit, api_format)
    shutil.move(
        api_format + "-responses/advanced_search." + api_format,
        api_format + "-responses/advanced_search (artist)." + api_format)

    if api_format == 'xml':
        for child in search_artist:
            if child.tag == 'total_count':
                print('total_count', child.text)
                if int(child.text) > int(limit):
                    print()
                    sys.exit('ERROR: advanced_search (artist) ' + child.text +
                             ' found more items than the limit ' + str(limit))
                else:
                    continue
            print(child.tag, child.attrib)
            for subchildren in child:
                print(str(subchildren.tag) + ': ' + str(subchildren.text))
            artist_title = child.find('name').text
    else:
        artist_title = search_artist[0]['name']
    """ album
    def album(ampache_url, ampache_api, filter, include = False, api_format = 'xml'):
    """
    album = ampache.album(ampache_url, ampache_api, single_album, False,
                          api_format)

    if api_format == 'xml':
        for child in album:
            if child.tag == 'album':
                print(child.tag, child.attrib)
                album_title = child.find('name').text
                for subchildren in child:
                    print(str(subchildren.tag) + ': ' + str(subchildren.text))
    else:
        album_title = search_album[0]['name']
    """ album_songs
    def album_songs(ampache_url, ampache_api, filter, offset = 0, limit = 0, api_format = 'xml'):
    """
    album_songs = ampache.album_songs(ampache_url, ampache_api, single_album,
                                      0, 0, api_format)
    if api_format == 'xml':
        for child in album_songs:
            if child.tag == 'song':
                print(child.tag, child.attrib)
                for subchildren in child:
                    print(str(subchildren.tag) + ': ' + str(subchildren.text))
    """ albums
    def albums(ampache_url, ampache_api, filter = False, exact = False, add = False, update = False, offset = 0, limit = 0, include = False, api_format = 'xml'):
    """
    albums = ampache.albums(ampache_url, ampache_api, album_title, 1, False,
                            False, 0, 10, False, api_format)
    if api_format == 'xml':
        for child in albums:
            if child.tag == 'total_count':
                print('total_count', child.text)
                if int(child.text) > int(limit):
                    print()
                    sys.exit('ERROR: albums ' + child.text +
                             ' found more items than the limit ' + str(limit))
                else:
                    continue
            print(child.tag, child.attrib)
            for subchildren in child:
                print(str(subchildren.tag) + ': ' + str(subchildren.text))
    """ stats
    def stats(ampache_url, ampache_api, type, filter = 'random', username = False, user_id = False, offset = 0, limit = 0, api_format = 'xml'):
    """
    stats = ampache.stats(ampache_url, ampache_api, 'artist', 'random',
                          ampache_user, False, 0, 2, api_format)
    shutil.move(api_format + "-responses/stats." + api_format,
                api_format + "-responses/stats (artist)." + api_format)

    if api_format == 'xml':
        for child in stats:
            if child.tag == 'artist':
                print(
                    '\ngetting a random artist using the stats method and found',
                    child.find('name').text)
                single_artist = child.attrib['id']
                print(child.tag, child.attrib)
                for subchildren in child:
                    print(str(subchildren.tag) + ': ' + str(subchildren.text))
    else:
        single_artist = stats[0]['id']

    stats = ampache.stats(ampache_url, ampache_api, 'album', 'random',
                          ampache_user, None, 0, 2, api_format)
    shutil.move(api_format + "-responses/stats." + api_format,
                api_format + "-responses/stats (album)." + api_format)

    if api_format == 'xml':
        for child in stats:
            if child.tag == 'album':
                print(
                    '\ngetting a random album using the stats method and found',
                    child.find('name').text)
                single_album = child.attrib['id']
                album_title = child.find('name').text
                print(child.tag, child.attrib)
                for subchildren in child:
                    print(str(subchildren.tag) + ': ' + str(subchildren.text))
    else:
        album_title = stats[0]['name']
    """ artist
    def artist(ampache_url, ampache_api, filter, include = False, api_format = 'xml'):
    """
    artist = ampache.artist(ampache_url, ampache_api, single_artist, False,
                            api_format)

    if api_format == 'xml':
        for child in artist:
            if child.tag == 'artist':
                print('\nsearching for an artist with this id', single_artist)
                print(child.tag, child.attrib)
                for subchildren in child:
                    print(str(subchildren.tag) + ': ' + str(subchildren.text))
    """ artist_albums
    def artist_albums(ampache_url, ampache_api, filter, offset = 0, limit = 0, api_format = 'xml'):
    """
    artist_albums = ampache.artist_albums(ampache_url, ampache_api,
                                          single_artist, 0, 0, api_format)
    """ artist_songs
    def artist_songs(ampache_url, ampache_api, filter, offset = 0, limit = 0, api_format = 'xml'):
    """
    artist_songs = ampache.artist_songs(ampache_url, ampache_api,
                                        single_artist, 0, 0, api_format)
    """ artists
    def artists(ampache_url, ampache_api, filter = False, add = False, update = False, offset = 0, limit = 0, include = False, api_format = 'xml'):
    """
    myartists = ampache.artists(ampache_url, ampache_api, False, False, False,
                                0, 0, False, api_format)
    """ catalog_action
    def catalog_action(ampache_url, ampache_api, task, catalog, api_format = 'xml'):
    """
    catalog_action = ampache.catalog_action(ampache_url, ampache_api, 'clean',
                                            2, api_format)
    shutil.move(api_format + "-responses/catalog_action." + api_format,
                api_format + "-responses/catalog_action (error)." + api_format)

    catalog_action = ampache.catalog_action(ampache_url, ampache_api,
                                            'clean_catalog', 2, api_format)
    shutil.move(
        api_format + "-responses/catalog_action." + api_format,
        api_format + "-responses/catalog_action (clean_catalog)." + api_format)
    """ flag
    def flag(ampache_url, ampache_api, type, id, flag, api_format = 'xml'):
    """
    #print(ampache.flag(ampache_url, ampache_api))
    """ followers
    def followers(ampache_url, ampache_api, username, api_format = 'xml'):
    """
    followers = ampache.followers(ampache_url, ampache_api, ampache_user,
                                  api_format)
    """ following
    def following(ampache_url, ampache_api, username, api_format = 'xml'):
    """
    following = ampache.following(ampache_url, ampache_api, ampache_user,
                                  api_format)
    """ friends_timeline
    def friends_timeline(ampache_url, ampache_api, limit = 0, since = 0, api_format = 'xml'):
    """
    friends_timeline = ampache.friends_timeline(ampache_url, ampache_api, 0, 0,
                                                api_format)
    """ last_shouts
    def last_shouts(ampache_url, ampache_api, username, limit = 0, api_format = 'xml'):
    """
    last_shouts = ampache.last_shouts(ampache_url, ampache_api, ampache_user,
                                      0, api_format)
    """ playlists
    def playlists(ampache_url, ampache_api, filter = False, exact = False, offset = 0, limit = 0, api_format = 'xml'):
    """
    playlists = ampache.playlists(ampache_url, ampache_api, False, False, 0, 0,
                                  api_format)
    """ playlist
    def playlist(ampache_url, ampache_api, filter, api_format = 'xml'):
    """
    playlist = ampache.playlist(ampache_url, ampache_api, single_playlist,
                                api_format)
    """ playlist_songs
    def playlist_songs(ampache_url, ampache_api, filter, offset = 0, limit = 0, api_format = 'xml'):
    """
    playlist_songs = ampache.playlist_songs(ampache_url, ampache_api,
                                            single_playlist, 0, 0, api_format)
    """ playlist_create
    def playlist_create(ampache_url, ampache_api, name, type, api_format = 'xml'):
    """
    #print(ampache.playlist_create(ampache_url, ampache_api))
    """ playlist_edit
    def playlist_edit(ampache_url, ampache_api, filter, name = False, type = False, api_format = 'xml'):
    """
    #print(ampache.playlist_edit(ampache_url, ampache_api))
    """ playlist_add_song
    def playlist_add_song(ampache_url, ampache_api, filter, song, check = 0, api_format = 'xml'):
    """
    #print(ampache.playlist_add_song(ampache_url, ampache_api))
    """ playlist_remove_song
    def playlist_remove_song(ampache_url, ampache_api, filter, song = False, track = False, api_format = 'xml'):
    """
    #print(ampache.playlist_remove_song(ampache_url, ampache_api))
    """ playlist_delete
    def playlist_delete(ampache_url, ampache_api, filter, api_format = 'xml'):
    """
    #print(ampache.playlist_delete(ampache_url, ampache_api))
    """ playlist_generate
    def playlist_generate(ampache_url, ampache_api, mode = 'random', filter = False, album = False, artist = False, flag = False, format = 'song', offset = 0, limit = 0, api_format = 'xml'):
    'song'|'index'|'id'
    """
    ampache.playlist_generate(ampache_url, ampache_api, 'random', False, False,
                              False, False, 'song', 0, limit, api_format)
    shutil.move(
        api_format + "-responses/playlist_generate." + api_format,
        api_format + "-responses/playlist_generate (song)." + api_format)

    ampache.playlist_generate(ampache_url, ampache_api, 'random', False, False,
                              False, False, 'index', 0, limit, api_format)
    shutil.move(
        api_format + "-responses/playlist_generate." + api_format,
        api_format + "-responses/playlist_generate (index)." + api_format)

    ampache.playlist_generate(ampache_url, ampache_api, 'random', False, False,
                              False, False, 'id', 0, limit, api_format)
    shutil.move(api_format + "-responses/playlist_generate." + api_format,
                api_format + "-responses/playlist_generate (id)." + api_format)
    """ rate
    def rate(ampache_url, ampache_api, type, id, rating, api_format = 'xml'):
    """
    #print(ampache.rate(ampache_url, ampache_api))
    """ record_play
    def record_play(ampache_url, ampache_api, id, user, client = 'AmpacheAPI', api_format = 'xml'):
    """
    #print(ampache.record_play(ampache_url, ampache_api))
    """ scrobble
    def scrobble(ampache_url, ampache_api, title, artist, album, MBtitle = False, MBartist = False, MBalbum = False, time = False, client = 'AmpacheAPI', api_format = 'xml'):
    """
    scrobble = ampache.scrobble(ampache_url, ampache_api, 'Hear.Life.Spoken',
                                'Sub Atari Knives',
                                'Sub Atari Knives', False, False, False,
                                int(time.time()), 'AmpaceApi', api_format)
    shutil.move(api_format + "-responses/scrobble." + api_format,
                api_format + "-responses/scrobble (error)." + api_format)

    scrobble = ampache.scrobble(ampache_url, ampache_api,
                                'Welcome to Planet Sexor',
                                'Tiga', 'Sexor', False, False, False,
                                int(time.time()), 'test.py', api_format)
    """ search_songs
    def search_songs(ampache_url, ampache_api, filter, offset = 0, limit = 0, api_format = 'xml'):
    """
    search_songs = ampache.search_songs(ampache_url, ampache_api, song_title,
                                        0, 0, api_format)

    if api_format == 'xml':
        for child in search_songs:
            print(child.tag, child.attrib)
            for subchildren in child:
                print(str(subchildren.tag) + ': ' + str(subchildren.text))
    """ song
    def song(ampache_url, ampache_api, filter, api_format = 'xml'):
    """
    song = ampache.song(ampache_url, ampache_api, single_song, api_format)

    if api_format == 'xml':
        for child in song:
            print(child.tag, child.attrib)
            for subchildren in child:
                print(str(subchildren.tag) + ': ' + str(subchildren.text))
    """ songs
    def songs(ampache_url, ampache_api, filter = False, exact = False, add = False, update = False, offset = 0, limit = 0, api_format = 'xml'):
    """
    songs = ampache.songs(ampache_url, ampache_api, False, False, False, False,
                          0, 0, api_format)
    if api_format == 'xml':
        for child in songs:
            print(child.tag, child.attrib)
            for subchildren in child:
                print(str(subchildren.tag) + ': ' + str(subchildren.text))
    """ tags
    def tags(ampache_url, ampache_api, filter = False, exact = False, offset = 0, limit = 0, api_format = 'xml'):
    """
    genre = ''
    tags = ampache.tags(ampache_url, ampache_api, 'Brutal Death Metal', '1', 0,
                        limit, api_format)
    if api_format == 'xml':
        for child in tags:
            if child.tag == 'total_count':
                print('total_count', child.text)
                if int(child.text) > int(limit):
                    print()
                    sys.exit('ERROR: tags ' + child.text +
                             ' found more items than the limit ' + str(limit))
                else:
                    continue
            print(child.tag, child.attrib)
            genre = child.attrib['id']
            for subchildren in child:
                print(str(subchildren.tag) + ': ' + str(subchildren.text))
    else:
        genre = tags[0]['tag']['id']
    """ tag
    def tag(ampache_url, ampache_api, filter, api_format = 'xml'):
    """
    tag = ampache.tag(ampache_url, ampache_api, genre, api_format)
    """ tag_albums
    def tag_albums(ampache_url, ampache_api, filter, offset = 0, limit = 0, api_format = 'xml'):
    """
    tag_albums = ampache.tag_albums(ampache_url, ampache_api, genre, 0, 2,
                                    api_format)
    if api_format == 'xml':
        for child in tag_albums:
            print(child.tag, child.attrib)
            for subchildren in child:
                print(str(subchildren.tag) + ': ' + str(subchildren.text))
    """ tag_artists
    def tag_artists(ampache_url, ampache_api, filter, offset = 0, limit = 0, api_format = 'xml'):
    """
    tag_artists = ampache.tag_artists(ampache_url, ampache_api, genre, 0, 1,
                                      api_format)
    if api_format == 'xml':
        for child in tag_artists:
            print(child.tag, child.attrib)
            for subchildren in child:
                print(str(subchildren.tag) + ': ' + str(subchildren.text))
    """ tag_songs
    def tag_songs(ampache_url, ampache_api, filter, offset = 0, limit = 0, api_format = 'xml'):
    """
    tag_songs = ampache.tag_songs(ampache_url, ampache_api, genre, 0, 1,
                                  api_format)
    """ timeline
    def timeline(ampache_url, ampache_api, username, limit = 0, since = 0, api_format = 'xml'):
    """
    timeline = ampache.timeline(ampache_url, ampache_api, ampache_user, 10, 0,
                                api_format)

    if api_format == 'xml':
        for child in timeline:
            print(child.tag, child.attrib)
            for subchildren in child:
                print(str(subchildren.tag) + ': ' + str(subchildren.text))
    """ toggle_follow
    def toggle_follow(ampache_url, ampache_api, username, api_format = 'xml'):
    """
    toggle = 'generic'
    if ampache_user == 'generic':
        toggle = 'user'
    togglefollow = ampache.toggle_follow(ampache_url, ampache_api, toggle,
                                         api_format)
    """ update_from_tags
    def update_from_tags(ampache_url, ampache_api, ampache_type, ampache_id, api_format = 'xml'):
    """
    update_from_tags = ampache.update_from_tags(ampache_url, ampache_api,
                                                'album', single_album,
                                                api_format)
    """ video
    def video(ampache_url, ampache_api, filter, api_format = 'xml'):
    """
    #print(ampache.video(ampache_url, ampache_api))
    """ videos
    def videos(ampache_url, ampache_api, filter = False, exact = False, offset = 0, limit = 0, api_format = 'xml'):
    """
    #print(ampache.videos(ampache_url, ampache_api))
    """ localplay
    def localplay(ampache_url, ampache_api, command, api_format = 'xml'):
    """
    #print(ampache.localplay(ampache_url, ampache_api))
    """ democratic
    def democratic(ampache_url, ampache_api, method, action, oid, api_format = 'xml'):
    """
    #print(ampache.democratic(ampache_url, ampache_api))
    """ goodbye
    def goodbye(ampache_url, ampache_api, api_format = 'xml'):
    """
    # Close your session when you're done
    goodbye = ampache.goodbye(ampache_url, ampache_api, api_format)
Beispiel #7
0
def run_tests(ampache_url, ampache_api, ampache_user, api_format):

    print(
        f"{HEADER}\n################\nRUN PYTHON TESTS\n################\n{ENDC}"
    )
    print("Testing: " + api_format)
    """TODO
    def update_art(ampache_url, ampache_api, ampache_type, ampache_id, overwrite = False, api_format = 'xml'):
    def update_artist_info(ampache_url, ampache_api, id, api_format = 'xml'):
    def stream(ampache_url, ampache_api, id, type, destination, api_format = 'xml'):
    def download(ampache_url, ampache_api, id, type, destination, format = 'raw', api_format = 'xml'):
    def get_art(ampache_url, ampache_api, id, type, api_format = 'xml'):
    """
    """ encrypt_string
    def encrypt_string(ampache_api, user):
    """
    encrypted_key = ampache.encrypt_string(ampache_api, ampache_user)
    if encrypted_key:
        print(f"ampache.encrypted_key: {OKGREEN}PASS{ENDC}")
        #print("\nreturned:\n" + encrypted_key)
    else:
        sys.exit(f"\nampache.encrypted_key:     {FAIL}FAIL{ENDC}")
    """ handshake
    def handshake(ampache_url, ampache_api, user = False, timestamp = False, version = '400004', api_format = 'xml'):
    """
    # processed details
    ampache_api = ampache.handshake(ampache_url, encrypted_key, False, False,
                                    '400004', api_format)
    if ampache_api:
        print(f"ampache.handshake: {OKGREEN}PASS{ENDC}")
        #print("\nreturned:\n" + ampache_api)
    else:
        print(f"ampache.handshake: {FAIL}FAIL{ENDC}")
        sys.exit(f"\n{FAIL}ERROR:{ENDC} Failed to connect to " + ampache_url)
    """ ping
    def ping(ampache_url, ampache_api, api_format = 'xml'):
    """
    # did all this work?
    my_ping = ampache.ping(ampache_url, ampache_api, api_format)
    if my_ping:
        print(f"ampache.ping: {OKGREEN}PASS{ENDC}")
        #print("\nreturned:\n" + my_ping)
    else:
        print(f"ampache.ping: {FAIL}FAIL{ENDC}")
        sys.exit(f"\n{FAIL}ERROR:{ENDC} Failed to ping " + ampache_url)
    """ set_debug
    def set_debug(mybool):
    """
    set_debug = ampache.set_debug(False)
    """ url_to_song
    def url_to_song(ampache_url, ampache_api, url, api_format = 'xml'):
    """
    song_url = 'https://music.com.au/play/index.php?ssid=eeb9f1b6056246a7d563f479f518bb34&type=song&oid=164215&uid=2&player=api&name=Hellyeah%20-%20-.mp3'
    song_id = False
    url_to_song = ampache.url_to_song(ampache_url, ampache_api, song_url,
                                      api_format)

    if api_format == 'xml':
        song_id = ET.tostring(url_to_song).decode()
    else:
        song_id = url_to_song

    if url_to_song and song_id:
        print(f"ampache.url_to_song: {OKGREEN}PASS{ENDC}")
        #print("\nreturned:")
        #print(song_id)
    else:
        print(f"ampache.url_to_song: {FAIL}FAIL{ENDC}")
    """ user_create
    def user_create(ampache_url, ampache_api, username, password, email, fullname = False, disable = False, api_format = 'xml'):
    """
    failed = False
    message = ''
    tempusername = '******'
    createuser = ampache.user_create(ampache_url, ampache_api, tempusername,
                                     'supoersecretpassword', '*****@*****.**',
                                     False, False, api_format)
    if api_format == 'xml':
        for child in createuser:
            if child.tag == 'error':
                failed = True
                message = child.text
            if child.tag == 'success':
                message = child.text
    else:
        if 'error' in createuser:
            failed = True
            message = createuser['error']['message']
        if 'success' in createuser:
            message = createuser['success']['message']

    if createuser and not failed:
        print(f"ampache.user_create: {OKGREEN}PASS{ENDC}")
        #print("\nreturned:")
        #print(message)
    else:
        if message == 'User does not have access to this function':
            print(f"ampache.user_create: {WARNING}WARNING{ENDC}")
        else:
            print(f"ampache.user_create: {FAIL}FAIL{ENDC}")
        print("returned:")
        print(message + "\n")
    """ user_edit
    def user_update(ampache_url, ampache_api, username, password = False, fullname = False, email = False, website = False, state = False, city = False, disable = False, maxbitrate = False, api_format = 'xml'):
    """
    failed = False
    message = ''
    edituser = ampache.user_update(ampache_url, ampache_api, tempusername,
                                   False, False, False, False, False, False,
                                   True, False, api_format)
    if api_format == 'xml':
        for child in edituser:
            if child.tag == 'error':
                failed = True
                message = child.text
            if child.tag == 'success':
                message = child.text
    else:
        if 'error' in edituser:
            failed = True
            message = edituser['error']['message']
        if 'success' in edituser:
            message = edituser['success']['message']

    if edituser and not failed:
        print(f"ampache.user_update: {OKGREEN}PASS{ENDC}")
        #print("\nreturned:")
        #print(message)
    else:
        if message == 'User does not have access to this function':
            print(f"ampache.user_create: {WARNING}WARNING{ENDC}")
        else:
            print(f"ampache.user_create: {FAIL}FAIL{ENDC}")
        print("returned:")
        print(message + "\n")
    """ user_delete
    def user_delete(ampache_url, ampache_api, username, api_format = 'xml'):
    """
    failed = False
    message = ''
    deleteuser = ampache.user_delete(ampache_url, ampache_api, tempusername,
                                     api_format)
    if api_format == 'xml':
        for child in deleteuser:
            if child.tag == 'error':
                failed = True
                message = child.text
            if child.tag == 'success':
                message = child.text
    else:
        if 'error' in deleteuser:
            failed = True
            message = deleteuser['error']['message']
        if 'success' in deleteuser:
            message = deleteuser['success']['message']

    if deleteuser and not failed:
        print(f"ampache.user_delete: {OKGREEN}PASS{ENDC}")
        #print("\nreturned:")
        #print(message)
    else:
        if message == 'User does not have access to this function':
            print(f"ampache.user_create: {WARNING}WARNING{ENDC}")
        else:
            print(f"ampache.user_create: {FAIL}FAIL{ENDC}")
        print("returned:")
        print(message + "\n")
    """ user
    def user(ampache_url, ampache_api, username, api_format = 'xml'):
    """
    myuser = ampache.user(ampache_url, ampache_api, 'missing_user', api_format)
    myuser = ampache.user(ampache_url, ampache_api, ampache_user, api_format)

    if api_format == 'xml':
        user_id = ET.tostring(myuser).decode()
    else:
        user_id = myuser

    if myuser:
        print(f"ampache.user: {OKGREEN}PASS{ENDC}")
        #print("\nreturned:")
        #print(user_id)
    else:
        sys.exit(f"\nampache.user: {FAIL}FAIL{ENDC}")
    """ get_indexes
    def get_indexes(ampache_url, ampache_api, type, filter = False, add = False, update = False, offset = 0, limit = 0, api_format = 'xml'):

    'song'|'album'|'artist'|'playlist'
    """
    songs = ampache.get_indexes(ampache_url, ampache_api, 'song', '', '', '',
                                '', 4, api_format)
    if api_format == 'xml':
        for child in songs:
            if child.tag == 'total_count':
                if int(child.text) > int(limit):
                    print(f"ampache.get_indexes: {FAIL}FAIL{ENDC}")
                    sys.exit(f"\n{FAIL}ERROR:{ENDC} songs " + child.text +
                             ' found more items than the limit ' + str(limit))
                else:
                    continue

    albums = ampache.get_indexes(ampache_url, ampache_api, 'album', '', '', '',
                                 '', 4, api_format)
    if api_format == 'xml':
        for child in albums:
            if child.tag == 'total_count':
                if int(child.text) > int(limit):
                    print(f"ampache.get_indexes: {FAIL}FAIL{ENDC}")
                    sys.exit(f"\n{FAIL}ERROR:{ENDC} albums " + child.text +
                             ' found more items than the limit ' + str(limit))
                else:
                    continue

    artists = ampache.get_indexes(ampache_url, ampache_api, 'artist', '', '',
                                  '', '', 4, api_format)
    if api_format == 'xml':
        for child in artists:
            if child.tag == 'total_count':
                if int(child.text) > int(limit):
                    print(f"ampache.get_indexes: {FAIL}FAIL{ENDC}")
                    sys.exit(f"\n{FAIL}ERROR:{ENDC} artists " + child.text +
                             ' found more items than the limit ' + str(limit))
                else:
                    continue

    playlists = ampache.get_indexes(ampache_url, ampache_api, 'playlist', '',
                                    '', '', '', 4, api_format)
    if api_format == 'xml':
        for child in playlists:
            if child.tag == 'total_count':
                if int(child.text) > int(limit):
                    print(f"ampache.get_indexes: {FAIL}FAIL{ENDC}")
                    sys.exit(f"\n{FAIL}ERROR:{ENDC} playlists " + child.text +
                             ' found more items than the limit ' + str(limit))
                else:
                    continue

    if api_format == 'xml':
        for child in songs:
            if child.tag == 'song':
                single_song = child.attrib['id']
        for child in albums:
            if child.tag == 'album':
                single_album = child.attrib['id']
        for child in artists:
            if child.tag == 'artist':
                single_artist = child.attrib['id']
        for child in playlists:
            if child.tag == 'playlist':
                single_playlist = child.attrib['id']
    else:
        single_song = songs[0]['id']
        single_album = albums[0]['id']
        single_artist = artists[0]['id']
        single_playlist = playlists[0]['id']

    if single_song and single_album and single_artist and single_playlist:
        print(f"ampache.get_indexes: {OKGREEN}PASS{ENDC}")
    else:
        sys.exit(f"\nampache.get_indexes: {FAIL}FAIL{ENDC}")
    """ advanced_search
    def advanced_search(ampache_url, ampache_api, rules, operator = 'and', type = 'song', offset = 0, limit = 0, api_format = 'xml'):
    """
    search_rules = [['favorite', 0, '%'], ['artist', 3, 'Prodigy']]
    search_song = ampache.advanced_search(ampache_url, ampache_api,
                                          search_rules, 'or', 'song', 0, 4,
                                          api_format)

    if api_format == 'xml':
        for child in search_song:
            if child.tag == 'total_count':
                if int(child.text) > int(limit):
                    print(f"ampache.advanced_search: {FAIL}FAIL{ENDC}")
                    sys.exit(f"\n{FAIL}ERROR:{ENDC} advanced_search (song) " +
                             child.text + ' found more items than the limit ' +
                             str(limit))
                else:
                    continue
            #print(child.tag, child.attrib)
            #for subchildren in child:
            #    #print(str(subchildren.tag) + ': ' + str(subchildren.text))
            song_title = child.find('title').text
    else:
        song_title = search_song[0]['title']

    search_rules = [['favorite', 0, '%'], ['artist', 0, 'Men']]
    search_album = ampache.advanced_search(ampache_url, ampache_api,
                                           search_rules, 'or', 'album', 0, 4,
                                           api_format)

    if api_format == 'xml':
        for child in search_album:
            if child.tag == 'total_count':
                if int(child.text) > int(limit):
                    print(f"ampache.advanced_search: {FAIL}FAIL{ENDC}")
                    sys.exit(f"\n{FAIL}ERROR:{ENDC} advanced_search (album) " +
                             child.text + ' found more items than the limit ' +
                             str(limit))
                else:
                    continue
            #print(child.tag, child.attrib)
            #for subchildren in child:
            #    print(str(subchildren.tag) + ': ' + str(subchildren.text))
            album_title = child.find('name').text
    else:
        album_title = search_album[0]['name']

    search_rules = [['favorite', 0, '%'], ['artist', 4, 'Prodigy']]
    search_artist = ampache.advanced_search(ampache_url, ampache_api,
                                            search_rules, 'or', 'artist', 0, 4,
                                            api_format)

    if api_format == 'xml':
        for child in search_artist:
            if child.tag == 'total_count':
                if int(child.text) > int(limit):
                    print(f"ampache.advanced_search: {FAIL}FAIL{ENDC}")
                    sys.exit(f"{FAIL}ERROR:{ENDC} advanced_search (artist) " +
                             child.text + ' found more items than the limit ' +
                             str(limit))
                else:
                    continue
            #print(child.tag, child.attrib)
            #for subchildren in child:
            #    print(str(subchildren.tag) + ': ' + str(subchildren.text))
            artist_title = child.find('name').text
    else:
        artist_title = search_artist[0]['name']

    if search_song and search_album and search_artist and song_title and album_title and artist_title:
        print(f"ampache.get_indexes: {OKGREEN}PASS{ENDC}")
    else:
        sys.exit(f"\nampache.get_indexes: {FAIL}FAIL{ENDC}")
    """ album
    def album(ampache_url, ampache_api, filter, include = False, api_format = 'xml'):
    """
    album = ampache.album(ampache_url, ampache_api, single_album, False,
                          api_format)

    if api_format == 'xml':
        for child in album:
            if child.tag == 'album':
                #print(child.tag, child.attrib)
                album_title = child.find('name').text
                #for subchildren in child:
                #    print(str(subchildren.tag) + ': ' + str(subchildren.text))
    else:
        album_title = search_album[0]['name']

    if album_title:
        print(f"ampache.album: {OKGREEN}PASS{ENDC}")
    else:
        sys.exit(f"\nampache.album: {FAIL}FAIL{ENDC}")
    """ album_songs
    def album_songs(ampache_url, ampache_api, filter, offset = 0, limit = 0, api_format = 'xml'):
    """
    album_songs = ampache.album_songs(ampache_url, ampache_api, single_album,
                                      0, 0, api_format)
    #if api_format == 'xml':
    #    #for child in album_songs:
    #    #    #if child.tag == 'song':
    #    #    #    #print(child.tag, child.attrib)
    #    #    #    #for subchildren in child:
    #    #    #    #    print(str(subchildren.tag) + ': ' + str(subchildren.text))

    if album_songs:
        print(f"ampache.album_songs: {OKGREEN}PASS{ENDC}")
    else:
        sys.exit(f"\nampache.album_songs: {FAIL}FAIL{ENDC}")
    """ albums
    def albums(ampache_url, ampache_api, filter = False, exact = False, add = False, update = False, offset = 0, limit = 0, include = False, api_format = 'xml'):
    """
    albums = ampache.albums(ampache_url, ampache_api, album_title, 1, False,
                            False, 0, 10, False, api_format)
    if api_format == 'xml':
        for child in albums:
            if child.tag == 'total_count':
                if int(child.text) > int(limit):
                    print(f"ampache.albums: {FAIL}FAIL{ENDC}")
                    sys.exit(f"{FAIL}ERROR:{ENDC} albums " + child.text +
                             ' found more items than the limit ' + str(limit))
                else:
                    continue
            #print(child.tag, child.attrib)
            #for subchildren in child:
            #    print(str(subchildren.tag) + ': ' + str(subchildren.text))

    if albums:
        print(f"ampache.albums: {OKGREEN}PASS{ENDC}")
    else:
        sys.exit(f"\nampache.albums: {FAIL}FAIL{ENDC}")
    """ stats
    def stats(ampache_url, ampache_api, type, filter = 'random', username = False, user_id = False, offset = 0, limit = 0, api_format = 'xml'):
    """
    stats = ampache.stats(ampache_url, ampache_api, 'artist', 'random',
                          ampache_user, False, 0, 2, api_format)

    if api_format == 'xml':
        for child in stats:
            if child.tag == 'artist':
                #print('\ngetting a random artist using the stats method and found', child.find('name').text)
                single_artist = child.attrib['id']
                #print(child.tag, child.attrib)
                #for subchildren in child:
                #    print(str(subchildren.tag) + ': ' + str(subchildren.text))
    else:
        single_artist = stats[0]['id']
    stats = ampache.stats(ampache_url, ampache_api, 'album', 'random',
                          ampache_user, None, 0, 2, api_format)

    if api_format == 'xml':
        for child in stats:
            if child.tag == 'album':
                #print('\ngetting a random album using the stats method and found', child.find('name').text)
                single_album = child.attrib['id']
                album_title = child.find('name').text
                #print(child.tag, child.attrib)
                #for subchildren in child:
                #    print(str(subchildren.tag) + ': ' + str(subchildren.text))
    else:
        single_album = stats[0]['id']
        album_title = stats[0]['name']

    if single_artist and single_album and album_title:
        print(f"ampache.stats: {OKGREEN}PASS{ENDC}")
    else:
        sys.exit(f"\nampache.stats: {FAIL}FAIL{ENDC}")
    """ artist
    def artist(ampache_url, ampache_api, filter, include = False, api_format = 'xml'):
    """
    artist = ampache.artist(ampache_url, ampache_api, single_artist, False,
                            api_format)

    #if api_format == 'xml':
    #    for child in artist:
    #        if child.tag == 'artist':
    #            #print('\nsearching for an artist with this id', single_artist)
    #            #print(child.tag, child.attrib)
    #            #for subchildren in child:
    #            #    print(str(subchildren.tag) + ': ' + str(subchildren.text))

    if artist:
        print(f"ampache.artist: {OKGREEN}PASS{ENDC}")
    else:
        sys.exit(f"\nampache.artist: {FAIL}FAIL{ENDC}")
    """ artist_albums
    def artist_albums(ampache_url, ampache_api, filter, offset = 0, limit = 0, api_format = 'xml'):
    """
    artist_albums = ampache.artist_albums(ampache_url, ampache_api,
                                          single_artist, 0, 0, api_format)

    if artist_albums:
        print(f"ampache.artist_albums: {OKGREEN}PASS{ENDC}")
    else:
        sys.exit(f"\nampache.artist_albums: {FAIL}FAIL{ENDC}")
    """ artist_songs
    def artist_songs(ampache_url, ampache_api, filter, offset = 0, limit = 0, api_format = 'xml'):
    """
    artist_songs = ampache.artist_songs(ampache_url, ampache_api,
                                        single_artist, 0, 0, api_format)

    if artist_songs:
        print(f"ampache.artist_songs: {OKGREEN}PASS{ENDC}")
    else:
        sys.exit(f"\nampache.artist_songs: {FAIL}FAIL{ENDC}")
    """ artists
    def artists(ampache_url, ampache_api, filter = False, add = False, update = False, offset = 0, limit = 0, include = False, api_format = 'xml'):
    """
    myartists = ampache.artists(ampache_url, ampache_api, False, False, False,
                                0, 0, False, api_format)

    if myartists:
        print(f"ampache.artists: {OKGREEN}PASS{ENDC}")
    else:
        sys.exit(f"\nampache.artists: {FAIL}FAIL{ENDC}")
    """ catalog_action
    def catalog_action(ampache_url, ampache_api, task, catalog, api_format = 'xml'):
    """
    catalog_action = ampache.catalog_action(ampache_url, ampache_api, 'clean',
                                            2, api_format)
    catalog_action = ampache.catalog_action(ampache_url, ampache_api,
                                            'clean_catalog', 2, api_format)

    if catalog_action:
        print(f"ampache.catalog_action: {OKGREEN}PASS{ENDC}")
    else:
        sys.exit(f"\nampache.catalog_action: {FAIL}FAIL{ENDC}")
    """ flag
    def flag(ampache_url, ampache_api, type, id, flag, api_format = 'xml'):
    """
    #print(ampache.flag(ampache_url, ampache_api))
    """ followers
    def followers(ampache_url, ampache_api, username, api_format = 'xml'):
    """
    followers = ampache.followers(ampache_url, ampache_api, ampache_user,
                                  api_format)
    """ following
    def following(ampache_url, ampache_api, username, api_format = 'xml'):
    """
    following = ampache.following(ampache_url, ampache_api, ampache_user,
                                  api_format)
    """ friends_timeline
    def friends_timeline(ampache_url, ampache_api, limit = 0, since = 0, api_format = 'xml'):
    """
    friends_timeline = ampache.friends_timeline(ampache_url, ampache_api, 0, 0,
                                                api_format)
    """ last_shouts
    def last_shouts(ampache_url, ampache_api, username, limit = 0, api_format = 'xml'):
    """
    last_shouts = ampache.last_shouts(ampache_url, ampache_api, ampache_user,
                                      0, api_format)
    """ playlists
    def playlists(ampache_url, ampache_api, filter = False, exact = False, offset = 0, limit = 0, api_format = 'xml'):
    """
    playlists = ampache.playlists(ampache_url, ampache_api, False, False, 0, 0,
                                  api_format)
    """ playlist
    def playlist(ampache_url, ampache_api, filter, api_format = 'xml'):
    """
    playlist = ampache.playlist(ampache_url, ampache_api, single_playlist,
                                api_format)
    """ playlist_songs
    def playlist_songs(ampache_url, ampache_api, filter, offset = 0, limit = 0, api_format = 'xml'):
    """
    playlist_songs = ampache.playlist_songs(ampache_url, ampache_api,
                                            single_playlist, 0, 0, api_format)
    """ playlist_create
    def playlist_create(ampache_url, ampache_api, name, type, api_format = 'xml'):
    """
    #print(ampache.playlist_create(ampache_url, ampache_api))
    """ playlist_edit
    def playlist_edit(ampache_url, ampache_api, filter, name = False, type = False, api_format = 'xml'):
    """
    #print(ampache.playlist_edit(ampache_url, ampache_api))
    """ playlist_add_song
    def playlist_add_song(ampache_url, ampache_api, filter, song, check = 0, api_format = 'xml'):
    """
    #print(ampache.playlist_add_song(ampache_url, ampache_api))
    """ playlist_remove_song
    def playlist_remove_song(ampache_url, ampache_api, filter, song = False, track = False, api_format = 'xml'):
    """
    #print(ampache.playlist_remove_song(ampache_url, ampache_api))
    """ playlist_delete
    def playlist_delete(ampache_url, ampache_api, filter, api_format = 'xml'):
    """
    #print(ampache.playlist_delete(ampache_url, ampache_api))
    """ playlist_generate
    def playlist_generate(ampache_url, ampache_api, mode = 'random', filter = False, album = False, artist = False, flag = False, format = 'song', offset = 0, limit = 0, api_format = 'xml'):
    """
    ampache.playlist_generate(ampache_url, ampache_api, 'random', False, False,
                              False, False, 'song', 0, limit, api_format)

    ampache.playlist_generate(ampache_url, ampache_api, 'random', False, False,
                              False, False, 'index', 0, limit, api_format)

    ampache.playlist_generate(ampache_url, ampache_api, 'random', False, False,
                              False, False, 'id', 0, limit, api_format)
    """ rate
    def rate(ampache_url, ampache_api, type, id, rating, api_format = 'xml'):
    """
    #print(ampache.rate(ampache_url, ampache_api))
    """ record_play
    def record_play(ampache_url, ampache_api, id, user, client = 'AmpacheAPI', api_format = 'xml'):
    """
    #print(ampache.record_play(ampache_url, ampache_api))
    """ scrobble
    def scrobble(ampache_url, ampache_api, title, artist, album, MBtitle = False, MBartist = False, MBalbum = False, time = False, client = 'AmpacheAPI', api_format = 'xml'):
    """
    scrobble = ampache.scrobble(ampache_url, ampache_api, 'Hear.Life.Spoken',
                                'Sub Atari Knives',
                                'Sub Atari Knives', False, False, False,
                                int(time.time()), 'AmpaceApi', api_format)
    scrobble = ampache.scrobble(ampache_url, ampache_api,
                                'Welcome to Planet Sexor',
                                'Tiga', 'Sexor', False, False, False,
                                int(time.time()), 'test.py', api_format)
    """ search_songs
    def search_songs(ampache_url, ampache_api, filter, offset = 0, limit = 0, api_format = 'xml'):
    """
    search_songs = ampache.search_songs(ampache_url, ampache_api, song_title,
                                        0, 0, api_format)

    #if api_format == 'xml':
    #    for child in search_songs:
    #        print(child.tag, child.attrib)
    #        for subchildren in child:
    #            print(str(subchildren.tag) + ': ' + str(subchildren.text))
    """ song
    def song(ampache_url, ampache_api, filter, api_format = 'xml'):
    """
    song = ampache.song(ampache_url, ampache_api, single_song, api_format)

    #if api_format == 'xml':
    #    for child in song:
    #        #print(child.tag, child.attrib)
    #        #for subchildren in child:
    #        #    print(str(subchildren.tag) + ': ' + str(subchildren.text))
    """ songs
    def songs(ampache_url, ampache_api, filter = False, exact = False, add = False, update = False, offset = 0, limit = 0, api_format = 'xml'):
    """
    songs = ampache.songs(ampache_url, ampache_api, False, False, False, False,
                          0, 0, api_format)
    #if api_format == 'xml':
    #    for child in songs:
    #        #print(child.tag, child.attrib)
    #        #for subchildren in child:
    #        #    print(str(subchildren.tag) + ': ' + str(subchildren.text))
    """ tags
    def tags(ampache_url, ampache_api, filter = False, exact = False, offset = 0, limit = 0, api_format = 'xml'):
    """
    genre = ''
    tags = ampache.tags(ampache_url, ampache_api, 'Brutal Death Metal', '1', 0,
                        4, api_format)
    if api_format == 'xml':
        for child in tags:
            if child.tag == 'total_count':
                if int(child.text) > int(limit):
                    print(f"ampache.tags: {FAIL}FAIL{ENDC}")
                    sys.exit(f"\n{FAIL}ERROR:{ENDC} tags " + child.text +
                             ' found more items than the limit ' + str(limit))
                else:
                    continue
            #print(child.tag, child.attrib)
            genre = child.attrib['id']
            #for subchildren in child:
            #    print(str(subchildren.tag) + ': ' + str(subchildren.text))
    else:
        genre = tags[0]['tag']['id']
    """ tag
    def tag(ampache_url, ampache_api, filter, api_format = 'xml'):
    """
    tag = ampache.tag(ampache_url, ampache_api, genre, api_format)
    """ tag_albums
    def tag_albums(ampache_url, ampache_api, filter, offset = 0, limit = 0, api_format = 'xml'):
    """
    tag_albums = ampache.tag_albums(ampache_url, ampache_api, genre, 0, 2,
                                    api_format)
    #if api_format == 'xml':
    #    for child in tag_albums:
    #        #print(child.tag, child.attrib)
    #        #for subchildren in child:
    #        #    print(str(subchildren.tag) + ': ' + str(subchildren.text))
    """ tag_artists
    def tag_artists(ampache_url, ampache_api, filter, offset = 0, limit = 0, api_format = 'xml'):
    """
    tag_artists = ampache.tag_artists(ampache_url, ampache_api, genre, 0, 1,
                                      api_format)
    #if api_format == 'xml':
    #    for child in tag_artists:
    #        #print(child.tag, child.attrib)
    #        #for subchildren in child:
    #        #    print(str(subchildren.tag) + ': ' + str(subchildren.text))
    """ tag_songs
    def tag_songs(ampache_url, ampache_api, filter, offset = 0, limit = 0, api_format = 'xml'):
    """
    tag_songs = ampache.tag_songs(ampache_url, ampache_api, genre, 0, 1,
                                  api_format)
    """ timeline
    def timeline(ampache_url, ampache_api, username, limit = 0, since = 0, api_format = 'xml'):
    """
    timeline = ampache.timeline(ampache_url, ampache_api, ampache_user, 10, 0,
                                api_format)

    #if api_format == 'xml':
    #    for child in timeline:
    #        #print(child.tag, child.attrib)
    #        #for subchildren in child:
    #        #    print(str(subchildren.tag) + ': ' + str(subchildren.text))
    """ toggle_follow
    def toggle_follow(ampache_url, ampache_api, username, api_format = 'xml'):
    """
    toggle = 'generic'
    if ampache_user == 'generic':
        toggle = 'user'
    #togglefollow = ampache.toggle_follow(ampache_url, ampache_api, toggle, api_format))
    """ update_from_tags
    def update_from_tags(ampache_url, ampache_api, ampache_type, ampache_id, api_format = 'xml'):
    """
    update_from_tags = ampache.update_from_tags(ampache_url, ampache_api,
                                                'album', single_album,
                                                api_format)
    """ video
    def video(ampache_url, ampache_api, filter, api_format = 'xml'):
    """
    #print(ampache.video(ampache_url, ampache_api))
    """ videos
    def videos(ampache_url, ampache_api, filter = False, exact = False, offset = 0, limit = 0, api_format = 'xml'):
    """
    #print(ampache.videos(ampache_url, ampache_api))
    """ localplay
    def localplay(ampache_url, ampache_api, command, api_format = 'xml'):
    """
    #print(ampache.localplay(ampache_url, ampache_api))
    """ democratic
    def democratic(ampache_url, ampache_api, method, action, oid, api_format = 'xml'):
    """
    #print(ampache.democratic(ampache_url, ampache_api))
    """ goodbye
    def goodbye(ampache_url, ampache_api, api_format = 'xml'):
    """
    # Close your session when you're done
    goodbye = ampache.goodbye(ampache_url, ampache_api, api_format)
Beispiel #8
0
#!/usr/bin/env python3

import sys

import ampache

# user variables
ampache_url = 'https://music.server'
ampache_api = 'mysuperapikey'
ampache_user = '******'
"""
encrypt_string
"""
encrypted_key = ampache.encrypt_string(ampache_api, ampache_user)
"""
handshake
"""
# processed details
print('Connecting to:\n    ', ampache_url)
src_api = ampache_api
ampache_api = ampache.handshake(ampache_url, encrypted_key, False, False,
                                '400004', 'json')
print('\nThe ampache handshake for:\n    ', src_api,
      '\n\nReturned the following session key:\n    ', ampache_api)
if not ampache_api:
    print()
    sys.exit('ERROR: Failed to connect to ' + ampache_url)
def cache_playlist(ampache_url, ampache_api, ampache_user, api_format, smartlist, destination, transcode, limit):
    """ encrypt_string
    def encrypt_string(ampache_api, user):
    """
    encrypted_key = ampache.encrypt_string(ampache_api, ampache_user)

    """ handshake
    def handshake(ampache_url, ampache_api, user = False, timestamp = False, version = '420000', api_format = 'xml'):
    # processed details
    """
    ampache_session = ampache.handshake(ampache_url, encrypted_key, False, False, '420000', api_format)
    if not ampache_session:
        print()
        sys.exit('ERROR: Failed to connect to ' + ampache_url)

    """ ping
    def ping(ampache_url, ampache_api, api_format = 'xml'):
    # did all this work?
    """
    my_ping = ampache.ping(ampache_url, ampache_session, api_format)
    if not my_ping:
        print()
        sys.exit('ERROR: Failed to ping ' + ampache_url)

    """ set_debug
    def set_debug(mybool):
    """
    ampache.set_debug(False)

    """ advanced_search
    def advanced_search(ampache_url, ampache_api, rules, operator = 'and',
                        type = 'song', offset = 0, limit = 0, random = 0, api_format = 'xml'):
    """
    list_songs = list()
    search_rules = [['smartplaylist', 0, smartlist]]
    search_song = ampache.advanced_search(ampache_url, ampache_session,
                                          search_rules, 'or', 'song', 0, limit, 1, api_format)

    for child in search_song:
        if api_format == 'xml':
            if child.tag == 'song':
                list_songs.append([child.attrib['id'],
                                   os.path.basename(os.path.splitext(child.find('filename').text)[0] + '.' + transcode)])
        else:
            list_songs.append([child['id'], os.path.basename(os.path.splitext(child['filename'])[0] + '.' + transcode)])

    print(list_songs)
    
    """ download
    def download(ampache_url, ampache_api, object_id, object_type, destination, file_format='raw', api_format='xml'):
    """
    for object_id in list_songs:
        if not os.path.isfile(os.path.join(destination, object_id[1])):
            ampache.download(ampache_url, ampache_session, object_id[0],
                             'song', os.path.join(destination, object_id[1]), transcode, api_format)
        else:
            print('File exists')

    """ goodbye
    def goodbye(ampache_url, ampache_api, api_format = 'xml'):
    Close your session when you're done
    """
    ampache.goodbye(ampache_url, ampache_session, api_format)
Beispiel #10
0
#!/usr/bin/env python3

import sys

import ampache

# user variables
ampache_url = 'https://music.server'
ampache_api = 'mysuperapikey'
ampache_user = '******'

# xml or json supported formats
api_format = 'json'
"""
encrypt_string
"""
encrypted_key = ampache.encrypt_string(ampache_api, ampache_user)
"""
handshake
"""
print('Connecting to:\n    ', ampache_url)
src_api = ampache_api
ampache_api = ampache.handshake(ampache_url, encrypted_key, False, False,
                                '420000', api_format)

print('\nThe ampache handshake for:\n    ', src_api,
      '\n\nReturned the following session key:\n    ', ampache_api)
if not ampache_api:
    print()
    sys.exit('ERROR: Failed to connect to ' + ampache_url)