Forráskód Böngészése

Big reorg to support pacakging

Colin Powell 2 éve
szülő
commit
819723b927

+ 1 - 0
.gitignore

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

+ 0 - 13
scripts.py

@@ -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)

+ 0 - 0
scrobbles/__init__.py → vrobbler/apps/scrobbles/__init__.py


+ 0 - 0
scrobbles/admin.py → vrobbler/apps/scrobbles/admin.py


+ 0 - 0
scrobbles/apps.py → vrobbler/apps/scrobbles/apps.py


+ 0 - 0
scrobbles/migrations/0001_initial.py → vrobbler/apps/scrobbles/migrations/0001_initial.py


+ 0 - 0
scrobbles/migrations/0002_scrobble_counted.py → vrobbler/apps/scrobbles/migrations/0002_scrobble_counted.py


+ 0 - 0
scrobbles/migrations/0003_remove_scrobble_counted_scrobble_in_progress.py → vrobbler/apps/scrobbles/migrations/0003_remove_scrobble_counted_scrobble_in_progress.py


+ 0 - 0
scrobbles/migrations/0004_scrobble_scrobble_log.py → vrobbler/apps/scrobbles/migrations/0004_scrobble_scrobble_log.py


+ 18 - 0
vrobbler/apps/scrobbles/migrations/0005_alter_scrobble_playback_position_ticks.py

@@ -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),
+        ),
+    ]

+ 0 - 0
scrobbles/migrations/__init__.py → vrobbler/apps/scrobbles/migrations/__init__.py


+ 1 - 1
scrobbles/models.py → vrobbler/apps/scrobbles/models.py

@@ -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)

+ 0 - 0
scrobbles/serializers.py → vrobbler/apps/scrobbles/serializers.py


+ 0 - 0
scrobbles/urls.py → vrobbler/apps/scrobbles/urls.py


+ 9 - 7
scrobbles/views.py → vrobbler/apps/scrobbles/views.py

@@ -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"]

+ 0 - 0
videos/__init__.py → vrobbler/apps/videos/__init__.py


+ 0 - 0
videos/admin.py → vrobbler/apps/videos/admin.py


+ 0 - 0
videos/apps.py → vrobbler/apps/videos/apps.py


+ 0 - 0
videos/migrations/0001_initial.py → vrobbler/apps/videos/migrations/0001_initial.py


+ 0 - 0
videos/migrations/0002_alter_series_options.py → vrobbler/apps/videos/migrations/0002_alter_series_options.py


+ 18 - 0
vrobbler/apps/videos/migrations/0003_alter_video_run_time_ticks.py

@@ -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),
+        ),
+    ]

+ 0 - 0
videos/migrations/__init__.py → vrobbler/apps/videos/migrations/__init__.py


+ 1 - 1
videos/models.py → vrobbler/apps/videos/models.py

@@ -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

+ 9 - 7
vrobbler/settings.py

@@ -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 = (

+ 0 - 0
templates/base.html → vrobbler/templates/base.html


+ 0 - 0
templates/scrobbles/scrobble_list.html → vrobbler/templates/scrobbles/scrobble_list.html