Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add video streaming functionality and remove extra files to save space on hosting #29

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions backend/backend/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,13 @@
'gdstorage',
'quizapp',

'allauth',
'allauth.account',
'allauth.socialaccount',
'allauth.socialaccount.providers.google',
# 'allauth',
# 'allauth.account',
# 'allauth.socialaccount',
# 'allauth.socialaccount.providers.google',

'dj_rest_auth',
'dj_rest_auth.registration',
# 'dj_rest_auth',
# 'dj_rest_auth.registration',

'rest_registration',
]
Expand All @@ -70,7 +70,7 @@
MIDDLEWARE = [
"corsheaders.middleware.CorsMiddleware",
'django.middleware.security.SecurityMiddleware',
"whitenoise.middleware.WhiteNoiseMiddleware",
# "whitenoise.middleware.WhiteNoiseMiddleware",
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
Expand Down
1 change: 1 addition & 0 deletions backend/main/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@
urlpatterns = [
path('videos/',VideoList.as_view(),name='video_list'),
path('videos/<int:id>/',VideoDetail.as_view(),name = 'video_detail'),
path('stream-video/<int:video_id>/', stream_video, name='stream_video'),
]
28 changes: 28 additions & 0 deletions backend/main/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
from .models import *
from .serializers import *
from .permissions import *
from rest_framework.response import Response
from rest_framework.decorators import api_view
from django.http import FileResponse
from gdstorage.storage import GoogleDriveStorage



# Create your views here.
Expand All @@ -23,3 +28,26 @@ class VideoDetail(generics.RetrieveUpdateDestroyAPIView):
serializer_class = VideoSerializer
lookup_field = 'id'
permission_classes = [IsAuthenticatedOrReadOnly, IsVideoOwnerOrReadOnly]


@api_view(['GET'])
def stream_video(request, video_id):
try:
video = Video.objects.get(pk=video_id)
# Initialize GoogleDriveStorage
gds = GoogleDriveStorage()
file_path = video.video_file.name # Assuming you've stored the video file path in the model

# Get the video file from Google Drive
video_file = gds.open(file_path, 'rb')
response = FileResponse(video_file)

# Set appropriate content type for streaming video
response['Content-Type'] = 'video/mp4' # Change this to the appropriate video format

return response

except Video.DoesNotExist:
# Handle video not found case
pass

53 changes: 15 additions & 38 deletions backend/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,62 +1,39 @@
asgiref==3.7.2
attrs==23.1.0
cachetools==5.3.1
certifi==2023.5.7
cffi==1.15.1
charset-normalizer==3.1.0
cryptography==41.0.2
defusedxml==0.7.1
dj-database-url==2.0.0
dj-rest-auth==4.0.1
dj-stripe==2.7.3
Django==4.2.2
django-allauth==0.54.0
cachetools==4.2.4
certifi==2023.7.22
charset-normalizer==3.2.0
Django==4.2.4
django-cleanup==8.0.0
django-cors-headers==4.1.0
django-cors-headers==4.2.0
django-googledrive-storage==1.6.0
django-rest-registration==0.8.2
djangorestframework==3.14.0
drf-spectacular==0.26.2
drf-spectacular-sidecar==2023.6.1
drf-stripe-subscription==1.2.0
drf-spectacular==0.26.4
google-api-core==2.10.2
google-api-python-client==2.97.0
google-auth==1.35.0
google-auth-httplib2==0.1.0
google-auth-oauthlib==1.0.0
googleapis-common-protos==1.60.0
google-auth==2.22.0
google-auth-httplib2==0.1.0
google-auth-oauthlib==1.0.0
httplib2==0.22.0
idna==3.4
inflection==0.5.1
jsonfield==3.1.0
jsonschema==4.17.3
oauthlib==3.2.2
pdf2image==1.16.3
Pillow==9.5.0
protobuf==4.24.1
jsonschema==4.19.0
jsonschema-specifications==2023.7.1
protobuf==4.24.2
pyasn1==0.5.0
pyasn1-modules==0.3.0
pycparser==2.21
pydantic==1.10.9
PyJWT==2.7.0
pyparsing==3.1.0
PyPDF2==3.0.1
pyrsistent==0.19.3
pyparsing==3.1.1
python-dateutil==2.8.2
python-decouple==3.8
python3-openid==3.2.0
pytz==2023.3
PyYAML==6.0
PyYAML==6.0.1
referencing==0.30.2
requests==2.31.0
requests-oauthlib==1.3.1
rpds-py==0.9.2
rsa==4.9
six==1.16.0
sqlparse==0.4.4
stripe==4.2.0
typing_extensions==4.6.3
typing_extensions==4.7.1
uritemplate==4.1.1
urllib3==1.26.16
whitenoise==6.4.0
urllib3==2.0.4