[~] Refactor

This commit is contained in:
Siarhei Siniak 2024-05-05 10:55:35 +03:00
parent 78f558be80
commit c054da7ddf

@ -1659,9 +1659,12 @@ def scrap_yt_music(argv):
]) ])
def http_on_event(event, events): def http_on_event(event, events):
if 'title' in event: with context['track_cv']:
with context['track_cv']: if 'title' in event and event['title'].strip() != '':
context['track_name'] = str(event['title'])[:128].replace('\n', '') context['track_name'] = str(event['title'])[:128].replace('\n', '')
else:
context['track_name'] = None
logging.info(event) logging.info(event)
context['http_on_event'] = http_on_event context['http_on_event'] = http_on_event
@ -1672,20 +1675,28 @@ def scrap_yt_music(argv):
Open Youtube Music, Open Youtube Music,
and launch the following JS script: and launch the following JS script:
```js ```js
if (timer !== undefined)
{
clearInterval(timer);
}
timer = setInterval(
function(){ (function(){
fetch( let timer = null;
'http://127.0.0.1:8877/status?title=' + timer = setInterval(function(){
encodeURI($$('.ytmusic-player-bar.middle-controls')[0].innerText) let is_playing = () => $$('#play-pause-button')[0].title == 'Pause';
); let title = () => encodeURIComponent($$('.ytmusic-player-bar.middle-controls')[0].innerText);
}, let update_status = (query) => fetch('http://127.0.0.1:8877/status?' + query);
5000
); if (is_playing())
{
update_status('title=' + title());
}
else
{
update_status('')
clearInterval(timer);
}
},
1000
);
})();
``` ```
''') ''')