|
@ -80,7 +80,6 @@ def parse_library(headers, tracks, library_stats, user): |
|
|
|
|
|
|
|
|
# save_track_obj {{{ # |
|
|
# save_track_obj {{{ # |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def save_track_obj(track_dict, artists, user): |
|
|
def save_track_obj(track_dict, artists, user): |
|
|
"""Make an entry in the database for this track if it doesn't exist already. |
|
|
"""Make an entry in the database for this track if it doesn't exist already. |
|
|
|
|
|
|
|
@ -91,7 +90,11 @@ def save_track_obj(track_dict, artists, user): |
|
|
|
|
|
|
|
|
""" |
|
|
""" |
|
|
print(track_dict['name']) |
|
|
print(track_dict['name']) |
|
|
new_track, created = Track.objects.get_or_create( |
|
|
|
|
|
|
|
|
track_query = Track.objects.filter(track_id__exact=track_dict['id']) |
|
|
|
|
|
if len(track_query) != 0: |
|
|
|
|
|
return track_query[0], False |
|
|
|
|
|
else: |
|
|
|
|
|
new_track = Track.objects.create( |
|
|
track_id=track_dict['id'], |
|
|
track_id=track_dict['id'], |
|
|
year=track_dict['album']['release_date'].split('-')[0], |
|
|
year=track_dict['album']['release_date'].split('-')[0], |
|
|
popularity=int(track_dict['popularity']), |
|
|
popularity=int(track_dict['popularity']), |
|
@ -101,12 +104,11 @@ def save_track_obj(track_dict, artists, user): |
|
|
|
|
|
|
|
|
# have to add artists and user after saving object since track needs to |
|
|
# have to add artists and user after saving object since track needs to |
|
|
# have ID before filling in m2m field |
|
|
# have ID before filling in m2m field |
|
|
if created: |
|
|
|
|
|
for artist in artists: |
|
|
for artist in artists: |
|
|
new_track.artists.add(artist) |
|
|
new_track.artists.add(artist) |
|
|
new_track.users.add(user) |
|
|
new_track.users.add(user) |
|
|
new_track.save() |
|
|
new_track.save() |
|
|
return new_track, created |
|
|
|
|
|
|
|
|
return new_track, True |
|
|
|
|
|
|
|
|
# }}} save_track_obj # |
|
|
# }}} save_track_obj # |
|
|
|
|
|
|
|
|