Skip to content

Commit

Permalink
[#1] skip songs without a location also for the counts-ratings-command
Browse files Browse the repository at this point in the history
  • Loading branch information
phauer committed Sep 28, 2016
1 parent f0138fd commit a9af149
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
6 changes: 4 additions & 2 deletions TODO.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
- add tests for remote songs
- extend pyItunes: Add to Song: Track Type ("File" vs "Remote"). optionally Purchased (None vs True) and Matched (None vs True)
- #1
- centralize validation and error message
- add tests for remote songs. also for counts-ratings
- extend pyItunes: Add to Song: Track Type ("File" vs "Remote"). optionally Purchased (None vs True) and Matched (None vs True)
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,17 @@ def create_itunes_statistic_dict(itunes_songs: Dict[int, Song], itunes_library_r
"""use canonical location as a common identifier. returns dict[canonical_location -> SongStatistic(play_count, rating)]"""
dict = {}
for itunes_song in itunes_songs.values():
count = itunes_song.play_count
last_played = itunes_song.lastplayed
last_played_timestamp = calendar.timegm(last_played) if last_played is not None else None
itunes_rating = itunes_song.rating
mapped_rating = ITUNES_TO_RHYTHMBOX_RATINGS_MAP[itunes_rating]
location = itunes_song.location_escaped
canonical_location = location.replace("file://localhost/{}".format(itunes_library_root), "")
dict[canonical_location] = SongStatistic(count, mapped_rating, last_played_timestamp)
if itunes_song.location_escaped is not None:
count = itunes_song.play_count
last_played = itunes_song.lastplayed
last_played_timestamp = calendar.timegm(last_played) if last_played is not None else None
itunes_rating = itunes_song.rating
mapped_rating = ITUNES_TO_RHYTHMBOX_RATINGS_MAP[itunes_rating]
location = itunes_song.location_escaped
canonical_location = location.replace("file://localhost/{}".format(itunes_library_root), "")
dict[canonical_location] = SongStatistic(count, mapped_rating, last_played_timestamp)
else:
print(" Can't assign the track [{} - {}] because there is no file location defined. It's probably a remote file."
.format(itunes_song.artist, itunes_song.name))
return dict

0 comments on commit a9af149

Please sign in to comment.