mirror of
https://code.eliotberriot.com/funkwhale/funkwhale.git
synced 2025-10-05 17:28:12 +02:00
Resolve "Tagging artists/albums genres when importing music files"
This commit is contained in:
parent
7b0db234e2
commit
aea8e4fc59
12 changed files with 333 additions and 0 deletions
|
@ -14,7 +14,9 @@ from requests.exceptions import RequestException
|
|||
from funkwhale_api.common import channels, preferences
|
||||
from funkwhale_api.federation import routes
|
||||
from funkwhale_api.federation import library as lb
|
||||
from funkwhale_api.federation import utils as federation_utils
|
||||
from funkwhale_api.tags import models as tags_models
|
||||
from funkwhale_api.tags import tasks as tags_tasks
|
||||
from funkwhale_api.taskapp import celery
|
||||
|
||||
from . import licenses
|
||||
|
@ -668,6 +670,50 @@ def clean_transcoding_cache():
|
|||
return candidates.delete()
|
||||
|
||||
|
||||
@celery.app.task(name="music.albums_set_tags_from_tracks")
|
||||
@transaction.atomic
|
||||
def albums_set_tags_from_tracks(ids=None, dry_run=False):
|
||||
qs = models.Album.objects.filter(tagged_items__isnull=True).order_by("id")
|
||||
qs = federation_utils.local_qs(qs)
|
||||
qs = qs.values_list("id", flat=True)
|
||||
if ids is not None:
|
||||
qs = qs.filter(pk__in=ids)
|
||||
data = tags_tasks.get_tags_from_foreign_key(
|
||||
ids=qs, foreign_key_model=models.Track, foreign_key_attr="album",
|
||||
)
|
||||
logger.info("Found automatic tags for %s albums…", len(data))
|
||||
if dry_run:
|
||||
logger.info("Running in dry-run mode, not commiting")
|
||||
return
|
||||
|
||||
tags_tasks.add_tags_batch(
|
||||
data, model=models.Album,
|
||||
)
|
||||
return data
|
||||
|
||||
|
||||
@celery.app.task(name="music.artists_set_tags_from_tracks")
|
||||
@transaction.atomic
|
||||
def artists_set_tags_from_tracks(ids=None, dry_run=False):
|
||||
qs = models.Artist.objects.filter(tagged_items__isnull=True).order_by("id")
|
||||
qs = federation_utils.local_qs(qs)
|
||||
qs = qs.values_list("id", flat=True)
|
||||
if ids is not None:
|
||||
qs = qs.filter(pk__in=ids)
|
||||
data = tags_tasks.get_tags_from_foreign_key(
|
||||
ids=qs, foreign_key_model=models.Track, foreign_key_attr="artist",
|
||||
)
|
||||
logger.info("Found automatic tags for %s artists…", len(data))
|
||||
if dry_run:
|
||||
logger.info("Running in dry-run mode, not commiting")
|
||||
return
|
||||
|
||||
tags_tasks.add_tags_batch(
|
||||
data, model=models.Artist,
|
||||
)
|
||||
return data
|
||||
|
||||
|
||||
def get_prunable_tracks(
|
||||
exclude_favorites=True, exclude_playlists=True, exclude_listenings=True
|
||||
):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue