Skip to content

Commit

Permalink
Update ampache-fm.py
Browse files Browse the repository at this point in the history
update for Ampache 5
  • Loading branch information
lachlan-00 committed Aug 23, 2021
1 parent 571f84c commit 9cbbc9f
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions ampache-fm.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
"""

import ampache
import codecs
import configparser
import csv
Expand All @@ -28,7 +29,6 @@
import shutil
import time

import ampache

gi.require_version('Peas', '1.0')
gi.require_version('PeasGtk', '1.0')
Expand Down Expand Up @@ -134,6 +134,10 @@ def ampache_auth(self, key):
if key:
ping = self.ampache.ping(self.ampache_url, key)
if ping:
if not self.ampache.AMPACHE_URL:
self.ampache.AMPACHE_URL = self.ampache_url
if not self.ampache.AMPACHE_SESSION:
self.ampache.AMPACHE_SESSION = self.ampache_session
# ping successful
self.ampache_session = ping
return ping
Expand All @@ -145,6 +149,10 @@ def ampache_auth(self, key):
auth = self.ampache.handshake(self.ampache_url, self.ampache.encrypt_string(self.ampache_apikey, self.ampache_user))
if auth:
print('handshake successful')
if not self.ampache.AMPACHE_URL:
self.ampache.AMPACHE_URL = self.ampache_url
if not self.ampache.AMPACHE_SESSION:
self.ampache.AMPACHE_SESSION = self.ampache_session
self.ampache_session = auth
return auth
return False
Expand Down Expand Up @@ -180,7 +188,7 @@ def cache_now_playing(self):
if self._check_session():
print('Sending scrobble to Ampache: ' + self.nowtitle)
Process(target=self.ampache.scrobble,
args=(self.ampache_url, self.ampache_session, self.nowtitle, self.nowartist, self.nowalbum,
args=(self.nowtitle, self.nowartist, self.nowalbum,
self.nowMBtitle, self.nowMBartist, self.nowMBalbum,
self.nowtime, 'AmpacheFM Rhythmbox')).start()
# Log track details in last.fm format
Expand Down Expand Up @@ -371,7 +379,7 @@ def backfill(self):
if self._check_session():
print('Sending scrobble to Ampache: ' + str(rowtrack))
Process(target=self.ampache.scrobble,
args=(self.ampache_url, self.ampache_session, str(rowtrack), str(rowartist),
args=(str(rowtrack), str(rowartist),
str(rowalbum),
str(trackmbid).replace("None", ""), str(artistmbid).replace("None", ""),
str(albummbid).replace("None", ""),
Expand Down

0 comments on commit 9cbbc9f

Please sign in to comment.