[~] Refactor

This commit is contained in:
Siarhei Siniak 2024-05-11 11:41:02 +03:00
parent c054da7ddf
commit d80801192a

@ -1612,7 +1612,7 @@ def scrap_yt_music(argv):
if context['shutdown']: if context['shutdown']:
if not p is None: if not p is None:
p.terminate() p.terminate()
break break
if p is None and not current_name is None: if p is None and not current_name is None:
output_name = os.path.join( output_name = os.path.join(
@ -1679,24 +1679,35 @@ def scrap_yt_music(argv):
(function(){ (function(){
let timer = null; let timer = null;
timer = setInterval(function(){ let is_first = true;
let is_playing = () => $$('#play-pause-button')[0].title == 'Pause'; let last_play = null;
let title = () => encodeURIComponent($$('.ytmusic-player-bar.middle-controls')[0].innerText); function last_play_update() {last_play = (new Date());}
let update_status = (query) => fetch('http://127.0.0.1:8877/status?' + query); let should_stop = () => (((new Date()).valueOf() - last_play.valueOf()) > 5 * 1000);
timer = setInterval(() => {
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);
if (is_playing()) if (is_playing())
{
last_play_update();
is_first = false;
update_status('title=' + title());
}
else if (!is_first)
{
update_status('')
if (should_stop())
{ {
update_status('title=' + title()); console.log('should stop');
clearInterval(timer);
} }
else }
{ }, 1000);
update_status('')
clearInterval(timer);
}
},
1000
);
})(); })();
``` ```
''') ''')