Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
C
cp_video_dokku
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alexandr Dzehil
cp_video_dokku
Commits
24aa2057
You need to sign in or sign up before continuing.
Commit
24aa2057
authored
Mar 16, 2023
by
Ilya Simonov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix generate custom thumbnail
parent
be56892f
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
14 additions
and
45 deletions
+14
-45
apps.cpython-39.pyc
apps/core/__pycache__/apps.cpython-39.pyc
+0
-0
signals.cpython-39.pyc
apps/core/__pycache__/signals.cpython-39.pyc
+0
-0
utils.cpython-39.pyc
apps/core/__pycache__/utils.cpython-39.pyc
+0
-0
apps.py
apps/core/apps.py
+0
-3
signals.py
apps/core/signals.py
+0
-24
tasks.py
apps/core/tasks.py
+11
-3
utils.py
apps/core/utils.py
+3
-15
No files found.
apps/core/__pycache__/apps.cpython-39.pyc
View file @
24aa2057
No preview for this file type
apps/core/__pycache__/signals.cpython-39.pyc
deleted
100644 → 0
View file @
be56892f
File deleted
apps/core/__pycache__/utils.cpython-39.pyc
View file @
24aa2057
No preview for this file type
apps/core/apps.py
View file @
24aa2057
...
...
@@ -4,6 +4,3 @@ from django.apps import AppConfig
class
CoreConfig
(
AppConfig
):
default_auto_field
=
'django.db.models.BigAutoField'
name
=
'apps.core'
def
ready
(
self
):
import
apps.core.signals
apps/core/signals.py
deleted
100644 → 0
View file @
be56892f
import
os
from
django.conf
import
settings
from
django.dispatch
import
receiver
from
django.db.models.signals
import
post_save
from
.
import
models
,
utils
,
s3_uploader
# @receiver(post_save, sender=models.Video)
# def generate_default_thumbnail_for_video(sender, instance, **kwargs):
# if not instance.thumbnail and instance.local_file:
# if os.path.isfile(instance.local_file.path):
# thumbnail_name = utils.generate_thumbnail(instance.local_file)
# key = f'videos/{thumbnail_name}'
# thumbnail_path = f'{settings.MEDIA_ROOT}{key}'
#
# content = utils.get_thumbnail_content(thumbnail_path)
# content_type = 'image/jpeg'
# instance.thumbnail = s3_uploader.upload_file(content, key, content_type)
#
# instance.save(update_fields=['thumbnail'])
#
# os.remove(thumbnail_path)
apps/core/tasks.py
View file @
24aa2057
import
os
import
requests
from
django.conf
import
settings
from
.models
import
Video
,
READY
from
.s3_uploader
import
upload_file
from
.utils
import
asset_upload
from
.utils
import
asset_upload
,
generate_thumbnail
from
cp_video.celery
import
app
...
...
@@ -25,6 +24,15 @@ def send_video_to_s3():
local_video
.
s3_file
=
upload_file
(
content
,
key
,
'video/mp4'
)
local_video
.
status
=
READY
local_video
.
save
(
update_fields
=
[
's3_file'
,
'status'
])
if
not
local_video
.
thumbnail
and
local_video
.
local_file
:
thumbnail_name
=
generate_thumbnail
(
file_path
,
video_name
)
key
=
f
'videos/{thumbnail_name}'
thumbnail_path
=
settings
.
DOMAIN_NAME
+
settings
.
MEDIA_URL
+
thumbnail_name
response
=
requests
.
get
(
thumbnail_path
)
content
=
response
.
content
content_type
=
'image/jpeg'
local_video
.
thumbnail
=
upload_file
(
content
,
key
,
content_type
)
local_video
.
save
(
update_fields
=
[
's3_file'
,
'status'
,
'thumbnail'
])
local_videos
.
update
(
local_file
=
None
)
apps/core/utils.py
View file @
24aa2057
...
...
@@ -10,24 +10,12 @@ def asset_upload(instance, filename):
return
f
'videos/{filename}'
def
generate_thumbnail
(
video
):
clip
=
VideoFileClip
(
video
.
path
)
thumbnail_name
=
video
.
name
.
split
(
'.'
)[
0
]
def
generate_thumbnail
(
video
_path
,
video_name
):
clip
=
VideoFileClip
(
video
_
path
)
thumbnail_name
=
video
_
name
.
split
(
'.'
)[
0
]
thumbnail_name
=
f
'{settings.MEDIA_ROOT}{thumbnail_name}.jpg'
clip
.
save_frame
(
thumbnail_name
,
t
=
1.00
)
thumbnail_name
=
thumbnail_name
.
split
(
'/'
)[
-
1
]
return
thumbnail_name
def
get_thumbnail_content
(
thumbnail_path
):
img
=
PImage
.
open
(
thumbnail_path
)
roi_img
=
img
.
crop
()
img_byte_arr
=
io
.
BytesIO
()
roi_img
.
save
(
img_byte_arr
,
format
=
'JPEG'
)
content
=
img_byte_arr
.
getvalue
()
return
content
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment