fix config, fix import

This commit is contained in:
j 2023-11-14 15:06:56 +01:00
parent f3b9c2c0f5
commit fa7d6fb8bc
2 changed files with 23 additions and 21 deletions

View file

@ -911,18 +911,6 @@
"format": {"type": "number", "args": []}, "format": {"type": "number", "args": []},
"sort": true "sort": true
}, },
{
"id": "license",
"title": "License",
"type": ["string"],
"columnWidth": 120,
"filter": true,
"sort": true,
"default": [
"Creative Commons Attribution-ShareAlike 3.0 License",
"Pad.ma General Public License"
]
},
{ {
"id": "rightslevel", "id": "rightslevel",
"title": "Rights Level", "title": "Rights Level",
@ -1377,7 +1365,7 @@
"videoLoop": false, "videoLoop": false,
"videoMuted": false, "videoMuted": false,
"videoPoints": {}, "videoPoints": {},
"videoResolution": 240, "videoResolution": 720,
"videoScale": "fit", "videoScale": "fit",
"videoSize": "large", "videoSize": "large",
"videoSubtitles": false, "videoSubtitles": false,

View file

@ -1,14 +1,30 @@
import os
import subprocess import subprocess
import ox import ox
import shutil
import tempfile
from archive.models import File, Stream from archive.models import File, Stream, User
from archive.external import get_info from archive.external import get_info
def import_items(items):
import item.models
for data in items:
i = item.models.Item()
i.data = data
i.user = User.objects.all()[0]
i.save()
load_vimeo(i)
def load_vimeo(item): def load_vimeo(item):
urls = [url for url in item.data.get("links", []) if "vimeo.com" in url] urls = [url for url in item.data.get("links", []) if "vimeo.com" in url]
cdir = os.path.abspath(os.curdir) cdir = os.path.abspath(os.curdir)
orig = None orig = None
for url in urls: for url in urls:
info = get_info(url, None)
media = info[0]
for resolution in (720, 360): for resolution in (720, 360):
tmp = tempfile.mkdtemp() tmp = tempfile.mkdtemp()
if isinstance(tmp, bytes): if isinstance(tmp, bytes):
@ -17,7 +33,7 @@ def load_vimeo(item):
cmd = ['yt-dlp', '-q', url] cmd = ['yt-dlp', '-q', url]
cmd += ['-o', '%(title)80s.%(ext)s'] cmd += ['-o', '%(title)80s.%(ext)s']
cmd += [ cmd += [
'-f', 'bestvideo[height<=%s][ext=mp4]+bestaudio[ext=m4a]/bestvideo+bestaudio' % resolution, '-f', 'bestvideo[height<=%s][ext=mp4]+bestaudio[ext=m4a]' % resolution,
'--merge-output-format', 'mp4' '--merge-output-format', 'mp4'
] ]
p = subprocess.Popen(cmd, p = subprocess.Popen(cmd,
@ -35,20 +51,18 @@ def load_vimeo(item):
if created: if created:
orig = f orig = f
f.item = item f.item = item
f.info = ox.avinfo(f.data.path) f.info = ox.avinfo(name)
f.info['extension'] = media['extension'] f.info['extension'] = media['extension']
f.info['url'] = url f.info['url'] = url
f.path = '%(title)s.%(extension)s' % media f.path = '%(title)s.%(extension)s' % media
f.parse_info() f.parse_info()
f.selected = True f.selected = True
f.queued = True f.queued = False
if len(parts) > 1: if len(parts) > 1:
f.part = part f.part = part
part += 1 part += 1
f.save() f.save()
f.item.save() f.item.save()
f.extract_stream()
status = True
else: else:
return 'file exists' return 'file exists'
stream, created = Stream.objects.get_or_create(file=orig, resolution=resolution, format="mp4") stream, created = Stream.objects.get_or_create(file=orig, resolution=resolution, format="mp4")
@ -63,8 +77,8 @@ def load_vimeo(item):
stream.save() stream.save()
stream.make_timeline() stream.make_timeline()
if resolution == 720 and len(parts) == 1: if resolution == 720 and len(parts) == 1:
info = get_info(url, None)
media = info[0]
add_subtitles(item, media, tmp) add_subtitles(item, media, tmp)
item.update_timeline()
item.save()
o.chdir(cdir) o.chdir(cdir)
shutil.rmtree(tmp) shutil.rmtree(tmp)