changed if's hell

This commit is contained in:
localhost_frssoft 2023-07-08 12:50:20 +03:00
parent ac73249396
commit 0fb4edc655
1 changed files with 31 additions and 30 deletions

View File

@ -54,15 +54,13 @@ if track_activity_history or scrobbler_to_fediverse_token != '':
# Here, _value is either None if nothing is playing or a float containing
# fractional seconds since the beginning of the file.
if value:
if value >= 30.0 and value <= 30.1:
track = player_fw_storage.storage.get(track_url_to_uuid())
time.sleep(0.100)
if value > 30.1:
time.sleep(1)
return
if value and src.fw_api.current_instance.token != None and player.pause is False:
if value >= 30.0 and value <= 30.1:
if value >= 30.0 and value <= 30.1 and player.pause is False:
# detect 30 secs for reporting listen activity
try:
track = player_fw_storage.storage.get(track_url_to_uuid())
except:
return
if src.fw_api.current_instance.token is not None:
track_id = track.get('id')
if track_id:
@ -70,8 +68,7 @@ if track_activity_history or scrobbler_to_fediverse_token != '':
src.fw_api.record_track_in_history(track_id)
else:
logger.error("Can't write track to history: No track id")
if value and scrobbler_to_fediverse_token != '' and player.pause is False:
if value >= 30.0 and value <= 30.1:
if scrobbler_to_fediverse_token != '':
fid = track.get('fid')
artist = track['artist'].get('name')
album = track['album'].get('title')
@ -88,6 +85,10 @@ if track_activity_history or scrobbler_to_fediverse_token != '':
requests.post(f'https://{scrobbler_to_fediverse_instance}/api/v1/statuses',
json=status_obj,
headers={'Authorization': f'Bearer {scrobbler_to_fediverse_token}'})
time.sleep(0.100)
if value > 30.1:
time.sleep(1)
return
def osd_observer(value):