changed if's hell

This commit is contained in:
localhost_frssoft 2023-07-08 12:50:20 +03:00
parent ac73249396
commit 0fb4edc655

View File

@ -54,40 +54,41 @@ 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())
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:
if track_activity_history:
src.fw_api.record_track_in_history(track_id)
else:
logger.error("Can't write track to history: No track id")
if scrobbler_to_fediverse_token != '':
fid = track.get('fid')
artist = track['artist'].get('name')
album = track['album'].get('title')
title = track.get('title')
tags = track.get('tags')
if tags:
tags = [f'#{tag}' for tag in tags]
tags = ' '.join(tags)
if tags == []:
tags = ''
status_obj = {'spoiler_text': 'funkwhale-cli music scrobbler',
'visibility': 'unlisted',
'status': f'🎧 {artist} - {album} - {title}\n{fid}\n#NowPlaying {tags}'}
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
if value and src.fw_api.current_instance.token != None and player.pause is False:
if value >= 30.0 and value <= 30.1:
# detect 30 secs for reporting listen activity
track_id = track.get('id')
if track_id:
if track_activity_history:
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:
fid = track.get('fid')
artist = track['artist'].get('name')
album = track['album'].get('title')
title = track.get('title')
tags = track.get('tags')
if tags:
tags = [f'#{tag}' for tag in tags]
tags = ' '.join(tags)
if tags == []:
tags = ''
status_obj = {'spoiler_text': 'funkwhale-cli music scrobbler',
'visibility': 'unlisted',
'status': f'🎧 {artist} - {album} - {title}\n{fid}\n#NowPlaying {tags}'}
requests.post(f'https://{scrobbler_to_fediverse_instance}/api/v1/statuses',
json=status_obj,
headers={'Authorization': f'Bearer {scrobbler_to_fediverse_token}'})
def osd_observer(value):