Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
SpotifyBackup
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Robert Goldmann
SpotifyBackup
Commits
4c77e89e
Commit
4c77e89e
authored
1 year ago
by
Robert Goldmann
Browse files
Options
Downloads
Patches
Plain Diff
SpotifyRecorder: adjust sleep time according to remaining track duration
parent
582d75f2
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
SpotifyRecorder.py
+12
-14
12 additions, 14 deletions
SpotifyRecorder.py
with
12 additions
and
14 deletions
SpotifyRecorder.py
+
12
−
14
View file @
4c77e89e
...
@@ -15,7 +15,6 @@ LOGGER = DefaultLogger().create_logger_if_not_exists('SpotifyRecorder', logForma
...
@@ -15,7 +15,6 @@ LOGGER = DefaultLogger().create_logger_if_not_exists('SpotifyRecorder', logForma
class
SpotifyRecorder
:
class
SpotifyRecorder
:
_MAX_WAIT_TIME_TRACK_STARTING_IN_S
=
10
_MAX_WAIT_TIME_TRACK_STARTING_IN_S
=
10
_WAIT_TIME_TRACK_PLAYING_IN_S
=
10
_WAIT_TIME_TRACK_PLAYING_SHORT_IN_S
=
1
_WAIT_TIME_TRACK_PLAYING_SHORT_IN_S
=
1
_THRESHOLD_TRACK_END_IN_MS
=
5000
_THRESHOLD_TRACK_END_IN_MS
=
5000
...
@@ -132,25 +131,24 @@ class SpotifyRecorder:
...
@@ -132,25 +131,24 @@ class SpotifyRecorder:
currentPlayback
=
self
.
_spotify
.
current_playback
()
currentPlayback
=
self
.
_spotify
.
current_playback
()
if
currentPlayback
[
'
is_playing
'
]:
if
currentPlayback
[
'
is_playing
'
]:
remainingTimeInMs
=
trackDurationInMs
-
currentPlayback
[
'
progress_ms
'
]
remainingTimeInMs
=
trackDurationInMs
-
currentPlayback
[
'
progress_ms
'
]
remainingTimeInSeconds
=
remainingTimeInMs
//
1000
sleepTime
=
self
.
_WAIT_TIME_TRACK_PLAYING_SHORT_IN_S
if
remainingTimeInMs
>
self
.
_THRESHOLD_TRACK_END_IN_MS
:
sleepTime
=
remainingTimeInSeconds
/
2
if
remainingTimeInMs
<
self
.
_THRESHOLD_TRACK_END_IN_MS
:
LOGGER
.
debug
(
f
'
Waiting for track to end (remaining:
'
f
'
{
self
.
__convert_seconds_to_duration
(
remainingTimeInMs
//
1000
)
}
,
'
f
'
sleep:
{
self
.
_WAIT_TIME_TRACK_PLAYING_SHORT_IN_S
}
s)...
'
)
time
.
sleep
(
self
.
_WAIT_TIME_TRACK_PLAYING_SHORT_IN_S
)
else
:
LOGGER
.
debug
(
f
'
Waiting for track to end (remaining:
'
LOGGER
.
debug
(
f
'
Waiting for track to end (remaining:
'
f
'
{
self
.
__convert_seconds_to_duration
(
remainingTimeInMs
//
1000
)
}
,
'
f
'
{
self
.
__convert_seconds_to_duration
(
remainingTimeInSeconds
)
}
,
'
f
'
sleep:
{
self
.
_WAIT_TIME_TRACK_PLAYING_IN_S
}
s)...
'
)
f
'
sleep:
{
self
.
__convert_seconds_to_duration
(
sleepTime
)
}
s)...
'
)
time
.
sleep
(
self
.
_WAIT_TIME_TRACK_PLAYING_IN_S
)
time
.
sleep
(
sleepTime
)
continue
else
:
else
:
waitDuration
=
int
(
time
.
time
()
-
startTime
)
waitDuration
=
int
(
time
.
time
()
-
startTime
)
if
waitDuration
<
trackDurationInSeconds
:
if
waitDuration
<
trackDurationInSeconds
:
raise
RuntimeError
(
raise
RuntimeError
(
f
'
Track finished too early (waited:
{
waitDuration
}
s, expected:
{
trackDurationInSeconds
}
s)
'
)
f
'
Track finished too early (waited:
{
waitDuration
}
s, expected:
{
trackDurationInSeconds
}
s)
'
)
if
waitDuration
>
trackDurationInSeconds
+
self
.
_WAIT_TIME_TRACK_PLAYING_
IN_S
:
if
waitDuration
>
trackDurationInSeconds
+
self
.
_WAIT_TIME_TRACK_PLAYING_
SHORT_IN_S
*
3
:
raise
RuntimeError
(
raise
RuntimeError
(
f
'
Track finished too late (waited:
{
waitDuration
}
s, expected:
{
trackDurationInSeconds
}
)
'
)
f
'
Track finished too late (waited:
{
waitDuration
}
s, expected:
{
trackDurationInSeconds
}
)
'
)
...
@@ -180,7 +178,7 @@ class SpotifyRecorder:
...
@@ -180,7 +178,7 @@ class SpotifyRecorder:
startTime
=
time
.
time
()
startTime
=
time
.
time
()
while
time
.
time
()
-
startTime
<
self
.
_MAX_WAIT_TIME_TRACK_STARTING_IN_S
:
while
time
.
time
()
-
startTime
<
self
.
_MAX_WAIT_TIME_TRACK_STARTING_IN_S
:
if
self
.
_spotify
.
current_playback
()[
'
is_playing
'
]:
if
self
.
_spotify
.
current_playback
()[
'
is_playing
'
]:
LOGGER
.
debug
(
f
'
Track started playing after
{
time
.
time
()
-
startTime
}
s
'
)
LOGGER
.
debug
(
f
'
Track started playing after
{
time
.
time
()
-
startTime
:
.
1
f
}
s
'
)
break
break
time
.
sleep
(
1
)
time
.
sleep
(
1
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment