[music] Add albums to tracks and utility to condense tracks
This commit is contained in:
@ -2,17 +2,17 @@ import hashlib
|
||||
import logging
|
||||
import re
|
||||
from datetime import datetime, timedelta, tzinfo
|
||||
from sqlite3 import IntegrityError
|
||||
from urllib.parse import urlparse
|
||||
|
||||
import pytz
|
||||
from django.apps import apps
|
||||
from django.contrib.auth import get_user_model
|
||||
from django.db import models, transaction
|
||||
from django.db import models
|
||||
from django.utils import timezone
|
||||
from profiles.models import UserProfile
|
||||
from profiles.utils import now_user_timezone
|
||||
from scrobbles.constants import LONG_PLAY_MEDIA
|
||||
from scrobbles.notifications import NtfyNotification
|
||||
from scrobbles.tasks import (
|
||||
process_koreader_import,
|
||||
process_lastfm_import,
|
||||
@ -20,8 +20,6 @@ from scrobbles.tasks import (
|
||||
)
|
||||
from webdav.client import get_webdav_client
|
||||
|
||||
from vrobbler.apps.scrobbles.notifications import NtfyNotification
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
User = get_user_model()
|
||||
|
||||
@ -275,36 +273,6 @@ def get_file_md5_hash(file_path: str) -> str:
|
||||
return file_hash.hexdigest()
|
||||
|
||||
|
||||
def deduplicate_tracks(commit=False) -> int:
|
||||
from music.models import Track
|
||||
|
||||
# TODO This whole thing should iterate over users
|
||||
dups = []
|
||||
|
||||
for t in Track.objects.all():
|
||||
if Track.objects.filter(title=t.title, artist=t.artist).exists():
|
||||
dups.append(t)
|
||||
|
||||
for b in dups:
|
||||
tracks = Track.objects.filter(artist=b.artist, title=b.title)
|
||||
first = tracks.first()
|
||||
for other in tracks.exclude(id=first.id):
|
||||
print("moving scrobbles for ", other.id, " to ", first.id)
|
||||
if commit:
|
||||
with transaction.atomic():
|
||||
other.scrobble_set.update(track=first)
|
||||
print("deleting ", other.id, " - ", other)
|
||||
try:
|
||||
other.delete()
|
||||
except IntegrityError as e:
|
||||
print(
|
||||
"could not delete ",
|
||||
other.id,
|
||||
f": IntegrityError {e}",
|
||||
)
|
||||
return len(dups)
|
||||
|
||||
|
||||
def send_stop_notifications_for_in_progress_scrobbles() -> int:
|
||||
"""Get all inprogress scrobbles and check if they're passed their media obj length.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user