Skip to content

Commit

Permalink
Merge branch 'release/v1.4.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
Mirio committed Dec 2, 2023
2 parents adcc2c0 + ca2a984 commit edf200e
Show file tree
Hide file tree
Showing 25 changed files with 548 additions and 55 deletions.
4 changes: 4 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
"type": "python",
"request": "launch",
"program": "${workspaceFolder}/manage.py",
"envFile": "${workspaceFolder}/develop.env",
"cwd": "${workspaceFolder}",
"args": [
"shell"
],
Expand All @@ -17,6 +19,8 @@
"type": "python",
"request": "launch",
"program": "${workspaceFolder}/manage.py",
"envFile": "${workspaceFolder}/develop.env",
"cwd": "${workspaceFolder}",
"args": [
"runserver"
],
Expand Down
23 changes: 23 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,29 @@

All notable changes to this project will be documented in this file.

## [1.3.0] - 2023-11-20

### Bug Fixes

- Fix static player img
- Adding user auth filter on navbar + Adjust login page
- Restyle playlist list on player page

### Documentation

- Adding docs about helm + Adding new venv

### Features

- Rework the cache layer for the pages

### Miscellaneous Tasks

- Bump psycopg[binary] from 3.1.12 to 3.1.13


Docker package: [https://github.com/Mirio/verbacap/pkgs/container/verbacap](https://github.com/Mirio/verbacap/pkgs/container/verbacap)

## [1.2.9] - 2023-11-19

### Bug Fixes
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

![GitHub](https://img.shields.io/github/license/mirio/verbacap)
[![Built with Cookiecutter Django](https://img.shields.io/badge/built%20with-Cookiecutter%20Django-ff69b4.svg?logo=cookiecutter)](https://github.com/cookiecutter/cookiecutter-django/)
[![Artifact Hub](https://img.shields.io/endpoint?url=https://artifacthub.io/badge/repository/verbacap)](https://artifacthub.io/packages/search?repo=verbacap)
[![Artifact Hub](https://img.shields.io/endpoint?url=https://artifacthub.io/badge/repository/verbacap)](https://artifacthub.io/packages/helm/verbacap/verbacap)



Expand Down
46 changes: 41 additions & 5 deletions config/api_router.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
from django.urls import path
from rest_framework.routers import SimpleRouter

from core.api.views import EpisodeSerializerViewSet, EpisodeViewedSerializer, PlaylistEditView, PlaylistView
from core.api.views import (
Action_AppCacheCleanupView,
EpisodeSerializerViewSet,
EpisodeViewedView,
PlaylistEditView,
PlaylistView,
Task_CoreCalcolatePersistInfoView,
UpdatePlayerTimeView,
)
from spreaker.api.views import Task_SK_ImportEpisodeSK
from verbacap.users.api.views import UserViewSet
from youtube.api.views import Task_YT_ImportEpisodesYTChannel, Task_YT_ImportEpisodesYTPlaylist

router = SimpleRouter()

Expand All @@ -11,11 +21,37 @@

app_name = "api"
urlpatterns = [
path("playlist/", PlaylistView.as_view(), name="playlist"),
path("playlist/edit/<str:provider_shortname>/<str:episode_id>/", PlaylistEditView.as_view(), name="playlist-edit"),
path("action/core-deleteappcache/", Action_AppCacheCleanupView.as_view(), name="api-action-appcachecleanup"),
path(
"task/yt-importepisodeschannel/",
Task_YT_ImportEpisodesYTChannel.as_view(),
name="api-task-yt-importepisodeschannel",
),
path(
"task/yt-importepisodesplaylist/",
Task_YT_ImportEpisodesYTPlaylist.as_view(),
name="api-task-yt-importepisodesplaylist",
),
path("task/sk-importepisodes/", Task_SK_ImportEpisodeSK.as_view(), name="api-task-sk-importepisodes"),
path(
"task/core-calcolatepersistinfo/",
Task_CoreCalcolatePersistInfoView.as_view(),
name="api-task-corecalcolatepersistinfo",
),
path(
"updateplayertime/edit/<str:provider_shortname>/<str:episode_id>/<int:current_time>/",
UpdatePlayerTimeView.as_view(),
name="api-updateplayertime",
),
path("playlist/", PlaylistView.as_view(), name="api-playlist"),
path(
"playlist/edit/<str:provider_shortname>/<str:episode_id>/",
PlaylistEditView.as_view(),
name="api-playlist-edit",
),
path(
"episode/viewed/<str:provider_shortname>/<str:episode_id>/",
EpisodeViewedSerializer.as_view(),
name="episode-viewed",
EpisodeViewedView.as_view(),
name="api-episode-viewed",
),
] + router.urls
10 changes: 10 additions & 0 deletions core/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,16 @@
from core.models import DataSource, Episode, Playlist, Provider


class CommonSuccessSerializer(serializers.Serializer):
success = serializers.BooleanField()


class CommonSerializer(serializers.Serializer):
status = serializers.StringRelatedField
message = serializers.StringRelatedField
value = serializers.StringRelatedField


class ProviderSerializer(serializers.ModelSerializer):
class Meta:
model = Provider
Expand Down
46 changes: 44 additions & 2 deletions core/api/views.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,67 @@
from django.core.cache import cache
from django.db.models import Max
from django_filters.rest_framework import DjangoFilterBackend
from rest_framework.mixins import ListModelMixin
from rest_framework.response import Response
from rest_framework.views import APIView
from rest_framework.viewsets import GenericViewSet

from core.api.serializers import EpisodeSerializer, PlaylistSerializer
from core.api.serializers import CommonSuccessSerializer, EpisodeSerializer, PlaylistSerializer
from core.models import DataSource, Episode, Playlist, Provider
from core.services import download_episode
from core.shared import CommonResponse
from core.tasks import calcolate_persistinfo


class Action_AppCacheCleanupView(APIView):
serializer_class = None

def delete(self, request, format=None):
serializer = CommonSuccessSerializer({"success": bool(cache.clear())})
return Response(serializer.data)


class Task_CoreCalcolatePersistInfoView(APIView):
serializer_class = None

def put(self, request, format=None):
obj = calcolate_persistinfo.delay()
out = obj.id
serializer = CommonSuccessSerializer({"success": out})
return Response(serializer.data)


class UpdatePlayerTimeView(APIView):
serializer_class = None

def put(self, request, provider_shortname, episode_id, current_time, format=None):
cache_key = f"UpdatePlayerTime_{provider_shortname}_{episode_id}"
cache.set(cache_key, current_time)
return Response()


class PlaylistView(APIView):
serializer_class = PlaylistSerializer

def get(self, request, format=None):
playlist = []
for iter in Playlist.objects.all().order_by("order_num"):
if iter.episode.is_downloaded:
current_time = cache.get(
"UpdatePlayerTime_{}_{}".format(
iter.episode.datasource.provider.shortname, iter.episode.episode_id
)
)
if current_time:
iter.episode.current_time = current_time
playlist.append(iter)
serializer = PlaylistSerializer(playlist, many=True)
return Response(serializer.data)


class PlaylistEditView(APIView):
serializer_class = None

def delete(self, request, provider_shortname, episode_id, format=None):
out = CommonResponse()
try:
Expand Down Expand Up @@ -79,7 +119,9 @@ def put(self, request, provider_shortname, episode_id, format=None):
return Response(out.__dict__)


class EpisodeViewedSerializer(APIView):
class EpisodeViewedView(APIView):
serializer_class = None

def put(self, request, provider_shortname, episode_id, format=None):
out = CommonResponse()
episode_exists = False
Expand Down
17 changes: 17 additions & 0 deletions core/migrations/0005_alter_settings_name.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Generated by Django 4.2.7 on 2023-11-21 20:38

from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("core", "0004_settings"),
]

operations = [
migrations.AlterField(
model_name="settings",
name="name",
field=models.CharField(help_text="Settings Name", unique=True),
),
]
17 changes: 17 additions & 0 deletions core/migrations/0006_episode_current_time.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Generated by Django 4.2.7 on 2023-12-01 21:24

from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("core", "0005_alter_settings_name"),
]

operations = [
migrations.AddField(
model_name="episode",
name="current_time",
field=models.IntegerField(default=0),
),
]
17 changes: 17 additions & 0 deletions core/migrations/0007_alter_episode_current_time.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Generated by Django 4.2.7 on 2023-12-01 21:25

from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("core", "0006_episode_current_time"),
]

operations = [
migrations.AlterField(
model_name="episode",
name="current_time",
field=models.IntegerField(default=0, help_text="Current time (for resume function)"),
),
]
3 changes: 2 additions & 1 deletion core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class Episode(BaseModel):
name = models.CharField(help_text="Episode Name")
datasource = models.ForeignKey(DataSource, on_delete=models.CASCADE, help_text="Datasource to use")
episode_date = models.DateField()
current_time = models.IntegerField(default=0, help_text="Current time (for resume function)")
target = models.CharField(help_text="Episode target url/string based by Provider")
is_viewed = models.BooleanField(default=False)
is_downloaded = models.BooleanField(default=False)
Expand All @@ -52,7 +53,7 @@ def __str__(self):


class Settings(BaseModel):
name = models.CharField(help_text="Settings Name")
name = models.CharField(help_text="Settings Name", unique=True)
value = models.CharField(help_text="Value of the setting")

def __str__(self):
Expand Down
3 changes: 3 additions & 0 deletions core/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@
<li class="nav-item">
<a class="nav-link" href="{% url 'player' %}"><i class="fa-solid fa-circle-play"></i> Player</a>
</li>
<li class="nav-item">
<a class="nav-link" href="{% url 'settings' %}"><i class="fa-solid fa-gear"></i> Settings</a>
</li>
<li class="nav-item">
{# URL provided by django-allauth/account/urls.py #}
<a class="nav-link" href="{% url 'account_logout' %}"><i class="fa-solid fa-right-from-bracket"></i> Sign Out</a>
Expand Down
Loading

0 comments on commit edf200e

Please sign in to comment.