import os import sys import json import shlex import asyncio from io import BytesIO from . import config, client, seen_videos async def split_files(filename, destination_dir): args = [ 'split', '--verbose', '--numeric-suffixes=0', '--bytes=2097152000', '--suffix-length=2', filename, os.path.join(destination_dir, os.path.basename(filename)) + '.part' ] proc = await asyncio.create_subprocess_exec(*args, stdout=asyncio.subprocess.PIPE) stdout, _ = await proc.communicate() return shlex.split(' '.join([i[14:] for i in stdout.decode().strip().split('\n')])) async def update_seen_videos(): with BytesIO(json.dumps(seen_videos).encode()) as file: file.name = 'autoytarchive.json' file.seek(0) await client.edit_message(config['config']['storage_chat_id'], config['config']['storage_message_id'], file=file) async def get_video(video_id): proc = await asyncio.create_subprocess_exec(sys.executable, 'youtube-dl-injected.py', '--dump-single-json', '--', video_id, stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.PIPE) stdout, stderr = await proc.communicate() if proc.returncode: error_message = next(i.strip() for i in stderr.decode().split('\n') if i.startswith('ERROR: ')) return error_message or (proc.returncode, (stderr + stdout).decode()) return json.loads(stdout)