Skip to content

Commit

Permalink
Move playlist counter increase to stop_blocking() to prevent too many…
Browse files Browse the repository at this point in the history
… triggers
  • Loading branch information
thescooby committed Feb 17, 2021
1 parent 6b0dab4 commit feb2324
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions spotrec.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@
_shell_executable = "/bin/bash" # Default: "/bin/sh"
_shell_encoding = "utf-8"
_ffmpeg_executable = "ffmpeg" # Example: "/usr/bin/ffmpeg"
_pl_track_counter = 1

# Variables that change during runtime
is_script_paused = False
is_first_playing = True
pa_spotify_sink_input_id = -1
pl_track_counter = 1


def main():
Expand Down Expand Up @@ -352,16 +352,12 @@ def run(self):

# This gets called whenever Spotify sends the playingUriChanged signal
def on_playing_uri_changed(self, Player, three, four):
global _pl_track_counter
#log.debug("uri changed event")

# Update Metadata
self.update_metadata()

if _use_pl_track_counter:
_pl_track_counter += 1

# Update track & trackid
# Update track & trackid

self.trackid2 = self.metadata.get(dbus.String(u'mpris:trackid'))
if self.trackid != self.trackid2:
Expand Down Expand Up @@ -392,6 +388,8 @@ def playbackstatus_changed(self):
self.init_pa_stuff_if_needed()

def update_metadata(self):
global pl_track_counter

self.metadata = self.iface.Get(self.mpris_player_string, "Metadata")

self.metadata_artist = ", ".join(
Expand All @@ -401,7 +399,7 @@ def update_metadata(self):
self.metadata_trackNumber = str(self.metadata.get(
dbus.String(u'xesam:trackNumber'))).zfill(2)
if _use_pl_track_counter:
self.metadata_trackNumber = str(_pl_track_counter).zfill(3)
self.metadata_trackNumber = str(pl_track_counter).zfill(3)


def init_pa_stuff_if_needed(self):
Expand Down Expand Up @@ -457,6 +455,8 @@ def record(self, filename, metadata_for_file={}):

# The blocking version of this method waits until the process is dead
def stop_blocking(self):
global pl_track_counter

# Remove from instances list (and terminate)
if self in self.instances:
self.instances.remove(self)
Expand Down Expand Up @@ -491,6 +491,10 @@ def stop_blocking(self):
# Remove process from memory (and don't left a ffmpeg 'zombie' process)
self.process = None

# Update playlist counter here to get rid of too many triggers for counting
if _use_pl_track_counter:
pl_track_counter += 1

# Kill the process in the background
def stop(self):
class KillThread(Thread):
Expand Down

0 comments on commit feb2324

Please sign in to comment.