add config, bootstrap from external source

This commit is contained in:
j 2023-11-14 14:09:43 +01:00
parent 89e215d93a
commit f3b9c2c0f5
3 changed files with 1484 additions and 2 deletions

1412
config.jsonc Normal file

File diff suppressed because it is too large Load diff

View file

@ -8,8 +8,8 @@ import ox
overwrite = ( overwrite = (
#('home', 'indiancinema'), ('home', 'padma'),
#('infoView', 'indiancinema'), ('infoView', 'padma'),
) )
base = abspath(dirname(__file__)) base = abspath(dirname(__file__))

70
utils.py Normal file
View file

@ -0,0 +1,70 @@
import subprocess
import ox
from archive.models import File, Stream
from archive.external import get_info
def load_vimeo(item):
urls = [url for url in item.data.get("links", []) if "vimeo.com" in url]
cdir = os.path.abspath(os.curdir)
orig = None
for url in urls:
for resolution in (720, 360):
tmp = tempfile.mkdtemp()
if isinstance(tmp, bytes):
tmp = tmp.decode('utf-8')
os.chdir(tmp)
cmd = ['yt-dlp', '-q', url]
cmd += ['-o', '%(title)80s.%(ext)s']
cmd += [
'-f', 'bestvideo[height<=%s][ext=mp4]+bestaudio[ext=m4a]/bestvideo+bestaudio' % resolution,
'--merge-output-format', 'mp4'
]
p = subprocess.Popen(cmd,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE, close_fds=True)
stdout, stderr = p.communicate()
parts = list(os.listdir(tmp))
if parts:
part = 1
for name in parts:
name = os.path.join(tmp, name)
oshash = ox.oshash(name)
if orig is None:
f, created = File.objects.get_or_create(oshash=oshash)
if created:
orig = f
f.item = item
f.info = ox.avinfo(f.data.path)
f.info['extension'] = media['extension']
f.info['url'] = url
f.path = '%(title)s.%(extension)s' % media
f.parse_info()
f.selected = True
f.queued = True
if len(parts) > 1:
f.part = part
part += 1
f.save()
f.item.save()
f.extract_stream()
status = True
else:
return 'file exists'
stream, created = Stream.objects.get_or_create(file=orig, resolution=resolution, format="mp4")
stream.media.name = stream.path(stream.name())
ox.makedirs(os.path.dirname(stream.media.path))
shutil.move(name, stream.media.path)
stream.available = True
if resolution == 720:
source = stream
else:
stream.source = source
stream.save()
stream.make_timeline()
if resolution == 720 and len(parts) == 1:
info = get_info(url, None)
media = info[0]
add_subtitles(item, media, tmp)
o.chdir(cdir)
shutil.rmtree(tmp)