PK!q6pyvid.py#!/usr/bin/env python # -*- encoding: utf-8 """pyvid package. converts files in path to smaller mp4 files.""" from typing import List, Tuple, Generator, Any from pathlib import Path import os import re import ffmpeg import click import click_spinner as spin from hurry.filesize import size __version__ = "0.0.8" class VideoPath(os.PathLike): __slots__ = ("path", "exts", "force", "rem") def __init__( self, path: str, ext: str = "", force: bool = False, rem: bool = False ) -> None: self.path = Path(path) if ext: self.exts = [ext[1:] if ext[0] == "." else ext] else: self.exts = ["mp4", "avi", "mkv", "mov", "webm"] self.force = force self.rem = rem def __fspath__(self): return str(self.path) def __iter__(self) -> Generator: if self.path.is_file(): yield Video(self.path, self.force) else: for y in self.exts: for z in self.path.glob("*." + y): yield Video(z, self.force) class Video: __slots__ = ("path", "converted", "force", "size", "conv_path") def __init__(self, path: Path, force: bool) -> None: self.path = path self.converted = 0 self.force = force self.size = self.path.stat().st_size conv_name = self.path.with_suffix(".mp4").name self.conv_path = self.path.parent / "converted" / conv_name def __repr__(self) -> str: return f"