File size: 1,567 Bytes
bd65e34
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
from pathlib import Path
import subprocess


def compress(TWITCH_ID: str) -> str:
    file = f"{TWITCH_ID}.tar.lz4"
    subprocess.Popen(["tar", "-clvf", file, TWITCH_ID]).communicate()

    return file


def upload(file: str, prefix: str = "frames/"):
    subprocess.Popen(
        [
            "rclone",
            "--config",
            "rclone.conf",
            "copy",
            file,
            f"r2:lol-highlights-eu/{prefix}/",
        ]
    ).communicate()


def download(file: str, out_folder: str = "."):
    if not Path(file).exists():
        print(
            subprocess.Popen(
                [
                    "rclone",
                    "--config",
                    "rclone.conf",
                    "copy",
                    f"r2:lol-highlights-eu/{file}",
                    out_folder,
                ]
            ).communicate()
        )
        return file


def list_files(directory: str) -> list[str]:
    out, _ = subprocess.Popen(
        [
            "rclone",
            "--config",
            "rclone.conf",
            "ls",
            "--exclude",
            "*.jpg",
            f"r2:lol-highlights-eu/{directory}",
        ],
        stdout=subprocess.PIPE,
    ).communicate()
    out = [x.strip().split(" ")[-1] for x in out.decode("utf-8").split("\n") if len(x)]
    return out


def decompress(file: str):
    subprocess.Popen(["tar", "-xvf", file]).communicate()


def download_frames_and_unpack(filename: str):
    download(f"frames/{filename}")
    decompress(filename)
    Path(filename).unlink()