Big reorg to support pacakging
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,3 +1,4 @@
|
|||||||
db.sqlite3
|
db.sqlite3
|
||||||
vrobbler.conf
|
vrobbler.conf
|
||||||
/media/
|
/media/
|
||||||
|
/dist/
|
||||||
|
|||||||
13
scripts.py
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 +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),
|
||||||
|
),
|
||||||
|
]
|
||||||
@ -14,7 +14,7 @@ class Scrobble(TimeStampedModel):
|
|||||||
User, blank=True, null=True, on_delete=models.DO_NOTHING
|
User, blank=True, null=True, on_delete=models.DO_NOTHING
|
||||||
)
|
)
|
||||||
timestamp = models.DateTimeField(**BNULL)
|
timestamp = models.DateTimeField(**BNULL)
|
||||||
playback_position_ticks = models.PositiveIntegerField(**BNULL)
|
playback_position_ticks = models.PositiveBigIntegerField(**BNULL)
|
||||||
playback_position = models.CharField(max_length=8, **BNULL)
|
playback_position = models.CharField(max_length=8, **BNULL)
|
||||||
is_paused = models.BooleanField(default=False)
|
is_paused = models.BooleanField(default=False)
|
||||||
played_to_completion = models.BooleanField(default=False)
|
played_to_completion = models.BooleanField(default=False)
|
||||||
@ -14,6 +14,7 @@ from rest_framework.response import Response
|
|||||||
from scrobbles.models import Scrobble
|
from scrobbles.models import Scrobble
|
||||||
from scrobbles.serializers import ScrobbleSerializer
|
from scrobbles.serializers import ScrobbleSerializer
|
||||||
from videos.models import Series, Video
|
from videos.models import Series, Video
|
||||||
|
from vrobbler.settings import DELETE_STALE_SCROBBLES
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -115,18 +116,21 @@ def jellyfin_websocket(request):
|
|||||||
)
|
)
|
||||||
return Response(video_dict, status=status.HTTP_204_NO_CONTENT)
|
return Response(video_dict, status=status.HTTP_204_NO_CONTENT)
|
||||||
|
|
||||||
# Check if found in progress scrobble is more than a day old
|
existing_scrobble_more_than_a_day_old = (
|
||||||
if not (
|
|
||||||
existing_in_progress_scrobble
|
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(
|
logger.info(
|
||||||
'Found a scrobble for this video more than a day old, creating a new scrobble'
|
'Found a scrobble for this video more than a day old, creating a new scrobble'
|
||||||
)
|
)
|
||||||
scrobble = existing_in_progress_scrobble
|
scrobble = existing_in_progress_scrobble
|
||||||
scrobble_created = False
|
scrobble_created = False
|
||||||
else:
|
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()
|
existing_in_progress_scrobble.delete()
|
||||||
scrobble, scrobble_created = Scrobble.objects.get_or_create(
|
scrobble, scrobble_created = Scrobble.objects.get_or_create(
|
||||||
**scrobble_dict
|
**scrobble_dict
|
||||||
@ -137,8 +141,6 @@ def jellyfin_websocket(request):
|
|||||||
scrobble.source = data_dict['ClientName']
|
scrobble.source = data_dict['ClientName']
|
||||||
scrobble.source_id = data_dict['MediaSourceId']
|
scrobble.source_id = data_dict['MediaSourceId']
|
||||||
scrobble.scrobble_log = ""
|
scrobble.scrobble_log = ""
|
||||||
else:
|
|
||||||
last_tick = scrobble.playback_position_ticks
|
|
||||||
|
|
||||||
# Update a found scrobble with new position and timestamp
|
# Update a found scrobble with new position and timestamp
|
||||||
scrobble.playback_position_ticks = data_dict["PlaybackPositionTicks"]
|
scrobble.playback_position_ticks = data_dict["PlaybackPositionTicks"]
|
||||||
@ -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),
|
||||||
|
),
|
||||||
|
]
|
||||||
@ -33,7 +33,7 @@ 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 = models.CharField(max_length=8, **BNULL)
|
||||||
run_time_ticks = models.BigIntegerField(**BNULL)
|
run_time_ticks = models.PositiveBigIntegerField(**BNULL)
|
||||||
year = models.IntegerField()
|
year = models.IntegerField()
|
||||||
|
|
||||||
# TV show specific fields
|
# TV show specific fields
|
||||||
@ -4,7 +4,12 @@ import sys
|
|||||||
|
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
from dotenv import load_dotenv
|
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
|
# Tap vrobbler.conf if it's available
|
||||||
if os.path.exists("vrobbler.conf"):
|
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"):
|
elif os.path.exists("/usr/local/etc/vrobbler.conf"):
|
||||||
load_dotenv("/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'.
|
# Build paths inside the project like this: BASE_DIR / 'subdir'.
|
||||||
BASE_DIR = Path(__file__).resolve().parent.parent
|
|
||||||
|
|
||||||
|
|
||||||
# Quick-start development settings - unsuitable for production
|
# Quick-start development settings - unsuitable for production
|
||||||
@ -94,7 +96,7 @@ ROOT_URLCONF = "vrobbler.urls"
|
|||||||
TEMPLATES = [
|
TEMPLATES = [
|
||||||
{
|
{
|
||||||
"BACKEND": "django.template.backends.django.DjangoTemplates",
|
"BACKEND": "django.template.backends.django.DjangoTemplates",
|
||||||
"DIRS": [str(BASE_DIR.joinpath("templates"))], # new
|
"DIRS": [str(PROJECT_ROOT.joinpath("templates"))],
|
||||||
"APP_DIRS": True,
|
"APP_DIRS": True,
|
||||||
"OPTIONS": {
|
"OPTIONS": {
|
||||||
"context_processors": [
|
"context_processors": [
|
||||||
@ -111,7 +113,7 @@ WSGI_APPLICATION = "vrobbler.wsgi.application"
|
|||||||
|
|
||||||
DATABASES = {
|
DATABASES = {
|
||||||
"default": dj_database_url.config(
|
"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,
|
conn_max_age=600,
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
@ -181,7 +183,7 @@ AUTH_PASSWORD_VALIDATORS = [
|
|||||||
|
|
||||||
LANGUAGE_CODE = "en-us"
|
LANGUAGE_CODE = "en-us"
|
||||||
|
|
||||||
TIME_ZONE = os.getenv("vrobbler_TIME_ZONE", "EST")
|
TIME_ZONE = os.getenv("VROBBLER_TIME_ZONE", "EST")
|
||||||
|
|
||||||
USE_I18N = True
|
USE_I18N = True
|
||||||
|
|
||||||
@ -195,7 +197,7 @@ USE_TZ = True
|
|||||||
|
|
||||||
STATIC_URL = "static/"
|
STATIC_URL = "static/"
|
||||||
STATIC_ROOT = os.getenv(
|
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:
|
if not DEBUG:
|
||||||
STATICFILES_STORAGE = (
|
STATICFILES_STORAGE = (
|
||||||
|
|||||||
Reference in New Issue
Block a user