mirror of
https://code.eliotberriot.com/funkwhale/funkwhale.git
synced 2025-10-05 00:59:17 +02:00
See #297: linting of various, uncommon errors
This commit is contained in:
parent
ab80dffeea
commit
d17ceec1f0
29 changed files with 39 additions and 109 deletions
|
@ -1,12 +1,6 @@
|
|||
import os
|
||||
|
||||
import acoustid
|
||||
from django.core.files import File
|
||||
from django.db import transaction
|
||||
|
||||
from funkwhale_api.music import metadata, models
|
||||
from funkwhale_api.providers.acoustid import get_acoustid_client
|
||||
from funkwhale_api.taskapp import celery
|
||||
|
||||
|
||||
@transaction.atomic
|
||||
|
@ -49,33 +43,3 @@ def import_track_data_from_path(path):
|
|||
defaults={"title": data.get("title"), "position": position},
|
||||
)[0]
|
||||
return track
|
||||
|
||||
|
||||
def import_metadata_with_musicbrainz(path):
|
||||
pass
|
||||
|
||||
|
||||
@celery.app.task(name="audiofile.from_path")
|
||||
def from_path(path):
|
||||
acoustid_track_id = None
|
||||
try:
|
||||
client = get_acoustid_client()
|
||||
result = client.get_best_match(path)
|
||||
acoustid_track_id = result["id"]
|
||||
except acoustid.WebServiceError:
|
||||
track = import_track_data_from_path(path)
|
||||
except (TypeError, KeyError):
|
||||
track = import_metadata_without_musicbrainz(path)
|
||||
else:
|
||||
track, created = models.Track.get_or_create_from_api(
|
||||
mbid=result["recordings"][0]["id"]
|
||||
)
|
||||
|
||||
if track.files.count() > 0:
|
||||
raise ValueError("File already exists for track {}".format(track.pk))
|
||||
|
||||
track_file = models.TrackFile(track=track, acoustid_track_id=acoustid_track_id)
|
||||
track_file.audio_file.save(os.path.basename(path), File(open(path, "rb")))
|
||||
track_file.save()
|
||||
|
||||
return track_file
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue