diff --git a/.gitignore b/.gitignore index 56a7f43..a667458 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,6 @@ +.vscode/ +__pycache__/ db.sqlite3 videos/ channel_archiver/yt-dlp-archive.txt -channel_archiver/UnusualVideos* +channel_archiver/UnusualVideos* \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json deleted file mode 100644 index 834369a..0000000 --- a/.vscode/settings.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "[python]": { - "editor.defaultFormatter": "ms-python.python" - }, - "python.formatting.provider": "none" -} \ No newline at end of file diff --git a/api/README.md b/api/README.md new file mode 100644 index 0000000..eded595 --- /dev/null +++ b/api/README.md @@ -0,0 +1,24 @@ +# VideoAPI + +## Search +`GET /api/?param=value` + +### Parameters +| Param | Value | +|-|-| +| `q` | The search query string. | +| `limit` | A limit on the number of objects to be returned. Default is 6. | + +### Response +``` +[ + { + "id": 1, + "name": "Video 1" + }, + {...} +] +``` + +### Examples +> `GET /api/?q=foo&limit=3` will return the first 3 videos with "foo" in their name. diff --git a/api/__init__.py b/api/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/api/urls.py b/api/urls.py new file mode 100644 index 0000000..ad6ea78 --- /dev/null +++ b/api/urls.py @@ -0,0 +1,7 @@ +from django.urls import path, include +from . import views + +urlpatterns = [ + path('search/', views.searchAPI), + path('', include('sage_stream.api.urls')), +] \ No newline at end of file diff --git a/api/views.py b/api/views.py new file mode 100644 index 0000000..200f5db --- /dev/null +++ b/api/views.py @@ -0,0 +1,17 @@ +from django.db.models import Q +from rest_framework.response import Response +from rest_framework.decorators import api_view +from core.models import Video +from core.serializers import VideoSerializer + +@api_view(['GET']) +def searchAPI(request): + q = request.GET.get('q', '') + l = request.GET.get('limit', '6') + try: + l = int(l) + videos = Video.objects.filter(Q(id__contains=q) | Q(name__contains=q))[:l] + except: + videos = Video.objects.filter(Q(id__contains=q) | Q(name__contains=q)) + serializer = VideoSerializer(videos, many=True) + return Response(serializer.data) diff --git a/core/__pycache__/__init__.cpython-38.pyc b/core/__pycache__/__init__.cpython-38.pyc deleted file mode 100644 index 79d0b5f..0000000 Binary files a/core/__pycache__/__init__.cpython-38.pyc and /dev/null differ diff --git a/core/__pycache__/admin.cpython-38.pyc b/core/__pycache__/admin.cpython-38.pyc deleted file mode 100644 index 8f8ad87..0000000 Binary files a/core/__pycache__/admin.cpython-38.pyc and /dev/null differ diff --git a/core/__pycache__/apps.cpython-38.pyc b/core/__pycache__/apps.cpython-38.pyc deleted file mode 100644 index 1939d17..0000000 Binary files a/core/__pycache__/apps.cpython-38.pyc and /dev/null differ diff --git a/core/__pycache__/models.cpython-38.pyc b/core/__pycache__/models.cpython-38.pyc deleted file mode 100644 index 2f41b94..0000000 Binary files a/core/__pycache__/models.cpython-38.pyc and /dev/null differ diff --git a/core/__pycache__/urls.cpython-38.pyc b/core/__pycache__/urls.cpython-38.pyc deleted file mode 100644 index 835d60f..0000000 Binary files a/core/__pycache__/urls.cpython-38.pyc and /dev/null differ diff --git a/core/__pycache__/views.cpython-38.pyc b/core/__pycache__/views.cpython-38.pyc deleted file mode 100644 index 1437c5f..0000000 Binary files a/core/__pycache__/views.cpython-38.pyc and /dev/null differ diff --git a/core/admin.py b/core/admin.py index 63d2e8a..ddce0fa 100644 --- a/core/admin.py +++ b/core/admin.py @@ -1,6 +1,4 @@ from django.contrib import admin - - from .models import Video @admin.register(Video) diff --git a/core/migrations/__pycache__/0001_initial.cpython-38.pyc b/core/migrations/__pycache__/0001_initial.cpython-38.pyc deleted file mode 100644 index 0c1200a..0000000 Binary files a/core/migrations/__pycache__/0001_initial.cpython-38.pyc and /dev/null differ diff --git a/core/migrations/__pycache__/0002_video_thumbnail_alter_video_created_at.cpython-38.pyc b/core/migrations/__pycache__/0002_video_thumbnail_alter_video_created_at.cpython-38.pyc deleted file mode 100644 index 3f6408b..0000000 Binary files a/core/migrations/__pycache__/0002_video_thumbnail_alter_video_created_at.cpython-38.pyc and /dev/null differ diff --git a/core/migrations/__pycache__/0003_alter_video_file_alter_video_thumbnail.cpython-38.pyc b/core/migrations/__pycache__/0003_alter_video_file_alter_video_thumbnail.cpython-38.pyc deleted file mode 100644 index 2554846..0000000 Binary files a/core/migrations/__pycache__/0003_alter_video_file_alter_video_thumbnail.cpython-38.pyc and /dev/null differ diff --git a/core/migrations/__pycache__/__init__.cpython-38.pyc b/core/migrations/__pycache__/__init__.cpython-38.pyc deleted file mode 100644 index ffc280f..0000000 Binary files a/core/migrations/__pycache__/__init__.cpython-38.pyc and /dev/null differ diff --git a/core/serializers.py b/core/serializers.py new file mode 100644 index 0000000..5452b30 --- /dev/null +++ b/core/serializers.py @@ -0,0 +1,7 @@ +from rest_framework import serializers +from .models import Video + +class VideoSerializer(serializers.ModelSerializer): + class Meta: + model = Video + fields = ['id', 'name'] \ No newline at end of file diff --git a/core/templates/base.html b/core/templates/base.html index c81382d..18ba5dd 100644 --- a/core/templates/base.html +++ b/core/templates/base.html @@ -12,8 +12,7 @@ - +