From a2973bcd82b4acedfefd60bc374055d10ec8b04f Mon Sep 17 00:00:00 2001 From: pierregeeraert Date: Wed, 5 Aug 2026 15:32:03 +0100 Subject: [PATCH 01/12] no need for python-json-logger anymore as we cancelled netdata idea --- requirements.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 6bd0bf5..137d398 100644 --- a/requirements.txt +++ b/requirements.txt @@ -19,4 +19,3 @@ bitwarden_sdk xmltodict whitenoise djangoql -python-json-logger From 78a95435ae1ac1124386a2293ba8b89e3010ea2f Mon Sep 17 00:00:00 2001 From: pierregeeraert Date: Wed, 5 Aug 2026 16:59:10 +0100 Subject: [PATCH 02/12] clickable links almost everywhere --- django_code/apps/podcast_aggregator/admin.py | 6 +++++- django_code/apps/random_simpsons/admin.py | 15 +++++++++------ django_code/apps/streaming/admin.py | 8 ++++++-- 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/django_code/apps/podcast_aggregator/admin.py b/django_code/apps/podcast_aggregator/admin.py index 9479bd9..ecbf68e 100644 --- a/django_code/apps/podcast_aggregator/admin.py +++ b/django_code/apps/podcast_aggregator/admin.py @@ -1,9 +1,13 @@ from django.contrib import admin from import_export.admin import ImportExportModelAdmin from import_export import resources +from django.utils.html import format_html from .models import podcastData # Register your models here. @admin.register(podcastData) class JobAdmin(ImportExportModelAdmin): - list_display = ('podcast_name','podcast_url','enabled') + list_display = ('podcast_name','clickable_links','enabled') + + def clickable_links(self, obj): + return format_html('{}', obj.podcast_url,obj.podcast_url) \ No newline at end of file diff --git a/django_code/apps/random_simpsons/admin.py b/django_code/apps/random_simpsons/admin.py index cdda8d8..1a4bf36 100644 --- a/django_code/apps/random_simpsons/admin.py +++ b/django_code/apps/random_simpsons/admin.py @@ -1,12 +1,13 @@ from django.contrib import admin,messages from django.utils.translation import ngettext -from prompt_toolkit.shortcuts import print_container -from .models import SimpsonsData,simpsons_data_object,urlData -from .utils import mark_episode_watched,unwatch_all_episodes,generate_new_urls_for_episode -from import_export import resources -from import_export.admin import ImportExportModelAdmin +from django.utils.html import format_html from django.utils import timezone from djangoql.admin import DjangoQLSearchMixin +from prompt_toolkit.shortcuts import print_container +from import_export.admin import ImportExportModelAdmin +from import_export import resources +from .models import SimpsonsData,simpsons_data_object,urlData +from .utils import mark_episode_watched,unwatch_all_episodes,generate_new_urls_for_episode # Register your models here. @@ -72,7 +73,9 @@ class EpisodeAdmin(DjangoQLSearchMixin,ImportExportModelAdmin): actions = [make_seen,make_unseen,unseen_betaserie,generate_new_urls] search_fields = ['season', 'episode', 'url', 'seen'] djangoql_completion_enabled_by_default = False - + + def clickable_links(self, obj): + return format_html('{}', obj.url,obj.url) def get_queryset(self, request): diff --git a/django_code/apps/streaming/admin.py b/django_code/apps/streaming/admin.py index ce2f06f..7f852a2 100644 --- a/django_code/apps/streaming/admin.py +++ b/django_code/apps/streaming/admin.py @@ -1,4 +1,5 @@ from django.contrib import admin +from django.utils.html import format_html from import_export.admin import ImportExportModelAdmin from .models import streamingData from .utils import full_testing @@ -30,6 +31,9 @@ def check(modeladmin, request, queryset): @admin.register(streamingData) class streamingAdmin(ImportExportModelAdmin): - list_display = ['url','result','status'] + list_display = ['clickable_links','result','status'] fields = ['url'] - actions = [check] \ No newline at end of file + actions = [check] + + def clickable_links(self, obj): + return format_html('{}', obj.url,obj.url) \ No newline at end of file From 9595ea326f0d8c2c73ce94244c39e2d9291d6fc8 Mon Sep 17 00:00:00 2001 From: pierre geeraert Date: Wed, 5 Aug 2026 19:55:27 +0100 Subject: [PATCH 03/12] clean the URLs from import --- django_code/apps/streaming/admin.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/django_code/apps/streaming/admin.py b/django_code/apps/streaming/admin.py index 7f852a2..e6503f2 100644 --- a/django_code/apps/streaming/admin.py +++ b/django_code/apps/streaming/admin.py @@ -3,6 +3,7 @@ from django.utils.html import format_html from import_export.admin import ImportExportModelAdmin from .models import streamingData from .utils import full_testing +from urllib.parse import urlsplit, urlunsplit @@ -29,11 +30,24 @@ def check(modeladmin, request, queryset): # messages.SUCCESS, # ) +@admin.action(description="cleaning the url") +def urlcleaning(modeladmin, request, queryset): + for query in queryset: + # Split the URL into components + parsed = urlsplit(query.url) + + # Rebuild using only scheme and netloc, adding a trailing slash at the end + base_url = urlunsplit((parsed.scheme, parsed.netloc, "/", "", "")) + query.url = base_url + query.save(update_fields=["url"]) + print("Cleaning :"+str(base_url)) + + return 0 @admin.register(streamingData) class streamingAdmin(ImportExportModelAdmin): list_display = ['clickable_links','result','status'] fields = ['url'] - actions = [check] + actions = [check,urlcleaning] def clickable_links(self, obj): return format_html('{}', obj.url,obj.url) \ No newline at end of file From a991b69547d1147689048b6ec388637c112c987d Mon Sep 17 00:00:00 2001 From: pierregeeraert Date: Thu, 6 Aug 2026 15:33:19 +0100 Subject: [PATCH 04/12] add colored background --- django_code/apps/streaming/admin.py | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/django_code/apps/streaming/admin.py b/django_code/apps/streaming/admin.py index e6503f2..88d825d 100644 --- a/django_code/apps/streaming/admin.py +++ b/django_code/apps/streaming/admin.py @@ -45,9 +45,27 @@ def urlcleaning(modeladmin, request, queryset): return 0 @admin.register(streamingData) class streamingAdmin(ImportExportModelAdmin): - list_display = ['clickable_links','result','status'] + list_display = ['clickable_links','result_colored','newstatus'] fields = ['url'] actions = [check,urlcleaning] def clickable_links(self, obj): - return format_html('{}', obj.url,obj.url) \ No newline at end of file + return format_html('{}', obj.url,obj.url) + + def result_colored(self, obj): + colors = { + 'REACHABLE': 'green', + 'VPN REQUIRED': 'yellow', + 'UNREACHABLE': 'red', + } + + return format_html( + '{}', + colors[obj.result], + obj.result, + ) + def newstatus(self, obj): + if obj.status != '200': + return format_html('
{}
', obj.status) + #return obj.status + \ No newline at end of file From 7a1021edfaecb85c6d3f473f245469b0d860b11b Mon Sep 17 00:00:00 2001 From: pierregeeraert Date: Fri, 7 Aug 2026 11:56:22 +0100 Subject: [PATCH 05/12] adding streaming_redirect --- README.md | 4 +++ django_code/apps/streaming/apps.py | 1 + .../apps/streaming_redirect/__init__.py | 0 django_code/apps/streaming_redirect/admin.py | 3 ++ django_code/apps/streaming_redirect/apps.py | 7 +++++ .../migrations/0001_initial.py | 30 +++++++++++++++++++ .../streaming_redirect/migrations/__init__.py | 0 django_code/apps/streaming_redirect/models.py | 19 ++++++++++++ django_code/apps/streaming_redirect/tests.py | 3 ++ django_code/apps/streaming_redirect/views.py | 3 ++ django_code/core/routers.py | 15 ++++++++-- django_code/core/settings.py | 9 ++++++ infra/production/entrypoint.sh | 2 ++ infra/testing/entrypoint.sh | 2 ++ 14 files changed, 95 insertions(+), 3 deletions(-) create mode 100644 django_code/apps/streaming_redirect/__init__.py create mode 100644 django_code/apps/streaming_redirect/admin.py create mode 100644 django_code/apps/streaming_redirect/apps.py create mode 100644 django_code/apps/streaming_redirect/migrations/0001_initial.py create mode 100644 django_code/apps/streaming_redirect/migrations/__init__.py create mode 100644 django_code/apps/streaming_redirect/models.py create mode 100644 django_code/apps/streaming_redirect/tests.py create mode 100644 django_code/apps/streaming_redirect/views.py diff --git a/README.md b/README.md index ce385ad..7dca65f 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,7 @@ python django_code/manage.py makemigrations job python django_code/manage.py makemigrations telegram python django_code/manage.py makemigrations podcast python django_code/manage.py makemigrations streaming +python django_code/manage.py makemigrations streaming_redirect python django_code/manage.py migrate python django_code/manage.py migrate --database=cloudmanager_db @@ -21,6 +22,7 @@ python django_code/manage.py migrate --database=job_db python django_code/manage.py migrate --database=telegram_db python django_code/manage.py migrate --database=podcast_db python django_code/manage.py migrate --database=streaming_db +python django_code/manage.py migrate --database=streaming_redirect_db ``` ### Database debug @@ -33,6 +35,7 @@ create database job; create database telegram; create database podcast; create database streaming; +create database streaming_redirect; @@ -43,6 +46,7 @@ drop database job; drop database telegram; drop database podcast; drop database streaming; +drop database streaming_redirect; ``` diff --git a/django_code/apps/streaming/apps.py b/django_code/apps/streaming/apps.py index 85d22eb..7c1d9dd 100644 --- a/django_code/apps/streaming/apps.py +++ b/django_code/apps/streaming/apps.py @@ -4,3 +4,4 @@ from django.apps import AppConfig class StreamingConfig(AppConfig): default_auto_field = 'django.db.models.BigAutoField' name = 'apps.streaming' + label = 'streaming' diff --git a/django_code/apps/streaming_redirect/__init__.py b/django_code/apps/streaming_redirect/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/django_code/apps/streaming_redirect/admin.py b/django_code/apps/streaming_redirect/admin.py new file mode 100644 index 0000000..8c38f3f --- /dev/null +++ b/django_code/apps/streaming_redirect/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/django_code/apps/streaming_redirect/apps.py b/django_code/apps/streaming_redirect/apps.py new file mode 100644 index 0000000..20490bf --- /dev/null +++ b/django_code/apps/streaming_redirect/apps.py @@ -0,0 +1,7 @@ +from django.apps import AppConfig + + +class StreamingRedirectConfig(AppConfig): + default_auto_field = 'django.db.models.BigAutoField' + name = 'apps.streaming_redirect' + label = 'streaming_redirect' diff --git a/django_code/apps/streaming_redirect/migrations/0001_initial.py b/django_code/apps/streaming_redirect/migrations/0001_initial.py new file mode 100644 index 0000000..25a1a55 --- /dev/null +++ b/django_code/apps/streaming_redirect/migrations/0001_initial.py @@ -0,0 +1,30 @@ +# Generated by Django 4.2.30 on 2026-08-07 10:54 + +import apps.streaming_redirect.models +from django.db import migrations, models + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ] + + operations = [ + migrations.CreateModel( + name='urlData', + fields=[ + ('name', models.CharField(help_text='Name of the show', max_length=1000, primary_key=True, serialize=False)), + ('url_example', models.CharField(help_text='https://www.1shows.org/tv/456-the-simpsons?streaming=true&season=18&episode=5', max_length=1000)), + ('prefix', models.CharField(blank=True, help_text='https://www.1shows.org/tv/456-the-simpsons?streaming=true&season=', max_length=1000, null=True)), + ('infix', models.CharField(blank=True, help_text='&episode=', max_length=1000, null=True)), + ('suffix', models.CharField(blank=True, max_length=1000, null=True)), + ('addedDate', models.DateField(auto_now_add=True, null=True, verbose_name='Published')), + ('alias', models.CharField(default=apps.streaming_redirect.models.urlData.sanitize, max_length=1000)), + ], + options={ + 'db_table': 'redirectUrl', + }, + ), + ] diff --git a/django_code/apps/streaming_redirect/migrations/__init__.py b/django_code/apps/streaming_redirect/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/django_code/apps/streaming_redirect/models.py b/django_code/apps/streaming_redirect/models.py new file mode 100644 index 0000000..1737edc --- /dev/null +++ b/django_code/apps/streaming_redirect/models.py @@ -0,0 +1,19 @@ +from django.db import models + +# Create your models here. +class urlData(models.Model): + def sanitize(self): + print(self) + return 1 + + name = models.CharField(primary_key=True,max_length=1000, help_text="Name of the show") + url_example = models.CharField(max_length=1000, help_text="https://www.1shows.org/tv/456-the-simpsons?streaming=true&season=18&episode=5") + prefix = models.CharField(max_length=1000, help_text="https://www.1shows.org/tv/456-the-simpsons?streaming=true&season=",blank=True, null=True) + infix = models.CharField(max_length=1000, help_text="&episode=",blank=True, null=True) + suffix = models.CharField(max_length=1000, help_text="" ,blank=True, null=True) + addedDate = models.DateField('Published', blank=True, null=True, auto_now_add=True) + alias = models.CharField(max_length=1000, default=sanitize) + + + class Meta: + db_table = 'redirectUrl' \ No newline at end of file diff --git a/django_code/apps/streaming_redirect/tests.py b/django_code/apps/streaming_redirect/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/django_code/apps/streaming_redirect/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/django_code/apps/streaming_redirect/views.py b/django_code/apps/streaming_redirect/views.py new file mode 100644 index 0000000..91ea44a --- /dev/null +++ b/django_code/apps/streaming_redirect/views.py @@ -0,0 +1,3 @@ +from django.shortcuts import render + +# Create your views here. diff --git a/django_code/core/routers.py b/django_code/core/routers.py index cc62513..ea65120 100644 --- a/django_code/core/routers.py +++ b/django_code/core/routers.py @@ -30,6 +30,9 @@ class ProjectDatabaseRouter: if model._meta.app_label == 'streaming': return 'streaming_db' + if model._meta.app_label == 'streaming_redirect': + return 'streaming_redirect_db' + return 'default' def db_for_write(self, model, **hints): @@ -56,14 +59,17 @@ class ProjectDatabaseRouter: if model._meta.app_label == 'streaming': return 'streaming_db' + if model._meta.app_label == 'streaming_redirect': + return 'streaming_redirect_db' + return 'default' def allow_relation(self, obj1, obj2, **hints): """Allow relations if both models are in the same database.""" # Prevents accidental foreign key relationships across different physical DBs if ( - obj1._meta.app_label in ['cloudmanager', 'simpsons', 'redirect', 'job', 'telegram', 'podcast', 'streaming'] or - obj2._meta.app_label in ['cloudmanager', 'simpsons', 'redirect', 'job', 'telegram', 'podcast', 'streaming'] + obj1._meta.app_label in ['cloudmanager', 'simpsons', 'redirect', 'job', 'telegram', 'podcast', 'streaming', 'streaming_redirect'] or + obj2._meta.app_label in ['cloudmanager', 'simpsons', 'redirect', 'job', 'telegram', 'podcast', 'streaming', 'streaming_redirect'] ): return obj1._meta.app_label == obj2._meta.app_label return None @@ -92,8 +98,11 @@ class ProjectDatabaseRouter: if app_label == 'streaming': return db == 'streaming_db' + if app_label == 'streaming_redirect': + return db == 'streaming_redirect_db' + # Ensure default Django apps (auth, sessions, etc.) don't migrate into simpsons/cloudmanager - if db in ['cloudmanager_db', 'simpsons_db', 'redirect_db', 'job_db', 'telegram_db', 'podcast_db', 'streaming_db']: + if db in ['cloudmanager_db', 'simpsons_db', 'redirect_db', 'job_db', 'telegram_db', 'podcast_db', 'streaming_db', 'streaming_redirect_db']: return False return None diff --git a/django_code/core/settings.py b/django_code/core/settings.py index 7ff2b56..58fd02b 100644 --- a/django_code/core/settings.py +++ b/django_code/core/settings.py @@ -51,6 +51,7 @@ INSTALLED_APPS = [ 'apps.telegram_communication.apps.TelegramCommunicationConfig', 'apps.podcast_aggregator.apps.PodcastAggregatorConfig', 'apps.streaming.apps.StreamingConfig', + 'apps.streaming_redirect.apps.StreamingRedirectConfig', 'import_export', 'djangoql', ] @@ -163,6 +164,14 @@ DATABASES = { 'HOST': os.environ.get('DB_HOST'), 'PORT': os.environ.get('DB_PORT'), }, + 'streaming_redirect_db': { + 'ENGINE': 'django.db.backends.postgresql', + 'NAME': 'streaming_redirect', + 'USER': os.environ.get('DB_USERNAME'), + 'PASSWORD': os.environ.get('DB_PASSWORD'), + 'HOST': os.environ.get('DB_HOST'), + 'PORT': os.environ.get('DB_PORT'), + }, } DATABASE_ROUTERS = ['core.routers.ProjectDatabaseRouter'] #DATABASE_ROUTERS = [] diff --git a/infra/production/entrypoint.sh b/infra/production/entrypoint.sh index f501c9e..dfa8492 100644 --- a/infra/production/entrypoint.sh +++ b/infra/production/entrypoint.sh @@ -8,6 +8,7 @@ python django_code/manage.py makemigrations job python django_code/manage.py makemigrations telegram python django_code/manage.py makemigrations podcast python django_code/manage.py makemigrations streaming +python django_code/manage.py makemigrations streaming_redirect python django_code/manage.py migrate python django_code/manage.py migrate --database=cloudmanager_db @@ -17,6 +18,7 @@ python django_code/manage.py migrate --database=job_db python django_code/manage.py migrate --database=telegram_db python django_code/manage.py migrate --database=podcast_db python django_code/manage.py migrate --database=streaming_db +python django_code/manage.py migrate --database=streaming_redirect_db python django_code/manage.py runserver "0.0.0.0:8000" diff --git a/infra/testing/entrypoint.sh b/infra/testing/entrypoint.sh index 44f6586..0071164 100644 --- a/infra/testing/entrypoint.sh +++ b/infra/testing/entrypoint.sh @@ -15,6 +15,7 @@ python django_code/manage.py makemigrations job python django_code/manage.py makemigrations telegram python django_code/manage.py makemigrations podcast python django_code/manage.py makemigrations streaming +python django_code/manage.py makemigrations streaming_redirect python django_code/manage.py migrate python django_code/manage.py migrate --database=cloudmanager_db @@ -24,6 +25,7 @@ python django_code/manage.py migrate --database=job_db python django_code/manage.py migrate --database=telegram_db python django_code/manage.py migrate --database=podcast_db python django_code/manage.py migrate --database=streaming_db +python django_code/manage.py migrate --database=streaming_redirect_db python django_code/manage.py runserver "0.0.0.0:8000" From 2b410b5ff86dc3eccd4247cd7ccded29c900cd63 Mon Sep 17 00:00:00 2001 From: pierregeeraert Date: Fri, 7 Aug 2026 12:00:32 +0100 Subject: [PATCH 06/12] reverting and merging into streaming app instead --- README.md | 4 --- django_code/apps/streaming/models.py | 17 +++++++++++ .../apps/streaming_redirect/__init__.py | 0 django_code/apps/streaming_redirect/admin.py | 3 -- django_code/apps/streaming_redirect/apps.py | 7 ----- .../migrations/0001_initial.py | 30 ------------------- .../streaming_redirect/migrations/__init__.py | 0 django_code/apps/streaming_redirect/models.py | 19 ------------ django_code/apps/streaming_redirect/tests.py | 3 -- django_code/apps/streaming_redirect/views.py | 3 -- django_code/core/routers.py | 15 ++-------- django_code/core/settings.py | 10 +------ infra/production/entrypoint.sh | 4 +-- infra/testing/entrypoint.sh | 2 -- 14 files changed, 23 insertions(+), 94 deletions(-) delete mode 100644 django_code/apps/streaming_redirect/__init__.py delete mode 100644 django_code/apps/streaming_redirect/admin.py delete mode 100644 django_code/apps/streaming_redirect/apps.py delete mode 100644 django_code/apps/streaming_redirect/migrations/0001_initial.py delete mode 100644 django_code/apps/streaming_redirect/migrations/__init__.py delete mode 100644 django_code/apps/streaming_redirect/models.py delete mode 100644 django_code/apps/streaming_redirect/tests.py delete mode 100644 django_code/apps/streaming_redirect/views.py diff --git a/README.md b/README.md index 7dca65f..ce385ad 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,6 @@ python django_code/manage.py makemigrations job python django_code/manage.py makemigrations telegram python django_code/manage.py makemigrations podcast python django_code/manage.py makemigrations streaming -python django_code/manage.py makemigrations streaming_redirect python django_code/manage.py migrate python django_code/manage.py migrate --database=cloudmanager_db @@ -22,7 +21,6 @@ python django_code/manage.py migrate --database=job_db python django_code/manage.py migrate --database=telegram_db python django_code/manage.py migrate --database=podcast_db python django_code/manage.py migrate --database=streaming_db -python django_code/manage.py migrate --database=streaming_redirect_db ``` ### Database debug @@ -35,7 +33,6 @@ create database job; create database telegram; create database podcast; create database streaming; -create database streaming_redirect; @@ -46,7 +43,6 @@ drop database job; drop database telegram; drop database podcast; drop database streaming; -drop database streaming_redirect; ``` diff --git a/django_code/apps/streaming/models.py b/django_code/apps/streaming/models.py index 640f865..1fde17e 100644 --- a/django_code/apps/streaming/models.py +++ b/django_code/apps/streaming/models.py @@ -9,3 +9,20 @@ class streamingData(models.Model): class Meta: db_table = 'streaming' + +class urlData(models.Model): + def sanitize(self): + print(self) + return 1 + + name = models.CharField(primary_key=True,max_length=1000, help_text="Name of the show") + url_example = models.CharField(max_length=1000, help_text="https://www.1shows.org/tv/456-the-simpsons?streaming=true&season=18&episode=5") + prefix = models.CharField(max_length=1000, help_text="https://www.1shows.org/tv/456-the-simpsons?streaming=true&season=",blank=True, null=True) + infix = models.CharField(max_length=1000, help_text="&episode=",blank=True, null=True) + suffix = models.CharField(max_length=1000, help_text="" ,blank=True, null=True) + addedDate = models.DateField('Published', blank=True, null=True, auto_now_add=True) + alias = models.CharField(max_length=1000, default=sanitize) + + + class Meta: + db_table = 'redirectUrl' \ No newline at end of file diff --git a/django_code/apps/streaming_redirect/__init__.py b/django_code/apps/streaming_redirect/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/django_code/apps/streaming_redirect/admin.py b/django_code/apps/streaming_redirect/admin.py deleted file mode 100644 index 8c38f3f..0000000 --- a/django_code/apps/streaming_redirect/admin.py +++ /dev/null @@ -1,3 +0,0 @@ -from django.contrib import admin - -# Register your models here. diff --git a/django_code/apps/streaming_redirect/apps.py b/django_code/apps/streaming_redirect/apps.py deleted file mode 100644 index 20490bf..0000000 --- a/django_code/apps/streaming_redirect/apps.py +++ /dev/null @@ -1,7 +0,0 @@ -from django.apps import AppConfig - - -class StreamingRedirectConfig(AppConfig): - default_auto_field = 'django.db.models.BigAutoField' - name = 'apps.streaming_redirect' - label = 'streaming_redirect' diff --git a/django_code/apps/streaming_redirect/migrations/0001_initial.py b/django_code/apps/streaming_redirect/migrations/0001_initial.py deleted file mode 100644 index 25a1a55..0000000 --- a/django_code/apps/streaming_redirect/migrations/0001_initial.py +++ /dev/null @@ -1,30 +0,0 @@ -# Generated by Django 4.2.30 on 2026-08-07 10:54 - -import apps.streaming_redirect.models -from django.db import migrations, models - - -class Migration(migrations.Migration): - - initial = True - - dependencies = [ - ] - - operations = [ - migrations.CreateModel( - name='urlData', - fields=[ - ('name', models.CharField(help_text='Name of the show', max_length=1000, primary_key=True, serialize=False)), - ('url_example', models.CharField(help_text='https://www.1shows.org/tv/456-the-simpsons?streaming=true&season=18&episode=5', max_length=1000)), - ('prefix', models.CharField(blank=True, help_text='https://www.1shows.org/tv/456-the-simpsons?streaming=true&season=', max_length=1000, null=True)), - ('infix', models.CharField(blank=True, help_text='&episode=', max_length=1000, null=True)), - ('suffix', models.CharField(blank=True, max_length=1000, null=True)), - ('addedDate', models.DateField(auto_now_add=True, null=True, verbose_name='Published')), - ('alias', models.CharField(default=apps.streaming_redirect.models.urlData.sanitize, max_length=1000)), - ], - options={ - 'db_table': 'redirectUrl', - }, - ), - ] diff --git a/django_code/apps/streaming_redirect/migrations/__init__.py b/django_code/apps/streaming_redirect/migrations/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/django_code/apps/streaming_redirect/models.py b/django_code/apps/streaming_redirect/models.py deleted file mode 100644 index 1737edc..0000000 --- a/django_code/apps/streaming_redirect/models.py +++ /dev/null @@ -1,19 +0,0 @@ -from django.db import models - -# Create your models here. -class urlData(models.Model): - def sanitize(self): - print(self) - return 1 - - name = models.CharField(primary_key=True,max_length=1000, help_text="Name of the show") - url_example = models.CharField(max_length=1000, help_text="https://www.1shows.org/tv/456-the-simpsons?streaming=true&season=18&episode=5") - prefix = models.CharField(max_length=1000, help_text="https://www.1shows.org/tv/456-the-simpsons?streaming=true&season=",blank=True, null=True) - infix = models.CharField(max_length=1000, help_text="&episode=",blank=True, null=True) - suffix = models.CharField(max_length=1000, help_text="" ,blank=True, null=True) - addedDate = models.DateField('Published', blank=True, null=True, auto_now_add=True) - alias = models.CharField(max_length=1000, default=sanitize) - - - class Meta: - db_table = 'redirectUrl' \ No newline at end of file diff --git a/django_code/apps/streaming_redirect/tests.py b/django_code/apps/streaming_redirect/tests.py deleted file mode 100644 index 7ce503c..0000000 --- a/django_code/apps/streaming_redirect/tests.py +++ /dev/null @@ -1,3 +0,0 @@ -from django.test import TestCase - -# Create your tests here. diff --git a/django_code/apps/streaming_redirect/views.py b/django_code/apps/streaming_redirect/views.py deleted file mode 100644 index 91ea44a..0000000 --- a/django_code/apps/streaming_redirect/views.py +++ /dev/null @@ -1,3 +0,0 @@ -from django.shortcuts import render - -# Create your views here. diff --git a/django_code/core/routers.py b/django_code/core/routers.py index ea65120..cc62513 100644 --- a/django_code/core/routers.py +++ b/django_code/core/routers.py @@ -30,9 +30,6 @@ class ProjectDatabaseRouter: if model._meta.app_label == 'streaming': return 'streaming_db' - if model._meta.app_label == 'streaming_redirect': - return 'streaming_redirect_db' - return 'default' def db_for_write(self, model, **hints): @@ -59,17 +56,14 @@ class ProjectDatabaseRouter: if model._meta.app_label == 'streaming': return 'streaming_db' - if model._meta.app_label == 'streaming_redirect': - return 'streaming_redirect_db' - return 'default' def allow_relation(self, obj1, obj2, **hints): """Allow relations if both models are in the same database.""" # Prevents accidental foreign key relationships across different physical DBs if ( - obj1._meta.app_label in ['cloudmanager', 'simpsons', 'redirect', 'job', 'telegram', 'podcast', 'streaming', 'streaming_redirect'] or - obj2._meta.app_label in ['cloudmanager', 'simpsons', 'redirect', 'job', 'telegram', 'podcast', 'streaming', 'streaming_redirect'] + obj1._meta.app_label in ['cloudmanager', 'simpsons', 'redirect', 'job', 'telegram', 'podcast', 'streaming'] or + obj2._meta.app_label in ['cloudmanager', 'simpsons', 'redirect', 'job', 'telegram', 'podcast', 'streaming'] ): return obj1._meta.app_label == obj2._meta.app_label return None @@ -98,11 +92,8 @@ class ProjectDatabaseRouter: if app_label == 'streaming': return db == 'streaming_db' - if app_label == 'streaming_redirect': - return db == 'streaming_redirect_db' - # Ensure default Django apps (auth, sessions, etc.) don't migrate into simpsons/cloudmanager - if db in ['cloudmanager_db', 'simpsons_db', 'redirect_db', 'job_db', 'telegram_db', 'podcast_db', 'streaming_db', 'streaming_redirect_db']: + if db in ['cloudmanager_db', 'simpsons_db', 'redirect_db', 'job_db', 'telegram_db', 'podcast_db', 'streaming_db']: return False return None diff --git a/django_code/core/settings.py b/django_code/core/settings.py index 58fd02b..ca97e09 100644 --- a/django_code/core/settings.py +++ b/django_code/core/settings.py @@ -51,7 +51,6 @@ INSTALLED_APPS = [ 'apps.telegram_communication.apps.TelegramCommunicationConfig', 'apps.podcast_aggregator.apps.PodcastAggregatorConfig', 'apps.streaming.apps.StreamingConfig', - 'apps.streaming_redirect.apps.StreamingRedirectConfig', 'import_export', 'djangoql', ] @@ -164,14 +163,7 @@ DATABASES = { 'HOST': os.environ.get('DB_HOST'), 'PORT': os.environ.get('DB_PORT'), }, - 'streaming_redirect_db': { - 'ENGINE': 'django.db.backends.postgresql', - 'NAME': 'streaming_redirect', - 'USER': os.environ.get('DB_USERNAME'), - 'PASSWORD': os.environ.get('DB_PASSWORD'), - 'HOST': os.environ.get('DB_HOST'), - 'PORT': os.environ.get('DB_PORT'), - }, + } DATABASE_ROUTERS = ['core.routers.ProjectDatabaseRouter'] #DATABASE_ROUTERS = [] diff --git a/infra/production/entrypoint.sh b/infra/production/entrypoint.sh index dfa8492..828b5c1 100644 --- a/infra/production/entrypoint.sh +++ b/infra/production/entrypoint.sh @@ -8,7 +8,7 @@ python django_code/manage.py makemigrations job python django_code/manage.py makemigrations telegram python django_code/manage.py makemigrations podcast python django_code/manage.py makemigrations streaming -python django_code/manage.py makemigrations streaming_redirect + python django_code/manage.py migrate python django_code/manage.py migrate --database=cloudmanager_db @@ -18,7 +18,7 @@ python django_code/manage.py migrate --database=job_db python django_code/manage.py migrate --database=telegram_db python django_code/manage.py migrate --database=podcast_db python django_code/manage.py migrate --database=streaming_db -python django_code/manage.py migrate --database=streaming_redirect_db + python django_code/manage.py runserver "0.0.0.0:8000" diff --git a/infra/testing/entrypoint.sh b/infra/testing/entrypoint.sh index 0071164..44f6586 100644 --- a/infra/testing/entrypoint.sh +++ b/infra/testing/entrypoint.sh @@ -15,7 +15,6 @@ python django_code/manage.py makemigrations job python django_code/manage.py makemigrations telegram python django_code/manage.py makemigrations podcast python django_code/manage.py makemigrations streaming -python django_code/manage.py makemigrations streaming_redirect python django_code/manage.py migrate python django_code/manage.py migrate --database=cloudmanager_db @@ -25,7 +24,6 @@ python django_code/manage.py migrate --database=job_db python django_code/manage.py migrate --database=telegram_db python django_code/manage.py migrate --database=podcast_db python django_code/manage.py migrate --database=streaming_db -python django_code/manage.py migrate --database=streaming_redirect_db python django_code/manage.py runserver "0.0.0.0:8000" From 60aafb55b8a50cdcffa21d51751d07512559505b Mon Sep 17 00:00:00 2001 From: pierregeeraert Date: Fri, 7 Aug 2026 12:02:01 +0100 Subject: [PATCH 07/12] adding also new migrations --- .../apps/streaming/migrations/0003_urldata.py | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 django_code/apps/streaming/migrations/0003_urldata.py diff --git a/django_code/apps/streaming/migrations/0003_urldata.py b/django_code/apps/streaming/migrations/0003_urldata.py new file mode 100644 index 0000000..3dce65b --- /dev/null +++ b/django_code/apps/streaming/migrations/0003_urldata.py @@ -0,0 +1,29 @@ +# Generated by Django 4.2.30 on 2026-08-07 11:00 + +import apps.streaming.models +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('streaming', '0002_streamingdata_result'), + ] + + operations = [ + migrations.CreateModel( + name='urlData', + fields=[ + ('name', models.CharField(help_text='Name of the show', max_length=1000, primary_key=True, serialize=False)), + ('url_example', models.CharField(help_text='https://www.1shows.org/tv/456-the-simpsons?streaming=true&season=18&episode=5', max_length=1000)), + ('prefix', models.CharField(blank=True, help_text='https://www.1shows.org/tv/456-the-simpsons?streaming=true&season=', max_length=1000, null=True)), + ('infix', models.CharField(blank=True, help_text='&episode=', max_length=1000, null=True)), + ('suffix', models.CharField(blank=True, max_length=1000, null=True)), + ('addedDate', models.DateField(auto_now_add=True, null=True, verbose_name='Published')), + ('alias', models.CharField(default=apps.streaming.models.urlData.sanitize, max_length=1000)), + ], + options={ + 'db_table': 'redirectUrl', + }, + ), + ] From de1977fd2a70635d556dd80612146cc8a35b078d Mon Sep 17 00:00:00 2001 From: pierregeeraert Date: Fri, 7 Aug 2026 16:26:50 +0100 Subject: [PATCH 08/12] work on the redirection --- django_code/apps/streaming/admin.py | 11 ++++-- ...ldata.py => 0003_streamingredirectdata.py} | 8 ++--- ...gredirectdata_episode_to_watch_and_more.py | 28 +++++++++++++++ .../0005_streamingredirectdata_hello.py | 18 ++++++++++ ...ve_streamingredirectdata_hello_and_more.py | 22 ++++++++++++ ...gdata_streamingsitetestingdata_and_more.py | 22 ++++++++++++ django_code/apps/streaming/models.py | 35 +++++++++++++++---- 7 files changed, 130 insertions(+), 14 deletions(-) rename django_code/apps/streaming/migrations/{0003_urldata.py => 0003_streamingredirectdata.py} (85%) create mode 100644 django_code/apps/streaming/migrations/0004_streamingredirectdata_episode_to_watch_and_more.py create mode 100644 django_code/apps/streaming/migrations/0005_streamingredirectdata_hello.py create mode 100644 django_code/apps/streaming/migrations/0006_remove_streamingredirectdata_hello_and_more.py create mode 100644 django_code/apps/streaming/migrations/0007_rename_streamingdata_streamingsitetestingdata_and_more.py diff --git a/django_code/apps/streaming/admin.py b/django_code/apps/streaming/admin.py index 88d825d..895b184 100644 --- a/django_code/apps/streaming/admin.py +++ b/django_code/apps/streaming/admin.py @@ -1,7 +1,7 @@ from django.contrib import admin from django.utils.html import format_html from import_export.admin import ImportExportModelAdmin -from .models import streamingData +from .models import StreamingSiteTestingData,StreamingRedirectData from .utils import full_testing from urllib.parse import urlsplit, urlunsplit @@ -43,7 +43,7 @@ def urlcleaning(modeladmin, request, queryset): print("Cleaning :"+str(base_url)) return 0 -@admin.register(streamingData) +@admin.register(StreamingSiteTestingData) class streamingAdmin(ImportExportModelAdmin): list_display = ['clickable_links','result_colored','newstatus'] fields = ['url'] @@ -68,4 +68,9 @@ class streamingAdmin(ImportExportModelAdmin): if obj.status != '200': return format_html('
{}
', obj.status) #return obj.status - \ No newline at end of file + + +@admin.register(StreamingRedirectData) +class StreamingRedirectAdmin(ImportExportModelAdmin): + list_display = ['name','season_to_watch','episode_to_watch','addedDate','url_example','addedDate','alias'] + fields = ['name','season_to_watch','episode_to_watch','url_example','prefix','infix','suffix','alias','seasonInformation'] diff --git a/django_code/apps/streaming/migrations/0003_urldata.py b/django_code/apps/streaming/migrations/0003_streamingredirectdata.py similarity index 85% rename from django_code/apps/streaming/migrations/0003_urldata.py rename to django_code/apps/streaming/migrations/0003_streamingredirectdata.py index 3dce65b..208d7cc 100644 --- a/django_code/apps/streaming/migrations/0003_urldata.py +++ b/django_code/apps/streaming/migrations/0003_streamingredirectdata.py @@ -1,4 +1,4 @@ -# Generated by Django 4.2.30 on 2026-08-07 11:00 +# Generated by Django 4.2.30 on 2026-08-07 13:13 import apps.streaming.models from django.db import migrations, models @@ -12,7 +12,7 @@ class Migration(migrations.Migration): operations = [ migrations.CreateModel( - name='urlData', + name='StreamingRedirectData', fields=[ ('name', models.CharField(help_text='Name of the show', max_length=1000, primary_key=True, serialize=False)), ('url_example', models.CharField(help_text='https://www.1shows.org/tv/456-the-simpsons?streaming=true&season=18&episode=5', max_length=1000)), @@ -20,10 +20,10 @@ class Migration(migrations.Migration): ('infix', models.CharField(blank=True, help_text='&episode=', max_length=1000, null=True)), ('suffix', models.CharField(blank=True, max_length=1000, null=True)), ('addedDate', models.DateField(auto_now_add=True, null=True, verbose_name='Published')), - ('alias', models.CharField(default=apps.streaming.models.urlData.sanitize, max_length=1000)), + ('alias', models.CharField(default=apps.streaming.models.StreamingRedirectData.sanitize, max_length=1000)), ], options={ - 'db_table': 'redirectUrl', + 'db_table': 'StreamingRedirect', }, ), ] diff --git a/django_code/apps/streaming/migrations/0004_streamingredirectdata_episode_to_watch_and_more.py b/django_code/apps/streaming/migrations/0004_streamingredirectdata_episode_to_watch_and_more.py new file mode 100644 index 0000000..bc762be --- /dev/null +++ b/django_code/apps/streaming/migrations/0004_streamingredirectdata_episode_to_watch_and_more.py @@ -0,0 +1,28 @@ +# Generated by Django 4.2.30 on 2026-08-07 14:02 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('streaming', '0003_streamingredirectdata'), + ] + + operations = [ + migrations.AddField( + model_name='streamingredirectdata', + name='episode_to_watch', + field=models.IntegerField(default=1), + ), + migrations.AddField( + model_name='streamingredirectdata', + name='season_to_watch', + field=models.IntegerField(default=1), + ), + migrations.AlterField( + model_name='streamingredirectdata', + name='alias', + field=models.CharField(blank=True, max_length=1000, null=True), + ), + ] diff --git a/django_code/apps/streaming/migrations/0005_streamingredirectdata_hello.py b/django_code/apps/streaming/migrations/0005_streamingredirectdata_hello.py new file mode 100644 index 0000000..7301f8b --- /dev/null +++ b/django_code/apps/streaming/migrations/0005_streamingredirectdata_hello.py @@ -0,0 +1,18 @@ +# Generated by Django 4.2.30 on 2026-08-07 14:49 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('streaming', '0004_streamingredirectdata_episode_to_watch_and_more'), + ] + + operations = [ + migrations.AddField( + model_name='streamingredirectdata', + name='hello', + field=models.CharField(blank=True, max_length=1000, null=True), + ), + ] diff --git a/django_code/apps/streaming/migrations/0006_remove_streamingredirectdata_hello_and_more.py b/django_code/apps/streaming/migrations/0006_remove_streamingredirectdata_hello_and_more.py new file mode 100644 index 0000000..2a9df99 --- /dev/null +++ b/django_code/apps/streaming/migrations/0006_remove_streamingredirectdata_hello_and_more.py @@ -0,0 +1,22 @@ +# Generated by Django 4.2.30 on 2026-08-07 14:55 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('streaming', '0005_streamingredirectdata_hello'), + ] + + operations = [ + migrations.RemoveField( + model_name='streamingredirectdata', + name='hello', + ), + migrations.AddField( + model_name='streamingredirectdata', + name='seasonInformation', + field=models.JSONField(blank=True, max_length=1000, null=True), + ), + ] diff --git a/django_code/apps/streaming/migrations/0007_rename_streamingdata_streamingsitetestingdata_and_more.py b/django_code/apps/streaming/migrations/0007_rename_streamingdata_streamingsitetestingdata_and_more.py new file mode 100644 index 0000000..1581313 --- /dev/null +++ b/django_code/apps/streaming/migrations/0007_rename_streamingdata_streamingsitetestingdata_and_more.py @@ -0,0 +1,22 @@ +# Generated by Django 4.2.30 on 2026-08-07 15:22 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('streaming', '0006_remove_streamingredirectdata_hello_and_more'), + ] + + operations = [ + migrations.RenameModel( + old_name='streamingData', + new_name='StreamingSiteTestingData', + ), + migrations.AlterField( + model_name='streamingredirectdata', + name='seasonInformation', + field=models.JSONField(blank=True, default='', max_length=1000), + ), + ] diff --git a/django_code/apps/streaming/models.py b/django_code/apps/streaming/models.py index 1fde17e..e7d5f3a 100644 --- a/django_code/apps/streaming/models.py +++ b/django_code/apps/streaming/models.py @@ -1,7 +1,10 @@ from django.db import models +from apps.betaserie.utils import betaserieUtils + + # Create your models here. -class streamingData(models.Model): +class StreamingSiteTestingData(models.Model): url = models.CharField(max_length=1000) addedDate = models.DateField('Published', blank=True, null=True, auto_now_add=True) status = models.CharField(max_length=1000, blank=True, null=True) @@ -10,19 +13,37 @@ class streamingData(models.Model): class Meta: db_table = 'streaming' -class urlData(models.Model): - def sanitize(self): - print(self) - return 1 + + +class StreamingRedirectData(models.Model): name = models.CharField(primary_key=True,max_length=1000, help_text="Name of the show") + season_to_watch = models.IntegerField(null=False,default=1) + episode_to_watch = models.IntegerField(null=False,default=1) url_example = models.CharField(max_length=1000, help_text="https://www.1shows.org/tv/456-the-simpsons?streaming=true&season=18&episode=5") prefix = models.CharField(max_length=1000, help_text="https://www.1shows.org/tv/456-the-simpsons?streaming=true&season=",blank=True, null=True) infix = models.CharField(max_length=1000, help_text="&episode=",blank=True, null=True) suffix = models.CharField(max_length=1000, help_text="" ,blank=True, null=True) addedDate = models.DateField('Published', blank=True, null=True, auto_now_add=True) - alias = models.CharField(max_length=1000, default=sanitize) + alias = models.CharField(max_length=1000, null=True,blank=True) + seasonInformation = models.JSONField(default="",max_length=1000,blank=True) + def sanitize(self, name): + return name.replace(" ", "") + def season_information(self, serie_name): + betaserie = betaserieUtils() + print(serie_name) + print(betaserie.identify_serie(serie_name)) + return betaserie.series_information(betaserie.identify_serie(serie_name))[0] + + + def save(self, *args, **kwargs): + if not self.seasonInformation : + self.seasonInformation = self.season_information(self.name) + if not self.alias: + self.alias = self.sanitize(self.name) + super().save(*args, **kwargs) + class Meta: - db_table = 'redirectUrl' \ No newline at end of file + db_table = 'StreamingRedirect' \ No newline at end of file From b6e60764bd2dd829498228c18fb17379c649836f Mon Sep 17 00:00:00 2001 From: pierregeeraert Date: Fri, 7 Aug 2026 16:29:29 +0100 Subject: [PATCH 09/12] change default --- django_code/apps/streaming/models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/django_code/apps/streaming/models.py b/django_code/apps/streaming/models.py index e7d5f3a..314130f 100644 --- a/django_code/apps/streaming/models.py +++ b/django_code/apps/streaming/models.py @@ -26,7 +26,7 @@ class StreamingRedirectData(models.Model): suffix = models.CharField(max_length=1000, help_text="" ,blank=True, null=True) addedDate = models.DateField('Published', blank=True, null=True, auto_now_add=True) alias = models.CharField(max_length=1000, null=True,blank=True) - seasonInformation = models.JSONField(default="",max_length=1000,blank=True) + seasonInformation = models.JSONField(default="{}",max_length=1000,blank=True) def sanitize(self, name): return name.replace(" ", "") From 8af967b4d3dd8e0c6df865bebc01a000c9bbcc18 Mon Sep 17 00:00:00 2001 From: pierregeeraert Date: Fri, 7 Aug 2026 16:34:07 +0100 Subject: [PATCH 10/12] change default --- django_code/apps/streaming/models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/django_code/apps/streaming/models.py b/django_code/apps/streaming/models.py index 314130f..a686e99 100644 --- a/django_code/apps/streaming/models.py +++ b/django_code/apps/streaming/models.py @@ -26,7 +26,7 @@ class StreamingRedirectData(models.Model): suffix = models.CharField(max_length=1000, help_text="" ,blank=True, null=True) addedDate = models.DateField('Published', blank=True, null=True, auto_now_add=True) alias = models.CharField(max_length=1000, null=True,blank=True) - seasonInformation = models.JSONField(default="{}",max_length=1000,blank=True) + seasonInformation = models.JSONField(default=dict, blank=True) def sanitize(self, name): return name.replace(" ", "") From e66c7034f06391b676bbc5bf7af2d1e394ebe518 Mon Sep 17 00:00:00 2001 From: pierregeeraert Date: Fri, 7 Aug 2026 17:17:26 +0100 Subject: [PATCH 11/12] finishing the design of the admin page --- django_code/apps/streaming/admin.py | 19 +++++++++++++-- ...mingredirectdata_randomviewing_and_more.py | 23 +++++++++++++++++++ django_code/apps/streaming/models.py | 1 + django_code/apps/streaming/utils.py | 3 ++- 4 files changed, 43 insertions(+), 3 deletions(-) create mode 100644 django_code/apps/streaming/migrations/0008_streamingredirectdata_randomviewing_and_more.py diff --git a/django_code/apps/streaming/admin.py b/django_code/apps/streaming/admin.py index 895b184..04ef6d9 100644 --- a/django_code/apps/streaming/admin.py +++ b/django_code/apps/streaming/admin.py @@ -72,5 +72,20 @@ class streamingAdmin(ImportExportModelAdmin): @admin.register(StreamingRedirectData) class StreamingRedirectAdmin(ImportExportModelAdmin): - list_display = ['name','season_to_watch','episode_to_watch','addedDate','url_example','addedDate','alias'] - fields = ['name','season_to_watch','episode_to_watch','url_example','prefix','infix','suffix','alias','seasonInformation'] + list_display = ['name','season_to_watch','episode_to_watch','randomViewing','url_example','addedDate','alias'] + #fields = ['name','season_to_watch','episode_to_watch','url_example','prefix','infix','suffix','alias','randomViewing','seasonInformation'] + fieldsets = ( + ( + 'Serie', { + 'fields': ('name', 'season_to_watch', 'episode_to_watch','randomViewing') + }), + ( + 'url', { + 'fields': (('prefix','infix','suffix'),'url_example') + }), + ( + 'Information', { + "classes": ["collapse"], + 'fields': ('seasonInformation','alias') + }), + ) \ No newline at end of file diff --git a/django_code/apps/streaming/migrations/0008_streamingredirectdata_randomviewing_and_more.py b/django_code/apps/streaming/migrations/0008_streamingredirectdata_randomviewing_and_more.py new file mode 100644 index 0000000..17cd169 --- /dev/null +++ b/django_code/apps/streaming/migrations/0008_streamingredirectdata_randomviewing_and_more.py @@ -0,0 +1,23 @@ +# Generated by Django 4.2.30 on 2026-08-07 15:59 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('streaming', '0007_rename_streamingdata_streamingsitetestingdata_and_more'), + ] + + operations = [ + migrations.AddField( + model_name='streamingredirectdata', + name='randomViewing', + field=models.BooleanField(default=False), + ), + migrations.AlterField( + model_name='streamingredirectdata', + name='seasonInformation', + field=models.JSONField(blank=True, default=dict), + ), + ] diff --git a/django_code/apps/streaming/models.py b/django_code/apps/streaming/models.py index a686e99..df53c3b 100644 --- a/django_code/apps/streaming/models.py +++ b/django_code/apps/streaming/models.py @@ -27,6 +27,7 @@ class StreamingRedirectData(models.Model): addedDate = models.DateField('Published', blank=True, null=True, auto_now_add=True) alias = models.CharField(max_length=1000, null=True,blank=True) seasonInformation = models.JSONField(default=dict, blank=True) + randomViewing = models.BooleanField(default=False) def sanitize(self, name): return name.replace(" ", "") diff --git a/django_code/apps/streaming/utils.py b/django_code/apps/streaming/utils.py index b873d5f..8aba529 100644 --- a/django_code/apps/streaming/utils.py +++ b/django_code/apps/streaming/utils.py @@ -35,4 +35,5 @@ def test_website(url_website,bool_proxy=False): except Exception as err: print(f"{type(err).__name__} was raised: {err}") status = "exception not targeted" - return status \ No newline at end of file + return status + From e85c372ad82d03de18a6559c1130b5222c3aee62 Mon Sep 17 00:00:00 2001 From: pierregeeraert Date: Tue, 25 Aug 2026 16:24:43 +0100 Subject: [PATCH 12/12] following episode function good, need to work on the random episode and more admin stuff --- django_code/apps/streaming/admin.py | 9 ++- ..._streamingredirectdata_episode_and_more.py | 23 ++++++ ...010_alter_streamingredirectdata_episode.py | 18 +++++ ...1_streamingredirectdata_betaserieshowid.py | 18 +++++ ...r_streamingredirectdata_betaserieshowid.py | 18 +++++ django_code/apps/streaming/models.py | 15 +++- django_code/apps/streaming/utils.py | 19 +++++ django_code/apps/streaming/views.py | 75 ++++++++++++++++++- django_code/core/urls.py | 6 ++ 9 files changed, 193 insertions(+), 8 deletions(-) create mode 100644 django_code/apps/streaming/migrations/0009_rename_episode_to_watch_streamingredirectdata_episode_and_more.py create mode 100644 django_code/apps/streaming/migrations/0010_alter_streamingredirectdata_episode.py create mode 100644 django_code/apps/streaming/migrations/0011_streamingredirectdata_betaserieshowid.py create mode 100644 django_code/apps/streaming/migrations/0012_alter_streamingredirectdata_betaserieshowid.py diff --git a/django_code/apps/streaming/admin.py b/django_code/apps/streaming/admin.py index 04ef6d9..bb77350 100644 --- a/django_code/apps/streaming/admin.py +++ b/django_code/apps/streaming/admin.py @@ -72,20 +72,21 @@ class streamingAdmin(ImportExportModelAdmin): @admin.register(StreamingRedirectData) class StreamingRedirectAdmin(ImportExportModelAdmin): - list_display = ['name','season_to_watch','episode_to_watch','randomViewing','url_example','addedDate','alias'] - #fields = ['name','season_to_watch','episode_to_watch','url_example','prefix','infix','suffix','alias','randomViewing','seasonInformation'] + list_display = ['name','season','episode','randomViewing','url_example','addedDate','alias'] + #fields = ['name','season','episode','url_example','prefix','infix','suffix','alias','randomViewing','seasonInformation'] fieldsets = ( ( 'Serie', { - 'fields': ('name', 'season_to_watch', 'episode_to_watch','randomViewing') + 'fields': ('name', 'season', 'episode','randomViewing') }), ( 'url', { + 'fields': (('prefix','infix','suffix'),'url_example') }), ( 'Information', { "classes": ["collapse"], - 'fields': ('seasonInformation','alias') + 'fields': ('seasonInformation','alias','betaserieShowId') }), ) \ No newline at end of file diff --git a/django_code/apps/streaming/migrations/0009_rename_episode_to_watch_streamingredirectdata_episode_and_more.py b/django_code/apps/streaming/migrations/0009_rename_episode_to_watch_streamingredirectdata_episode_and_more.py new file mode 100644 index 0000000..8de3284 --- /dev/null +++ b/django_code/apps/streaming/migrations/0009_rename_episode_to_watch_streamingredirectdata_episode_and_more.py @@ -0,0 +1,23 @@ +# Generated by Django 4.2.30 on 2026-08-25 14:06 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('streaming', '0008_streamingredirectdata_randomviewing_and_more'), + ] + + operations = [ + migrations.RenameField( + model_name='streamingredirectdata', + old_name='episode_to_watch', + new_name='episode', + ), + migrations.RenameField( + model_name='streamingredirectdata', + old_name='season_to_watch', + new_name='season', + ), + ] diff --git a/django_code/apps/streaming/migrations/0010_alter_streamingredirectdata_episode.py b/django_code/apps/streaming/migrations/0010_alter_streamingredirectdata_episode.py new file mode 100644 index 0000000..4dc4be3 --- /dev/null +++ b/django_code/apps/streaming/migrations/0010_alter_streamingredirectdata_episode.py @@ -0,0 +1,18 @@ +# Generated by Django 4.2.30 on 2026-08-25 14:08 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('streaming', '0009_rename_episode_to_watch_streamingredirectdata_episode_and_more'), + ] + + operations = [ + migrations.AlterField( + model_name='streamingredirectdata', + name='episode', + field=models.IntegerField(default=0), + ), + ] diff --git a/django_code/apps/streaming/migrations/0011_streamingredirectdata_betaserieshowid.py b/django_code/apps/streaming/migrations/0011_streamingredirectdata_betaserieshowid.py new file mode 100644 index 0000000..6392400 --- /dev/null +++ b/django_code/apps/streaming/migrations/0011_streamingredirectdata_betaserieshowid.py @@ -0,0 +1,18 @@ +# Generated by Django 4.2.30 on 2026-08-25 15:13 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('streaming', '0010_alter_streamingredirectdata_episode'), + ] + + operations = [ + migrations.AddField( + model_name='streamingredirectdata', + name='betaserieShowId', + field=models.IntegerField(default=0), + ), + ] diff --git a/django_code/apps/streaming/migrations/0012_alter_streamingredirectdata_betaserieshowid.py b/django_code/apps/streaming/migrations/0012_alter_streamingredirectdata_betaserieshowid.py new file mode 100644 index 0000000..b2232ac --- /dev/null +++ b/django_code/apps/streaming/migrations/0012_alter_streamingredirectdata_betaserieshowid.py @@ -0,0 +1,18 @@ +# Generated by Django 4.2.30 on 2026-08-25 15:14 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('streaming', '0011_streamingredirectdata_betaserieshowid'), + ] + + operations = [ + migrations.AlterField( + model_name='streamingredirectdata', + name='betaserieShowId', + field=models.IntegerField(blank=True, null=True), + ), + ] diff --git a/django_code/apps/streaming/models.py b/django_code/apps/streaming/models.py index df53c3b..3256e10 100644 --- a/django_code/apps/streaming/models.py +++ b/django_code/apps/streaming/models.py @@ -18,8 +18,8 @@ class StreamingSiteTestingData(models.Model): class StreamingRedirectData(models.Model): name = models.CharField(primary_key=True,max_length=1000, help_text="Name of the show") - season_to_watch = models.IntegerField(null=False,default=1) - episode_to_watch = models.IntegerField(null=False,default=1) + season = models.IntegerField(null=False,default=1) + episode = models.IntegerField(null=False,default=0) url_example = models.CharField(max_length=1000, help_text="https://www.1shows.org/tv/456-the-simpsons?streaming=true&season=18&episode=5") prefix = models.CharField(max_length=1000, help_text="https://www.1shows.org/tv/456-the-simpsons?streaming=true&season=",blank=True, null=True) infix = models.CharField(max_length=1000, help_text="&episode=",blank=True, null=True) @@ -27,6 +27,7 @@ class StreamingRedirectData(models.Model): addedDate = models.DateField('Published', blank=True, null=True, auto_now_add=True) alias = models.CharField(max_length=1000, null=True,blank=True) seasonInformation = models.JSONField(default=dict, blank=True) + betaserieShowId = models.IntegerField(null=True,blank=True) randomViewing = models.BooleanField(default=False) def sanitize(self, name): @@ -37,13 +38,21 @@ class StreamingRedirectData(models.Model): print(serie_name) print(betaserie.identify_serie(serie_name)) return betaserie.series_information(betaserie.identify_serie(serie_name))[0] - + + def betaserie_show_id(self,serie_name): + betaserie = betaserieUtils() + print(serie_name) + print(betaserie.identify_serie(serie_name)) + return betaserie.identify_serie(serie_name) + def save(self, *args, **kwargs): if not self.seasonInformation : self.seasonInformation = self.season_information(self.name) if not self.alias: self.alias = self.sanitize(self.name) + if not self.betaserieShowId: + self.betaserieShowId = self.betaserie_show_id(self.name) super().save(*args, **kwargs) class Meta: diff --git a/django_code/apps/streaming/utils.py b/django_code/apps/streaming/utils.py index 8aba529..40f31c4 100644 --- a/django_code/apps/streaming/utils.py +++ b/django_code/apps/streaming/utils.py @@ -37,3 +37,22 @@ def test_website(url_website,bool_proxy=False): status = "exception not targeted" return status + +def randomEpisode(): + return 0,0 + +def followingEpisode(season,episode,seasonInformation): + lastEpisode = False + #check if the episode is the last one of the season + if (episode < seasonInformation[season]['episodes']): + #the current episode is not the + episode += 1 + + #check if the season is the last one + elif((season+1) < (len(seasonInformation)-1)): + season += 1 + episode = 1 + else: + print("You watched the last episode of the serie") + lastEpisode = True + return season,episode,lastEpisode \ No newline at end of file diff --git a/django_code/apps/streaming/views.py b/django_code/apps/streaming/views.py index 91ea44a..1c56fdc 100644 --- a/django_code/apps/streaming/views.py +++ b/django_code/apps/streaming/views.py @@ -1,3 +1,76 @@ -from django.shortcuts import render +from django.http import HttpResponse +from django.shortcuts import redirect +from six import print_ +from .models import StreamingRedirectData +from .utils import randomEpisode,followingEpisode +from apps.betaserie.utils import betaserieUtils + +betaserie = betaserieUtils() + # Create your views here. +def hello(request): + return HttpResponse('

Hello streaming view!

') + + +def streamingRedirect(request,alias): + streaming_object = StreamingRedirectData.objects.filter(alias=alias) + + episode = streaming_object.values('episode')[0]['episode'] + season = streaming_object.values('season')[0]['season'] + seasonInformation = streaming_object.values('seasonInformation')[0]['seasonInformation'] + + url_prefix = streaming_object.values('prefix')[0]['prefix'] + url_infix = streaming_object.values('infix')[0]['infix'] + url_suffix = streaming_object.values('suffix')[0]['suffix'] or '' + + betaserieShowId = streaming_object.values('betaserieShowId')[0]['betaserieShowId'] + + print(url_prefix) + + print(season) + print(episode) + + + print(seasonInformation) + + value = str(streaming_object.values('url_example')) + print(value) + + url_example = str(streaming_object.values('url_example')[0]['url_example']) + print(url_example) + + randomViewing =str(streaming_object.values('randomViewing')[0]['randomViewing']) + print(randomViewing) + + if (randomViewing == False): + print('show set to random') + season,episode = randomEpisode() + else: + print('show set to following episode') + season,episode,lastEpisode = followingEpisode(season,episode,seasonInformation) + if (lastEpisode): + return HttpResponse('

You already watched the last episode of the serie!

') + + print(season) + print(episode) + + + url_generated = str(url_prefix)+str(season)+str(url_infix)+str(episode)+str(url_suffix) + print(url_generated) + + + #append the data into the model + StreamingRedirectData.objects.filter(alias=alias).update(season=season,episode=episode) + + #### mark as view in betaserie + + #mark episode as seen in betaserie + episode_number = "S"+str(season)+"E"+str(episode) + + episode_id = betaserie.identify_episode(betaserieShowId,episode_number) + + betaserie.mark_episodes_watched(episode_id) + + + return redirect(str(url_generated)) \ No newline at end of file diff --git a/django_code/core/urls.py b/django_code/core/urls.py index 25d64ce..fbfaefd 100644 --- a/django_code/core/urls.py +++ b/django_code/core/urls.py @@ -27,6 +27,7 @@ from apps.stash_management import apps as stashapp from apps.stash_management import views as stashview from apps.website_redirection import views as website_redirectionapp from apps.podcast_aggregator import views as podcast_views +from apps.streaming import views as streaming_views urlpatterns = [ @@ -93,4 +94,9 @@ urlpatterns = [ ################### cloudmanager ################### path('podcast/', podcast_views.execute_podcast), + ################### streaming ################### + path('streaming/', streaming_views.hello), + path('streaming/go/', streaming_views.streamingRedirect), + + ]