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
1fc8bcaf
You need to sign in or sign up before continuing.
Commit
1fc8bcaf
authored
Apr 07, 2023
by
Ilya Simonov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add generate video duration
parent
bbdff5dd
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
24 additions
and
3 deletions
+24
-3
utils.cpython-39.pyc
apps/core/__pycache__/utils.cpython-39.pyc
+0
-0
tasks.py
apps/core/tasks.py
+7
-1
utils.py
apps/core/utils.py
+17
-2
No files found.
apps/core/__pycache__/utils.cpython-39.pyc
View file @
1fc8bcaf
No preview for this file type
apps/core/tasks.py
View file @
1fc8bcaf
...
...
@@ -5,7 +5,12 @@ from django.conf import settings
from
.models
import
Video
,
READY
,
FAIL
from
.s3_uploader
import
upload_file
from
.utils
import
add_video_to_playlist
,
generate_thumbnail
,
download_file
from
.utils
import
(
add_video_to_playlist
,
generate_thumbnail
,
download_file
,
get_video_duration
,
)
from
cp_video.celery
import
app
from
cp_video.utils
import
asset_upload
...
...
@@ -32,6 +37,7 @@ def send_video_to_s3(video_id=None):
local_video
.
local_file
=
None
local_video
.
status
=
READY
local_video
.
s3_file
=
upload_file
(
video_file
,
key
,
'video/mp4'
)
local_video
.
duration
=
get_video_duration
(
video_name
)
try
:
log
.
info
(
'Generating thumbnail...'
)
...
...
apps/core/utils.py
View file @
1fc8bcaf
import
requests
import
logging
import
subprocess
,
json
,
requests
,
logging
from
django.contrib.contenttypes.models
import
ContentType
...
...
@@ -50,6 +49,22 @@ def generate_thumbnail(video_path, video_name):
return
thumbnail
,
thumbnail_name
def
get_video_duration
(
filename
):
result
=
subprocess
.
check_output
(
f
'ffprobe -v quiet -show_streams -select_streams v:0 -of json "{filename}"'
,
shell
=
True
)
.
decode
()
duration
=
json
.
loads
(
result
)[
'streams'
][
0
][
'duration'
]
try
:
duration
=
int
(
duration
)
except
ValueError
:
duration
=
float
(
duration
)
return
duration
def
add_video_to_playlist
(
video
):
video_content_type
=
ContentType
.
objects
.
get_for_model
(
Video
)
playlist_content_type
=
ContentType
.
objects
.
get_for_model
(
Playlist
)
...
...
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