-
-
Notifications
You must be signed in to change notification settings - Fork 11
/
downloader.py
148 lines (110 loc) · 3.78 KB
/
downloader.py
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
import sys
import os
import shutil
import glob
import requests
from py7zr import unpack_7zarchive
import re
from pyffmpeg import misc
version = os.environ['GITHUB_REF'].split('/')[-1]
print(f'version: {version}')
_, os_name, token = sys.argv
osn = os_name.split('-')[0]
cwd = os.path.realpath('.')
bin_path = os.path.join(cwd, 'pyffmpeg/static/bin')
# Download Qmlview archive for os
# extract to folder
# copy all those contents to folder_name, skipping the existing ones
# Login to GH
with open('token.txt', 'w') as tok:
tok.write(token)
print('Finished writing token file')
cmd = 'gh auth login --with-token < token.txt'
os.system(cmd)
print('Authenticated')
def extract_to_folder(ffmpeg: str, arch: str, z=True) -> str:
if z:
shutil.register_unpack_format('7zip', ['.7z'], unpack_7zarchive)
shutil.unpack_archive(arch, extract_dir=cwd)
print('done with unpack')
fpath = f'**/{ffmpeg}'
fname = glob.glob(fpath)[0]
return os.path.join(cwd, fname)
def replace_setup_file_version():
sta = '"Development Status :: 5 - Production/Stable"'
bta = '"Development Status :: 4 - Beta"'
ver = version.split('-')[0]
ver = ver.replace('v', '')
if 'beta' in version:
beta = version.split('-')[1]
beta = beta.split('beta.')[1]
ver += f'b{beta}'
with open('setup.py', 'r') as f:
data = f.read()
repl = re.compile("version='.*?[0-9]'")
ver_str = f"version='{ver}'"
data = repl.sub(ver_str, data)
if 'beta' in version:
data = data.replace(sta, bta)
else:
data = data.replace(bta, sta)
with open('setup.py', 'w') as fw:
fw.write(data)
print('Done changing version type')
# Build wheel
if os_name == 'win32':
# Download Qmlview archive for os
os_cmd = 'gh release download --repo'
os_cmd += ' github.com/GyanD/codexffmpeg --pattern "*full_build.7z"'
try:
os.system(os_cmd)
print('done with download of winbin')
# extract to folder
arch = glob.glob('ffmpeg*.7z')[0]
fullpath = extract_to_folder('ffmpeg.exe', arch)
out = 'win32'
misc.Paths().convert_to_py(fullpath, out)
# copy all those contents to folder_name, skip exitsting
win32 = os.path.join(bin_path, 'win32')
# replace
shutil.copy('win32.py', win32)
except Exception as err:
print(err)
print(os.listdir(cwd))
elif os_name == 'darwin':
try:
link = 'https://evermeet.cx/ffmpeg/get/ffmpeg/zip'
resp = requests.get(link, stream=True)
with open('ffmpeg.7z', 'wb') as z:
for chunk in resp.iter_content(chunk_size=2048):
if chunk:
z.write(chunk)
arch = glob.glob('ffmpeg*.7z')[0]
fullpath = extract_to_folder('ffmpeg',arch, z=False)
out = 'darwin'
misc.Paths().convert_to_py(fullpath, out)
darwin = os.path.join(bin_path, 'darwin')
shutil.copy('darwin.py', darwin)
except Exception as err:
print(err)
print(os.listdir(cwd))
else:
# Download Qmlview archive for os
try:
link = 'https://johnvansickle.com/ffmpeg/builds/ffmpeg-git-i686-static.tar.xz'
resp = requests.get(link, stream=True)
with open('ffmpeg.tar.xz', 'wb') as z:
for chunk in resp.iter_content(chunk_size=2048):
if chunk:
z.write(chunk)
arch = glob.glob('ffmpeg*.tar.xz')[0]
fullpath = extract_to_folder('ffmpeg', arch, z=False)
out = 'linux'
misc.Paths().convert_to_py(fullpath, out)
linux = os.path.join(bin_path, 'linuxmod')
shutil.copy('linux.py', linux)
except Exception as err:
print(err)
print(os.listdir(cwd))
# replace_setup_file_version()
print('All Done')