Big reorg to support pacakging

This commit is contained in:
2023-01-05 14:39:47 -05:00
parent 41a74f46c8
commit 819723b927
26 changed files with 57 additions and 29 deletions

1
.gitignore vendored
View File

@ -1,3 +1,4 @@
db.sqlite3
vrobbler.conf
/media/
/dist/

View File

@ -1,13 +0,0 @@
import subprocess
def server():
cmd =['python', 'manage.py', 'runserver_plus']
subprocess.run(cmd)
def migrate():
cmd =['python', 'manage.py', 'migrate']
subprocess.run(cmd)
def shell():
cmd =['python', 'manage.py', 'shell_plus']
subprocess.run(cmd)

View File

@ -0,0 +1,18 @@
# Generated by Django 4.1.5 on 2023-01-05 19:38
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('scrobbles', '0004_scrobble_scrobble_log'),
]
operations = [
migrations.AlterField(
model_name='scrobble',
name='playback_position_ticks',
field=models.PositiveBigIntegerField(blank=True, null=True),
),
]

View File

@ -14,7 +14,7 @@ class Scrobble(TimeStampedModel):
User, blank=True, null=True, on_delete=models.DO_NOTHING
)
timestamp = models.DateTimeField(**BNULL)
playback_position_ticks = models.PositiveIntegerField(**BNULL)
playback_position_ticks = models.PositiveBigIntegerField(**BNULL)
playback_position = models.CharField(max_length=8, **BNULL)
is_paused = models.BooleanField(default=False)
played_to_completion = models.BooleanField(default=False)

View File

@ -14,6 +14,7 @@ from rest_framework.response import Response
from scrobbles.models import Scrobble
from scrobbles.serializers import ScrobbleSerializer
from videos.models import Series, Video
from vrobbler.settings import DELETE_STALE_SCROBBLES
logger = logging.getLogger(__name__)
@ -115,18 +116,21 @@ def jellyfin_websocket(request):
)
return Response(video_dict, status=status.HTTP_204_NO_CONTENT)
# Check if found in progress scrobble is more than a day old
if not (
existing_scrobble_more_than_a_day_old = (
existing_in_progress_scrobble
and existing_in_progress_scrobble.modified < a_day_from_now
):
and existing_in_progress_scrobble.modified > a_day_from_now
)
delete_stale_scrobbles = getattr(settings, "DELETE_STALE_SCROBBLES", True)
# Check if found in progress scrobble is more than a day old
if existing_scrobble_more_than_a_day_old:
logger.info(
'Found a scrobble for this video more than a day old, creating a new scrobble'
)
scrobble = existing_in_progress_scrobble
scrobble_created = False
else:
if getattr(settings, "DELETE_STALE_SCROBBLES", True):
if existing_scrobble_more_than_a_day_old and delete_stale_scrobbles:
existing_in_progress_scrobble.delete()
scrobble, scrobble_created = Scrobble.objects.get_or_create(
**scrobble_dict
@ -137,8 +141,6 @@ def jellyfin_websocket(request):
scrobble.source = data_dict['ClientName']
scrobble.source_id = data_dict['MediaSourceId']
scrobble.scrobble_log = ""
else:
last_tick = scrobble.playback_position_ticks
# Update a found scrobble with new position and timestamp
scrobble.playback_position_ticks = data_dict["PlaybackPositionTicks"]

View File

@ -0,0 +1,18 @@
# Generated by Django 4.1.5 on 2023-01-05 19:38
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('videos', '0002_alter_series_options'),
]
operations = [
migrations.AlterField(
model_name='video',
name='run_time_ticks',
field=models.PositiveBigIntegerField(blank=True, null=True),
),
]

View File

@ -33,7 +33,7 @@ class Video(TimeStampedModel):
overview = models.TextField(**BNULL)
tagline = models.TextField(**BNULL)
run_time = models.CharField(max_length=8, **BNULL)
run_time_ticks = models.BigIntegerField(**BNULL)
run_time_ticks = models.PositiveBigIntegerField(**BNULL)
year = models.IntegerField()
# TV show specific fields

View File

@ -4,7 +4,12 @@ import sys
from django.utils.translation import gettext_lazy as _
from dotenv import load_dotenv
from pathlib import Path
# PROJECT_ROOT = os.path.dirname(__file__)
PROJECT_ROOT = Path(__file__).resolve().parent
BASE_DIR = Path(__file__).resolve().parent.parent
sys.path.insert(0, os.path.join(PROJECT_ROOT, 'apps'))
# Tap vrobbler.conf if it's available
if os.path.exists("vrobbler.conf"):
@ -14,10 +19,7 @@ elif os.path.exists("/etc/vrobbler.conf"):
elif os.path.exists("/usr/local/etc/vrobbler.conf"):
load_dotenv("/usr/local/etc/vrobbler.conf")
from pathlib import Path
# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent
# Quick-start development settings - unsuitable for production
@ -94,7 +96,7 @@ ROOT_URLCONF = "vrobbler.urls"
TEMPLATES = [
{
"BACKEND": "django.template.backends.django.DjangoTemplates",
"DIRS": [str(BASE_DIR.joinpath("templates"))], # new
"DIRS": [str(PROJECT_ROOT.joinpath("templates"))],
"APP_DIRS": True,
"OPTIONS": {
"context_processors": [
@ -111,7 +113,7 @@ WSGI_APPLICATION = "vrobbler.wsgi.application"
DATABASES = {
"default": dj_database_url.config(
default=os.getenv("vrobbler_DATABASE_URL", "sqlite:///db.sqlite3"),
default=os.getenv("VROBBLER_DATABASE_URL", "sqlite:///db.sqlite3"),
conn_max_age=600,
),
}
@ -181,7 +183,7 @@ AUTH_PASSWORD_VALIDATORS = [
LANGUAGE_CODE = "en-us"
TIME_ZONE = os.getenv("vrobbler_TIME_ZONE", "EST")
TIME_ZONE = os.getenv("VROBBLER_TIME_ZONE", "EST")
USE_I18N = True
@ -195,7 +197,7 @@ USE_TZ = True
STATIC_URL = "static/"
STATIC_ROOT = os.getenv(
"VROBBLER_STATIC_ROOT", os.path.join(BASE_DIR, "static")
"VROBBLER_STATIC_ROOT", os.path.join(PROJECT_ROOT, "static")
)
if not DEBUG:
STATICFILES_STORAGE = (