Skip to content

Commit

Permalink
Catch exceptions that can happen when playing internet radio
Browse files Browse the repository at this point in the history
  • Loading branch information
minneyar committed Oct 22, 2020
1 parent d435e28 commit 09bcf4f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.idea/
22 changes: 16 additions & 6 deletions clementine_discord.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env python3
# Copyright 2019 minneyar
# Copyright 2019-2020 minneyar
#
# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
# following conditions are met:
Expand Down Expand Up @@ -94,13 +94,23 @@ def update_loop(self):
tmp_metadata = dict()
for key, value in metadata.items():
tmp_metadata[key.replace(':', '-')] = value
details = DETAILS_STRING.format(**tmp_metadata)
try:
details = DETAILS_STRING.format(**tmp_metadata)
except KeyError:
self.logger.warning("Error getting song details:", exc_info=True)
self.logger.warning("You should customize the DETAILS_STRING in the script to use "
"appropriate metadata for your media.")
details = "(Error)"

if playback_status == 'Playing':
length_s = metadata['mpris:length'] / 1000000
time_now = time.time()
time_start = time_now - position_s
time_end = time_start + length_s
try:
length_s = metadata['mpris:length'] / 1000000
time_now = time.time()
time_start = time_now - position_s
time_end = time_start + length_s
except KeyError:
# Some media types may not provide length information; just ignore it
pass
self.logger.debug("Updating Discord.")
self.client.update(state=playback_status,
details=details,
Expand Down

0 comments on commit 09bcf4f

Please sign in to comment.