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
173868ae
Commit
173868ae
authored
Mar 28, 2023
by
Ilya Simonov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add function add_video_to_playlist
parent
41e72cae
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
24 deletions
+28
-24
tasks.py
apps/core/tasks.py
+3
-24
utils.py
apps/core/utils.py
+25
-0
No files found.
apps/core/tasks.py
View file @
173868ae
...
@@ -2,11 +2,10 @@ import requests
...
@@ -2,11 +2,10 @@ import requests
import
logging
import
logging
from
django.conf
import
settings
from
django.conf
import
settings
from
django.contrib.contenttypes.models
import
ContentType
from
.models
import
Video
,
Playlist
,
TagToObject
,
READY
,
DYNAMIC
,
FAIL
from
.models
import
Video
,
READY
,
FAIL
from
.s3_uploader
import
upload_file
from
.s3_uploader
import
upload_file
from
.utils
import
asset_upload
from
.utils
import
asset_upload
,
add_video_to_playlist
from
cp_video.celery
import
app
from
cp_video.celery
import
app
...
@@ -15,9 +14,6 @@ log = logging.getLogger('send_video_to_s3')
...
@@ -15,9 +14,6 @@ log = logging.getLogger('send_video_to_s3')
@
app
.
task
(
soft_time_limit
=
600
)
@
app
.
task
(
soft_time_limit
=
600
)
def
send_video_to_s3
(
video_id
=
None
):
def
send_video_to_s3
(
video_id
=
None
):
video_content_type
=
ContentType
.
objects
.
get_for_model
(
Video
)
playlist_content_type
=
ContentType
.
objects
.
get_for_model
(
Playlist
)
local_video
=
Video
.
objects
.
get
(
id
=
video_id
)
local_video
=
Video
.
objects
.
get
(
id
=
video_id
)
try
:
try
:
...
@@ -39,25 +35,8 @@ def send_video_to_s3(video_id=None):
...
@@ -39,25 +35,8 @@ def send_video_to_s3(video_id=None):
log
.
info
(
f
'Video id {local_video.id} uploaded to S3...'
)
log
.
info
(
f
'Video id {local_video.id} uploaded to S3...'
)
tag_ids
=
list
(
TagToObject
.
objects
.
filter
(
add_video_to_playlist
(
local_video
)
content_type
=
video_content_type
,
object_id
=
video_id
,
)
.
values_list
(
'tag_id'
,
flat
=
True
))
if
tag_ids
:
playlist_ids
=
list
(
TagToObject
.
objects
.
filter
(
content_type
=
playlist_content_type
,
tag_id__in
=
tag_ids
,
)
.
values_list
(
'object_id'
,
flat
=
True
))
if
playlist_ids
:
playlists
=
Playlist
.
objects
.
filter
(
id__in
=
playlist_ids
,
type
=
DYNAMIC
,
)
for
playlist
in
playlists
:
playlist
.
videos
.
add
(
local_video
)
except
Exception
as
e
:
except
Exception
as
e
:
log
.
error
(
e
)
log
.
error
(
e
)
local_video
.
status
=
FAIL
local_video
.
status
=
FAIL
...
...
apps/core/utils.py
View file @
173868ae
from
django.conf
import
settings
from
django.conf
import
settings
from
django.contrib.contenttypes.models
import
ContentType
from
moviepy.editor
import
VideoFileClip
from
moviepy.editor
import
VideoFileClip
from
.models
import
Video
,
Playlist
,
TagToObject
,
DYNAMIC
def
asset_upload
(
instance
,
filename
):
def
asset_upload
(
instance
,
filename
):
return
f
'videos/{filename}'
return
f
'videos/{filename}'
...
@@ -16,3 +19,25 @@ def generate_thumbnail(video_path, video_name):
...
@@ -16,3 +19,25 @@ def generate_thumbnail(video_path, video_name):
thumbnail_name
=
thumbnail_name
.
split
(
'/'
)[
-
1
]
thumbnail_name
=
thumbnail_name
.
split
(
'/'
)[
-
1
]
return
thumbnail_name
return
thumbnail_name
def
add_video_to_playlist
(
video
):
video_content_type
=
ContentType
.
objects
.
get_for_model
(
Video
)
playlist_content_type
=
ContentType
.
objects
.
get_for_model
(
Playlist
)
tag_ids
=
list
(
TagToObject
.
objects
.
filter
(
content_type
=
video_content_type
,
object_id
=
video
.
id
,
)
.
values_list
(
'tag_id'
,
flat
=
True
))
if
tag_ids
:
playlist_ids
=
list
(
TagToObject
.
objects
.
filter
(
content_type
=
playlist_content_type
,
tag_id__in
=
tag_ids
,
)
.
values_list
(
'object_id'
,
flat
=
True
))
if
playlist_ids
:
playlists
=
Playlist
.
objects
.
filter
(
id__in
=
playlist_ids
,
type
=
DYNAMIC
)
for
playlist
in
playlists
:
playlist
.
videos
.
add
(
video
)
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