def __init__(self):
        GObject.Object.__init__(self)
        RB.BrowserSource.__init__(self, name=_('ampache-fm'))
        self.ampache = ampache.API()
        self.ampache.set_format('json')
        self.plugin_info = 'ampache-fm'
        self.conf = configparser.RawConfigParser()
        self.configfile = RB.find_user_data_file(PLUGIN_PATH + CONFIGFILE)
        self.ui_file = RB.find_user_data_file(PLUGIN_PATH + UIFILE)
        self.shell = None
        self.rbdb = None
        self.db = None
        self.player = None
        self.source = None
        self.queue = None
        self.app = None
        self.elapsed_changed_id = None
        self.spinner = None

        # fields for current track
        self.nowtime = None
        self.nowtitle = None
        self.nowartist = None
        self.nowalbum = None
        self.nowMBtitle = None
        self.nowMBartist = None
        self.nowMBalbum = None

        # Fields for the last saved track to check against
        self.lasttime = None

        # ampache details
        self.ampache_url = None
        self.ampache_user = None
        self.ampache_apikey = None
        self.ampache_password = None
        self.ampache_session = False
示例#2
0
#!/usr/bin/env python3

import sys

import ampache

# user variables
ampache_url = 'https://develop.ampache.dev'
ampache_api = 'demodemo'
ampache_user = '******'

# xml or json supported formats
api_format = 'json'

ampacheConnection = ampache.API()
ampacheConnection.set_format(api_format)

"""
encrypt_string
"""
encrypted_key = ampacheConnection.encrypt_string(ampache_api, ampache_user)

"""
handshake
"""
print('Connecting to:\n    ', ampache_url)
src_api = ampache_api
ampache_api = ampacheConnection.handshake(ampache_url, encrypted_key, False, False, '420000')

print('\nThe ampache handshake for:\n    ', src_api, '\n\nReturned the following session key:\n    ', ampache_api)
if not ampache_api:
示例#3
0
    def __init__(self):
        """ start amPYche """
        print("\n##################\n"
              "# amPYche v" + VERSION + " #\n"
              "##################\n")
        check_config()
        self.conf = configparser.RawConfigParser()
        self.conf.read(CONFIG)
        self.ampache_url = self.conf.get('conf', 'ampache_url')
        self.ampache_user = self.conf.get('conf', 'ampache_user')
        self.ampache_apikey = self.conf.get('conf', 'ampache_apikey')
        self.ampache_session = self.conf.get('conf', 'ampache_session')
        self.api_format = self.conf.get('conf', 'api_format')
        self.ampacheConnection = ampache.API()
        self.ampacheConnection.set_format(self.api_format)

        # ping the last session to see if active
        my_ping = self.ampacheConnection.ping(self.ampache_url,
                                              self.ampache_session)
        if not my_ping:
            self.handshake()
        if not my_ping:
            print('CONNECTION ERROR')
            return

        # workaround for bugs
        if not self.ampacheConnection.AMPACHE_URL:
            self.ampacheConnection.AMPACHE_URL = self.ampache_url
        if not self.ampacheConnection.AMPACHE_SESSION:
            self.ampacheConnection.AMPACHE_SESSION = self.ampache_session

        # get your lists
        self.list_songs = list()
        if int(OID) > 0:
            if TYPE == 'playlist':
                self.playlist_songs(OID)
            if TYPE == 'song':
                song = self.ampacheConnection.song(OID)
                if self.api_format == 'xml':
                    for child in song:
                        if child.tag == 'song':
                            self.list_songs.append(child.attrib['id'])
                else:
                    for child in song:
                        self.list_songs.append(child['id'])
        # run your action
        if ACTION == 'ping':
            print("\nSESSION: " + self.ampacheConnection.ping(
                self.ampache_url, self.ampache_session))
        elif ACTION == 'configure':
            self.saveconf()
        elif ACTION == 'logout':
            self.quit()
        elif ACTION == 'showconfig':
            print("\nURL:     " + self.conf.get('conf', 'ampache_url'))
            print("USER:    "******"API_KEY: " + self.conf.get('conf', 'ampache_apikey'))
            print("SESSION: " + self.conf.get('conf', 'ampache_session'))
            print("FORMAT:  " + self.conf.get('conf', 'api_format') + "\n")
        elif ACTION == 'playlists':
            self.playlists()
        elif ACTION == 'localplay':
            for song_id in self.list_songs:
                if song_id:
                    self.localplay('add', song_id, 'song', 0)
            if COMMAND != 'add':
                result = self.localplay(COMMAND)
                if result:
                    for lines in result:
                        if self.api_format == 'xml':
                            print(lines[0] + ": " + lines[1])
                        else:
                            print(str(lines) + ": " + str(result[lines]))
        elif ACTION == 'download':
            if not os.path.isdir(DESTIN):
                os.makedirs(DESTIN)
            for song_id in self.list_songs:
                if song_id and os.path.isdir(os.path.dirname(DESTIN)):
                    self.download(song_id, DESTIN, TRANSCODE)
        elif ACTION == 'stream':
            for song_id in self.list_songs:
                if song_id:
                    self.stream(song_id, TRANSCODE)
        return
示例#4
0
def cache_playlist(ampache_url, ampache_api, ampache_user, api_format,
                   smartlist, destination, transcode, limit):
    ampacheConnection = ampache.API()
    ampacheConnection.set_format(api_format)
    """ encrypt_string
    def encrypt_string(ampache_api, user):
    """
    encrypted_key = ampacheConnection.encrypt_string(ampache_api, ampache_user)
    """ handshake
    def handshake(ampache_url, ampache_api, user = False, timestamp = False, version = '420000'):
    # processed details
    """
    ampache_session = ampacheConnection.handshake(ampache_url, encrypted_key,
                                                  False, False, '420000')
    if not ampache_session:
        print()
        sys.exit('ERROR: Failed to connect to ' + ampache_url)
    """ ping
    def ping(ampache_url, ampache_api):
    # did all this work?
    """
    my_ping = ampacheConnection.ping(ampache_url, ampache_session)
    if not my_ping:
        print()
        sys.exit('ERROR: Failed to ping ' + ampache_url)
    """ set_debug
    def set_debug(mybool):
    """
    ampacheConnection.set_debug(False)
    """ advanced_search
    def advanced_search(ampache_url, ampache_api, rules, operator = 'and',
                        type = 'song', offset = 0, limit = 0, random = 0):
    """
    list_songs = list()
    search_rules = [['smartplaylist', 0, smartlist]]
    search_song = ampacheConnection.advanced_search(search_rules, 'or', 'song',
                                                    0, limit, 1)

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

    print(list_songs)
    """ download
    def download(ampache_url, ampache_api, object_id, object_type, destination, file_format='raw'):
    """
    for object_id in list_songs:
        if not os.path.isfile(os.path.join(destination, object_id[1])):
            ampacheConnection.download(object_id[0], 'song',
                                       os.path.join(destination, object_id[1]),
                                       transcode)
        else:
            print('File exists')
    """ goodbye
    def goodbye(ampache_url, ampache_api):
    Close your session when you're done
    """
    ampacheConnection.goodbye()