Update repeated attributes for scrobblable models
This commit is contained in:
@ -1,13 +1,14 @@
|
|||||||
import logging
|
import logging
|
||||||
from typing import Dict, Optional
|
from typing import Dict, Optional
|
||||||
from uuid import uuid4
|
from uuid import uuid4
|
||||||
import musicbrainzngs
|
|
||||||
|
|
||||||
|
import musicbrainzngs
|
||||||
from django.apps.config import cached_property
|
from django.apps.config import cached_property
|
||||||
from django.core.files.base import ContentFile
|
from django.core.files.base import ContentFile
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
from django_extensions.db.models import TimeStampedModel
|
from django_extensions.db.models import TimeStampedModel
|
||||||
|
from scrobbles.mixins import ScrobblableMixin
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
BNULL = {"blank": True, "null": True}
|
BNULL = {"blank": True, "null": True}
|
||||||
@ -82,20 +83,15 @@ class Album(TimeStampedModel):
|
|||||||
return f"https://musicbrainz.org/release/{self.musicbrainz_id}"
|
return f"https://musicbrainz.org/release/{self.musicbrainz_id}"
|
||||||
|
|
||||||
|
|
||||||
class Track(TimeStampedModel):
|
class Track(ScrobblableMixin):
|
||||||
class Opinion(models.IntegerChoices):
|
class Opinion(models.IntegerChoices):
|
||||||
DOWN = -1, 'Thumbs down'
|
DOWN = -1, 'Thumbs down'
|
||||||
NEUTRAL = 0, 'No opinion'
|
NEUTRAL = 0, 'No opinion'
|
||||||
UP = 1, 'Thumbs up'
|
UP = 1, 'Thumbs up'
|
||||||
|
|
||||||
uuid = models.UUIDField(default=uuid4, editable=False, **BNULL)
|
|
||||||
title = models.CharField(max_length=255, **BNULL)
|
|
||||||
artist = models.ForeignKey(Artist, on_delete=models.DO_NOTHING)
|
artist = models.ForeignKey(Artist, on_delete=models.DO_NOTHING)
|
||||||
album = models.ForeignKey(Album, on_delete=models.DO_NOTHING, **BNULL)
|
album = models.ForeignKey(Album, on_delete=models.DO_NOTHING, **BNULL)
|
||||||
musicbrainz_id = models.CharField(max_length=255, unique=True, **BNULL)
|
musicbrainz_id = models.CharField(max_length=255, unique=True, **BNULL)
|
||||||
run_time = models.CharField(max_length=8, **BNULL)
|
|
||||||
run_time_ticks = models.PositiveBigIntegerField(**BNULL)
|
|
||||||
# thumbs = models.IntegerField(default=Opinion.NEUTRAL, choices=Opinion.choices)
|
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return f"{self.title} by {self.artist}"
|
return f"{self.title} by {self.artist}"
|
||||||
|
|||||||
@ -6,6 +6,8 @@ from django.db import models
|
|||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
from django_extensions.db.models import TimeStampedModel
|
from django_extensions.db.models import TimeStampedModel
|
||||||
|
|
||||||
|
from vrobbler.apps.scrobbles.mixins import ScrobblableMixin
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
BNULL = {"blank": True, "null": True}
|
BNULL = {"blank": True, "null": True}
|
||||||
|
|
||||||
@ -31,14 +33,10 @@ class Podcast(TimeStampedModel):
|
|||||||
return f"{self.name}"
|
return f"{self.name}"
|
||||||
|
|
||||||
|
|
||||||
class Episode(TimeStampedModel):
|
class Episode(ScrobblableMixin):
|
||||||
title = models.CharField(max_length=255)
|
|
||||||
uuid = models.UUIDField(default=uuid4, editable=False, **BNULL)
|
|
||||||
podcast = models.ForeignKey(Podcast, on_delete=models.DO_NOTHING)
|
podcast = models.ForeignKey(Podcast, on_delete=models.DO_NOTHING)
|
||||||
number = models.IntegerField(**BNULL)
|
number = models.IntegerField(**BNULL)
|
||||||
pub_date = models.DateField(**BNULL)
|
pub_date = models.DateField(**BNULL)
|
||||||
run_time = models.CharField(max_length=8, **BNULL)
|
|
||||||
run_time_ticks = models.PositiveBigIntegerField(**BNULL)
|
|
||||||
mopidy_uri = models.CharField(max_length=255, **BNULL)
|
mopidy_uri = models.CharField(max_length=255, **BNULL)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
|
|||||||
17
vrobbler/apps/scrobbles/mixins.py
Normal file
17
vrobbler/apps/scrobbles/mixins.py
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
from uuid import uuid4
|
||||||
|
|
||||||
|
from django.db import models
|
||||||
|
from django_extensions.db.models import TimeStampedModel
|
||||||
|
|
||||||
|
BNULL = {"blank": True, "null": True}
|
||||||
|
|
||||||
|
|
||||||
|
class ScrobblableMixin(TimeStampedModel):
|
||||||
|
uuid = models.UUIDField(default=uuid4, editable=False, **BNULL)
|
||||||
|
title = models.CharField(max_length=255, **BNULL)
|
||||||
|
run_time = models.CharField(max_length=8, **BNULL)
|
||||||
|
run_time_ticks = models.PositiveBigIntegerField(**BNULL)
|
||||||
|
# thumbs = models.IntegerField(default=Opinion.NEUTRAL, choices=Opinion.choices)
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
abstract = True
|
||||||
@ -1,7 +1,6 @@
|
|||||||
import logging
|
import logging
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
from uuid import uuid4
|
|
||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.contrib.auth import get_user_model
|
from django.contrib.auth import get_user_model
|
||||||
@ -22,16 +21,6 @@ VIDEO_WAIT_PERIOD = getattr(settings, 'VIDEO_WAIT_PERIOD_DAYS')
|
|||||||
TRACK_WAIT_PERIOD = getattr(settings, 'MUSIC_WAIT_PERIOD_MINUTES')
|
TRACK_WAIT_PERIOD = getattr(settings, 'MUSIC_WAIT_PERIOD_MINUTES')
|
||||||
|
|
||||||
|
|
||||||
class ScrobblableMixin(TimeStampedModel):
|
|
||||||
uuid = models.UUIDField(default=uuid4, editable=False, **BNULL)
|
|
||||||
title = models.CharField(max_length=255, **BNULL)
|
|
||||||
run_time = models.CharField(max_length=8, **BNULL)
|
|
||||||
run_time_ticks = models.PositiveBigIntegerField(**BNULL)
|
|
||||||
|
|
||||||
class Meta:
|
|
||||||
abstract = True
|
|
||||||
|
|
||||||
|
|
||||||
class Scrobble(TimeStampedModel):
|
class Scrobble(TimeStampedModel):
|
||||||
video = models.ForeignKey(Video, on_delete=models.DO_NOTHING, **BNULL)
|
video = models.ForeignKey(Video, on_delete=models.DO_NOTHING, **BNULL)
|
||||||
track = models.ForeignKey(Track, on_delete=models.DO_NOTHING, **BNULL)
|
track = models.ForeignKey(Track, on_delete=models.DO_NOTHING, **BNULL)
|
||||||
|
|||||||
@ -7,6 +7,7 @@ from django.urls import reverse
|
|||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
from django_extensions.db.models import TimeStampedModel
|
from django_extensions.db.models import TimeStampedModel
|
||||||
from scrobbles.utils import convert_to_seconds
|
from scrobbles.utils import convert_to_seconds
|
||||||
|
from scrobbles.mixins import ScrobblableMixin
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
BNULL = {"blank": True, "null": True}
|
BNULL = {"blank": True, "null": True}
|
||||||
@ -30,15 +31,12 @@ class Series(TimeStampedModel):
|
|||||||
verbose_name_plural = "series"
|
verbose_name_plural = "series"
|
||||||
|
|
||||||
|
|
||||||
class Video(TimeStampedModel):
|
class Video(ScrobblableMixin):
|
||||||
class VideoType(models.TextChoices):
|
class VideoType(models.TextChoices):
|
||||||
UNKNOWN = 'U', _('Unknown')
|
UNKNOWN = 'U', _('Unknown')
|
||||||
TV_EPISODE = 'E', _('TV Episode')
|
TV_EPISODE = 'E', _('TV Episode')
|
||||||
MOVIE = 'M', _('Movie')
|
MOVIE = 'M', _('Movie')
|
||||||
|
|
||||||
# General fields
|
|
||||||
uuid = models.UUIDField(default=uuid4, editable=False, **BNULL)
|
|
||||||
title = models.CharField(max_length=255, **BNULL)
|
|
||||||
video_type = models.CharField(
|
video_type = models.CharField(
|
||||||
max_length=1,
|
max_length=1,
|
||||||
choices=VideoType.choices,
|
choices=VideoType.choices,
|
||||||
@ -46,8 +44,6 @@ class Video(TimeStampedModel):
|
|||||||
)
|
)
|
||||||
overview = models.TextField(**BNULL)
|
overview = models.TextField(**BNULL)
|
||||||
tagline = models.TextField(**BNULL)
|
tagline = models.TextField(**BNULL)
|
||||||
run_time = models.CharField(max_length=8, **BNULL)
|
|
||||||
run_time_ticks = models.PositiveBigIntegerField(**BNULL)
|
|
||||||
year = models.IntegerField()
|
year = models.IntegerField()
|
||||||
|
|
||||||
# TV show specific fields
|
# TV show specific fields
|
||||||
|
|||||||
Reference in New Issue
Block a user