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
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Robert Goldmann
SpotifyBackup
Commits
44571bdb
Commit
44571bdb
authored
1 year ago
by
Robert Goldmann
Browse files
Options
Downloads
Patches
Plain Diff
SpotifyRecorder: print summary of skipped and error track numbers
parent
0fe7879b
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
SpotifyRecorder.py
+26
-14
26 additions, 14 deletions
SpotifyRecorder.py
with
26 additions
and
14 deletions
SpotifyRecorder.py
+
26
−
14
View file @
44571bdb
...
...
@@ -85,27 +85,29 @@ class SpotifyRecorder:
def
__record_tracks
(
self
,
tracks
:
list
):
deviceId
=
self
.
__get_device_id_by_name
(
self
.
_spotifyDeviceName
)
recordedTracks
=
[]
skippedTracks
=
[]
errorTracks
=
[]
recordedTrack
Number
s
=
[]
skippedTrack
Number
s
=
[]
errorTrack
Number
s
=
[]
if
self
.
_limit
==
-
1
:
LOGGER
.
info
(
f
'
Recording track #
{
self
.
_startNumber
}
to all
'
)
tracks
=
tracks
[
self
.
_startNumber
:]
tracks
=
tracks
[
self
.
_startNumber
-
1
:]
else
:
LOGGER
.
info
(
f
'
Recording track #
{
self
.
_startNumber
}
to (including) #
{
self
.
_startNumber
+
self
.
_limit
-
1
}
'
)
tracks
=
tracks
[
self
.
_startNumber
:
self
.
_startNumber
+
self
.
_limit
]
tracks
=
tracks
[
self
.
_startNumber
-
1
:
self
.
_startNumber
-
1
+
self
.
_limit
]
for
index
,
track
in
enumerate
(
tracks
):
indexInPlaylist
=
self
.
_startNumber
+
index
if
track
[
'
is_local
'
]:
# It's not possible to add a local track to a playlist using the web API.
# https://github.com/plamere/spotipy/issues/793#issuecomment-1082421408
LOGGER
.
info
(
f
'
Skipping local track
"
{
track
[
"
track
"
][
"
name
"
]
}
"'
)
skippedTracks
.
append
(
track
[
'
track
'
][
'
name
'
]
)
skippedTrack
Number
s
.
append
(
indexInPlaylist
)
continue
indexInPlaylist
=
self
.
_startNumber
+
index
LOGGER
.
info
(
f
'
>>> Recording track
{
index
+
1
}
/
{
len
(
tracks
)
}
: #
{
indexInPlaylist
}
"
{
track
[
"
track
"
][
"
name
"
]
}
"
...
'
)
LOGGER
.
info
(
f
'
>>> Recording track
{
index
+
1
}
/
{
len
(
tracks
)
}
: #
{
indexInPlaylist
}
"
{
track
[
"
track
"
][
"
name
"
]
}
"
...
'
)
try
:
filePath
=
self
.
__determine_file_path
(
indexInPlaylist
+
1
,
track
)
recorder
=
SpotifyAudioRecorder
(
self
.
_audioDeviceName
,
filePath
)
...
...
@@ -114,13 +116,23 @@ class SpotifyRecorder:
timeWaitedForPlaying
=
self
.
__wait_for_track_playing
(
track
[
'
track
'
][
'
id
'
])
self
.
__wait_for_track_end
(
track
,
timeWaitedForPlaying
)
recordedTracks
.
append
(
track
[
'
track
'
][
'
name
'
]
)
recordedTrack
Number
s
.
append
(
indexInPlaylist
)
except
Exception
as
e
:
LOGGER
.
error
(
f
'
An error occurred while recording track
"
{
track
[
"
track
"
][
"
name
"
]
}
"'
,
exc_info
=
e
)
errorTracks
.
append
(
track
[
'
track
'
][
'
name
'
]
)
errorTrack
Number
s
.
append
(
indexInPlaylist
)
LOGGER
.
info
(
'
### DONE ###
'
)
LOGGER
.
info
(
f
'
{
len
(
tracks
)
}
tracks,
{
len
(
recordedTracks
)
}
recorded,
{
len
(
skippedTracks
)
}
skipped,
{
len
(
errorTracks
)
}
errors
'
)
LOGGER
.
info
(
'
>>> Skipped <<<
'
)
for
number
in
skippedTrackNumbers
:
LOGGER
.
info
(
f
'
Skipped #
{
number
}
'
)
LOGGER
.
info
(
'
>>> Errors <<<
'
)
for
number
in
errorTrackNumbers
:
LOGGER
.
info
(
f
'
Error #
{
number
}
'
)
LOGGER
.
info
(
f
'
###
{
len
(
tracks
)
}
tracks,
{
len
(
recordedTrackNumbers
)
}
recorded,
{
len
(
skippedTrackNumbers
)
}
skipped,
{
len
(
errorTrackNumbers
)
}
errors ###
'
)
def
__determine_file_path
(
self
,
index
:
int
,
track
)
->
str
:
artists
=
track
[
'
track
'
][
'
artists
'
]
...
...
@@ -179,7 +191,7 @@ class SpotifyRecorder:
raise
RuntimeError
(
'
Device not found
'
)
def
__play_track
(
self
,
deviceId
:
str
,
trackUri
:
str
):
def
__play_track
(
self
,
deviceId
:
str
,
trackUri
:
str
)
->
None
:
self
.
_spotify
.
start_playback
(
device_id
=
deviceId
,
uris
=
[
trackUri
])
def
__wait_for_track_playing
(
self
,
expectedTrackId
:
str
)
->
float
:
...
...
@@ -194,7 +206,7 @@ class SpotifyRecorder:
LOGGER
.
debug
(
f
'
\t\t
Track started playing after
{
duration
:
.
1
f
}
s
'
)
break
else
:
raise
RuntimeError
(
'
Wrong track started playing
'
)
raise
RuntimeError
(
f
'
Wrong track started playing
(actual:
{
currentPlayback
[
"
item
"
][
"
id
"
]
}
, expected:
{
expectedTrackId
}
)
'
)
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