mirror of
https://github.com/mediacms-io/mediacms.git
synced 2024-12-12 10:00:44 +01:00
fix: pre-commit
This commit is contained in:
parent
99be0f07dd
commit
b8ee2e9fb8
@ -539,3 +539,6 @@ SPRITE_NUM_SECS = 10
|
|||||||
# number of seconds for sprite image.
|
# number of seconds for sprite image.
|
||||||
# If you plan to change this, you must also follow the instructions on admin_docs.md
|
# If you plan to change this, you must also follow the instructions on admin_docs.md
|
||||||
# to change the equivalent value in ./frontend/src/static/js/components/media-viewer/VideoViewer/index.js and then re-build frontend
|
# to change the equivalent value in ./frontend/src/static/js/components/media-viewer/VideoViewer/index.js and then re-build frontend
|
||||||
|
|
||||||
|
# how many images will be shown on the slideshow
|
||||||
|
SLIDESHOW_ITEMS = 30
|
||||||
|
@ -1,6 +1,15 @@
|
|||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
|
|
||||||
from .models import Category, Comment, EncodeProfile, Encoding, Language, Media, Subtitle, Tag
|
from .models import (
|
||||||
|
Category,
|
||||||
|
Comment,
|
||||||
|
EncodeProfile,
|
||||||
|
Encoding,
|
||||||
|
Language,
|
||||||
|
Media,
|
||||||
|
Subtitle,
|
||||||
|
Tag,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class CommentAdmin(admin.ModelAdmin):
|
class CommentAdmin(admin.ModelAdmin):
|
||||||
|
@ -32,7 +32,6 @@ for translation_file in files:
|
|||||||
replacement_strings[language_code] = tr_module.replacement_strings
|
replacement_strings[language_code] = tr_module.replacement_strings
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def get_translation(language_code):
|
def get_translation(language_code):
|
||||||
# get list of translations per language
|
# get list of translations per language
|
||||||
if not check_language_code(language_code):
|
if not check_language_code(language_code):
|
||||||
|
@ -18,7 +18,10 @@ class Command(BaseCommand):
|
|||||||
files = os.listdir(translations_dir)
|
files = os.listdir(translations_dir)
|
||||||
files = [f for f in files if f.endswith('.py') and f not in ('__init__.py', 'en.py')]
|
files = [f for f in files if f.endswith('.py') and f not in ('__init__.py', 'en.py')]
|
||||||
# Import the original English translations
|
# Import the original English translations
|
||||||
from files.frontend_translations.en import replacement_strings, translation_strings
|
from files.frontend_translations.en import (
|
||||||
|
replacement_strings,
|
||||||
|
translation_strings,
|
||||||
|
)
|
||||||
|
|
||||||
for file in files:
|
for file in files:
|
||||||
file_path = os.path.join(translations_dir, file)
|
file_path = os.path.join(translations_dir, file)
|
||||||
|
@ -780,13 +780,13 @@ class Media(models.Model):
|
|||||||
return helpers.url_from_path(self.poster.path)
|
return helpers.url_from_path(self.poster.path)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def slideshow_items(self):
|
def slideshow_items(self):
|
||||||
|
slideshow_items = getattr(settings, "SLIDESHOW_ITEMS", 30)
|
||||||
if self.media_type != "image":
|
if self.media_type != "image":
|
||||||
items = []
|
items = []
|
||||||
else:
|
else:
|
||||||
qs = Media.objects.filter(listable=True, user=self.user, media_type="image").exclude(id=self.id).order_by('id')[:20]
|
qs = Media.objects.filter(listable=True, user=self.user, media_type="image").exclude(id=self.id).order_by('id')[:slideshow_items]
|
||||||
|
|
||||||
items = [
|
items = [
|
||||||
{
|
{
|
||||||
@ -795,12 +795,21 @@ class Media(models.Model):
|
|||||||
"thumbnail_url": item.thumbnail_url,
|
"thumbnail_url": item.thumbnail_url,
|
||||||
"title": item.title,
|
"title": item.title,
|
||||||
"original_media_url": item.original_media_url,
|
"original_media_url": item.original_media_url,
|
||||||
} for item in qs
|
}
|
||||||
|
for item in qs
|
||||||
]
|
]
|
||||||
|
items.insert(
|
||||||
|
0,
|
||||||
|
{
|
||||||
|
"poster_url": self.poster_url,
|
||||||
|
"url": self.get_absolute_url(),
|
||||||
|
"thumbnail_url": self.thumbnail_url,
|
||||||
|
"title": self.title,
|
||||||
|
"original_media_url": self.original_media_url,
|
||||||
|
},
|
||||||
|
)
|
||||||
return items
|
return items
|
||||||
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def subtitles_info(self):
|
def subtitles_info(self):
|
||||||
"""Property used on serializers
|
"""Property used on serializers
|
||||||
|
@ -145,7 +145,7 @@ class SingleMediaSerializer(serializers.ModelSerializer):
|
|||||||
"ratings_info",
|
"ratings_info",
|
||||||
"add_subtitle_url",
|
"add_subtitle_url",
|
||||||
"allow_download",
|
"allow_download",
|
||||||
"slideshow_items"
|
"slideshow_items",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -23,7 +23,17 @@ from users.models import User
|
|||||||
|
|
||||||
from .backends import FFmpegBackend
|
from .backends import FFmpegBackend
|
||||||
from .exceptions import VideoEncodingError
|
from .exceptions import VideoEncodingError
|
||||||
from .helpers import calculate_seconds, create_temp_file, get_file_name, get_file_type, media_file_info, produce_ffmpeg_commands, produce_friendly_token, rm_file, run_command
|
from .helpers import (
|
||||||
|
calculate_seconds,
|
||||||
|
create_temp_file,
|
||||||
|
get_file_name,
|
||||||
|
get_file_type,
|
||||||
|
media_file_info,
|
||||||
|
produce_ffmpeg_commands,
|
||||||
|
produce_friendly_token,
|
||||||
|
rm_file,
|
||||||
|
run_command,
|
||||||
|
)
|
||||||
from .methods import list_tasks, notify_users, pre_save_action
|
from .methods import list_tasks, notify_users, pre_save_action
|
||||||
from .models import Category, EncodeProfile, Encoding, Media, Rating, Tag
|
from .models import Category, EncodeProfile, Encoding, Media, Rating, Tag
|
||||||
|
|
||||||
@ -376,23 +386,12 @@ def produce_sprite_from_video(friendly_token):
|
|||||||
output_name = tmpdirname + "/sprites.jpg"
|
output_name = tmpdirname + "/sprites.jpg"
|
||||||
|
|
||||||
fps = getattr(settings, 'SPRITE_NUM_SECS', 10)
|
fps = getattr(settings, 'SPRITE_NUM_SECS', 10)
|
||||||
ffmpeg_cmd = [
|
ffmpeg_cmd = [settings.FFMPEG_COMMAND, "-i", media.media_file.path, "-f", "image2", "-vf", f"fps=1/{fps}, scale=160:90", tmpdir_image_files]
|
||||||
settings.FFMPEG_COMMAND,
|
|
||||||
"-i", media.media_file.path,
|
|
||||||
"-f", "image2",
|
|
||||||
"-vf", f"fps=1/{fps}, scale=160:90",
|
|
||||||
tmpdir_image_files
|
|
||||||
]
|
|
||||||
run_command(ffmpeg_cmd)
|
run_command(ffmpeg_cmd)
|
||||||
image_files = [f for f in os.listdir(tmpdirname) if f.startswith("img") and f.endswith(".jpg")]
|
image_files = [f for f in os.listdir(tmpdirname) if f.startswith("img") and f.endswith(".jpg")]
|
||||||
image_files = sorted(image_files, key=lambda x: int(re.search(r'\d+', x).group()))
|
image_files = sorted(image_files, key=lambda x: int(re.search(r'\d+', x).group()))
|
||||||
image_files = [os.path.join(tmpdirname, f) for f in image_files]
|
image_files = [os.path.join(tmpdirname, f) for f in image_files]
|
||||||
cmd_convert = [
|
cmd_convert = ["convert", *image_files, "-append", output_name] # image files, unpacked into the list
|
||||||
"convert",
|
|
||||||
*image_files, # image files, unpacked into the list
|
|
||||||
"-append",
|
|
||||||
output_name
|
|
||||||
]
|
|
||||||
|
|
||||||
run_command(cmd_convert)
|
run_command(cmd_convert)
|
||||||
|
|
||||||
@ -435,12 +434,7 @@ def create_hls(friendly_token):
|
|||||||
existing_output_dir = output_dir
|
existing_output_dir = output_dir
|
||||||
output_dir = os.path.join(settings.HLS_DIR, p + produce_friendly_token())
|
output_dir = os.path.join(settings.HLS_DIR, p + produce_friendly_token())
|
||||||
files = " ".join([f.media_file.path for f in encodings if f.media_file])
|
files = " ".join([f.media_file.path for f in encodings if f.media_file])
|
||||||
cmd = [
|
cmd = [settings.MP4HLS_COMMAND, '--segment-duration=4', f'--output-dir={output_dir}', files]
|
||||||
settings.MP4HLS_COMMAND,
|
|
||||||
'--segment-duration=4',
|
|
||||||
f'--output-dir={output_dir}',
|
|
||||||
files
|
|
||||||
]
|
|
||||||
run_command(cmd)
|
run_command(cmd)
|
||||||
|
|
||||||
if existing_output_dir:
|
if existing_output_dir:
|
||||||
|
@ -7,5 +7,4 @@ register = template.Library()
|
|||||||
|
|
||||||
@register.filter
|
@register.filter
|
||||||
def custom_translate(string, lang_code):
|
def custom_translate(string, lang_code):
|
||||||
|
|
||||||
return translate_string(lang_code, string)
|
return translate_string(lang_code, string)
|
||||||
|
@ -12,14 +12,24 @@ from drf_yasg import openapi as openapi
|
|||||||
from drf_yasg.utils import swagger_auto_schema
|
from drf_yasg.utils import swagger_auto_schema
|
||||||
from rest_framework import permissions, status
|
from rest_framework import permissions, status
|
||||||
from rest_framework.exceptions import PermissionDenied
|
from rest_framework.exceptions import PermissionDenied
|
||||||
from rest_framework.parsers import FileUploadParser, FormParser, JSONParser, MultiPartParser
|
from rest_framework.parsers import (
|
||||||
|
FileUploadParser,
|
||||||
|
FormParser,
|
||||||
|
JSONParser,
|
||||||
|
MultiPartParser,
|
||||||
|
)
|
||||||
from rest_framework.response import Response
|
from rest_framework.response import Response
|
||||||
from rest_framework.settings import api_settings
|
from rest_framework.settings import api_settings
|
||||||
from rest_framework.views import APIView
|
from rest_framework.views import APIView
|
||||||
|
|
||||||
from actions.models import USER_MEDIA_ACTIONS, MediaAction
|
from actions.models import USER_MEDIA_ACTIONS, MediaAction
|
||||||
from cms.custom_pagination import FastPaginationWithoutCount
|
from cms.custom_pagination import FastPaginationWithoutCount
|
||||||
from cms.permissions import IsAuthorizedToAdd, IsAuthorizedToAddComment, IsUserOrEditor, user_allowed_to_upload
|
from cms.permissions import (
|
||||||
|
IsAuthorizedToAdd,
|
||||||
|
IsAuthorizedToAddComment,
|
||||||
|
IsUserOrEditor,
|
||||||
|
user_allowed_to_upload,
|
||||||
|
)
|
||||||
from users.models import User
|
from users.models import User
|
||||||
|
|
||||||
from .forms import ContactForm, MediaForm, SubtitleForm
|
from .forms import ContactForm, MediaForm, SubtitleForm
|
||||||
@ -36,7 +46,16 @@ from .methods import (
|
|||||||
show_related_media,
|
show_related_media,
|
||||||
update_user_ratings,
|
update_user_ratings,
|
||||||
)
|
)
|
||||||
from .models import Category, Comment, EncodeProfile, Encoding, Media, Playlist, PlaylistMedia, Tag
|
from .models import (
|
||||||
|
Category,
|
||||||
|
Comment,
|
||||||
|
EncodeProfile,
|
||||||
|
Encoding,
|
||||||
|
Media,
|
||||||
|
Playlist,
|
||||||
|
PlaylistMedia,
|
||||||
|
Tag,
|
||||||
|
)
|
||||||
from .serializers import (
|
from .serializers import (
|
||||||
CategorySerializer,
|
CategorySerializer,
|
||||||
CommentSerializer,
|
CommentSerializer,
|
||||||
|
@ -10,7 +10,7 @@ class MyAccountAdapter(DefaultAccountAdapter):
|
|||||||
return settings.SSL_FRONTEND_HOST + url
|
return settings.SSL_FRONTEND_HOST + url
|
||||||
|
|
||||||
def clean_email(self, email):
|
def clean_email(self, email):
|
||||||
if hasattr(settings,"ALLOWED_DOMAINS_FOR_USER_REGISTRATION") and settings.ALLOWED_DOMAINS_FOR_USER_REGISTRATION:
|
if hasattr(settings, "ALLOWED_DOMAINS_FOR_USER_REGISTRATION") and settings.ALLOWED_DOMAINS_FOR_USER_REGISTRATION:
|
||||||
if email.split("@")[1] not in settings.ALLOWED_DOMAINS_FOR_USER_REGISTRATION:
|
if email.split("@")[1] not in settings.ALLOWED_DOMAINS_FOR_USER_REGISTRATION:
|
||||||
raise ValidationError("Domain is not in the permitted list")
|
raise ValidationError("Domain is not in the permitted list")
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user