Skip to content

Commit 5948ca1

Browse files
committed
happi :)
0 parents  commit 5948ca1

File tree

10 files changed

+297
-0
lines changed

10 files changed

+297
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
replit_ffmpeg.egg-info/
2+
start.bat

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2023 JC
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# replit-ffmpeg
2+
3+
A simple tool for installing ffmpeg, libopus (opus) and youtube dl (optional) for you on Replit.
4+
5+
```bash
6+
$ pip install replit-ffmpeg
7+
```
8+
9+
To use it, simply run this in your terminal:
10+
11+
```bash
12+
$ replit-ffmpeg
13+
```
14+
15+
That's about it. Enjoy your "FFmpeg." Yup, it sounds weird.

dist/replit-ffmpeg-0.1.tar.gz

4.57 KB
Binary file not shown.

pyproject.toml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
[build-system]
2+
requires = ["flit_core >=3.2,<4"]
3+
build-backend = "flit_core.buildapi"
4+
5+
[project]
6+
name = "replit-ffmpeg"
7+
version = "0.1"
8+
description = "Installs FFmpeg for you on Replit."
9+
keywords = ["replit", "ffmpeg", "opus", "youtube-dl"]
10+
authors = [
11+
{ name = "AWeirdDev", email = "aweirdscratcher@gmail.com" },
12+
]
13+
license = { file = "LICENSE" }
14+
readme = "README.md"
15+
classifiers = [
16+
"Programming Language :: Python :: 3.9",
17+
"License :: OSI Approved :: MIT License",
18+
"Operating System :: OS Independent",
19+
]
20+
requires-python = ">=3.9"
21+
dependencies = [
22+
"rich",
23+
"requests"
24+
]
25+
26+
[project.scripts]
27+
replit-ffmpeg = "replit_ffmpeg.installer:main"
28+
29+
[project.urls]
30+
"Homepage" = "https://github.com/AWeirdScratcher/replit-ffmpeg"
31+
"Bug Tracker" = "https://github.com/AWeirdScratcher/replit-ffmpeg/issues"

replit_ffmpeg/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from .installer import main
2+
3+
__all__ = (
4+
'main',
5+
)

replit_ffmpeg/__main__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from replit_ffmpeg.installer import main
2+
3+
main()

replit_ffmpeg/installer.py

Lines changed: 190 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,190 @@
1+
import os
2+
import shutil
3+
import time
4+
import requests
5+
6+
from rich.console import Console
7+
from rich.markdown import Markdown
8+
9+
def main():
10+
console = Console()
11+
12+
console.print()
13+
console.print(
14+
" I will install [blue]ffmpeg, opus and youtube dl (opt)[/blue] for you."
15+
)
16+
console.print(
17+
" Make sure this REPL is clear so that nothing will be overwritten."
18+
)
19+
console.print()
20+
_next: str = console.input(
21+
" [green]?[/green] Continue? [blue](Yn)[/blue] "
22+
)
23+
console.print()
24+
25+
if _next.lower() not in ["y", "yes"]:
26+
exit(1)
27+
28+
_plain_ans_with_ytdl = console.input(
29+
" [green]?[/green] Would you also like me to install "
30+
"[red]youtube dl[/red]? [blue](Yn)[/blue] "
31+
)
32+
console.print()
33+
34+
with_ytdl: bool = _plain_ans_with_ytdl.lower() in ["y", "yes"]
35+
36+
r = None
37+
38+
headers={
39+
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36 OPR/100.0.0.0 (Edition GX-CN)"
40+
}
41+
42+
def download_ffmpeg():
43+
global r
44+
r = requests.get("https://johnvansickle.com/ffmpeg/releases/ffmpeg-release-amd64-static.tar.xz", headers=headers)
45+
46+
console.print(
47+
"[blue]install[/blue] ffmpeg static "
48+
"[d white](2x attempts)[/d white]"
49+
)
50+
51+
START = time.time()
52+
53+
for _ in range(2):
54+
try:
55+
download_ffmpeg()
56+
break
57+
except requests.exceptions.SSLError:
58+
console.print(
59+
"[d red]error [/d red][d] SSL error: retrying[/d]"
60+
)
61+
62+
console.print(
63+
"[blue]unpack [/blue] ffmpeg static "
64+
"[d white]@ ffmpeg.tar.xz[/d white]"
65+
)
66+
with open('ffmpeg.tar.xz', 'wb') as f:
67+
f.write(r.content)
68+
69+
os.system('tar -xf ffmpeg.tar.xz')
70+
71+
console.print(
72+
"[blue]moving [/blue] ffmpeg, ffprobe"
73+
)
74+
os.system('mv ffmpeg-6.0-amd64-static/ffmpeg ffmpeg')
75+
os.system('mv ffmpeg-6.0-amd64-static/ffprobe ffprobe')
76+
77+
console.print("[red]remove [/red] ffmpeg.tar.xz")
78+
os.remove('ffmpeg.tar.xz')
79+
80+
# https://www.linuxfromscratch.org/blfs/view/svn/multimedia/opus.html
81+
82+
console.print(
83+
"[blue]install[/blue] opus archive"
84+
)
85+
86+
opus_r = requests.get("https://archive.mozilla.org/pub/opus/opus-1.3.1.tar.gz", headers=headers)
87+
88+
with open("opus-1.3.1.tar.gz", "wb") as f:
89+
f.write(opus_r.content)
90+
91+
console.print(
92+
"[blue]unpack [/blue] opus archive "
93+
"[d white]@ opus-1.3.1.tar.gz[/d white]"
94+
)
95+
96+
os.system('tar -xf opus-1.3.1.tar.gz')
97+
os.remove("opus-1.3.1.tar.gz")
98+
99+
console.print(
100+
"[blue]command[/blue] 'configure' & 'make'"
101+
)
102+
console.print()
103+
104+
os.system("""cd opus-1.3.1 && ./configure --prefix=/usr \
105+
--disable-static \
106+
--docdir=/usr/share/doc/opus-1.3.1 && make""")
107+
108+
console.print()
109+
console.print(
110+
"[green]success[/green] built opus"
111+
)
112+
os.system("""mkdir opus && mv opus-1.3.1/.libs/* opus/""")
113+
console.print(
114+
"[blue]moving [/blue] 'libopus.so', 'libopus.so.0', and many other."
115+
)
116+
117+
console.print()
118+
119+
console.print(Markdown(
120+
"""
121+
# It's DONE!
122+
Congratulations! We've installed ffmpeg and opus for your REPL!
123+
124+
In constrast, I've:
125+
126+
- Installed `ffmpeg` and `ffprobe` in this directory
127+
- Installed `opus`
128+
- Created a dir named `opus` that contains `libopus.so` files
129+
130+
...that's pretty much it!
131+
132+
If you're making a Discord bot, whether it's `py-cord` or `discord.py`, use:
133+
134+
```python
135+
import discord
136+
137+
discord.opus.load_opus("opus/libopus.so")
138+
```
139+
140+
That's it, and have fun hacking! <3
141+
""",
142+
"one-dark"
143+
))
144+
145+
console.print()
146+
147+
if with_ytdl:
148+
console.print(
149+
"[d blue]extra [/d blue][d] downloading yt-dlp[/d]..."
150+
)
151+
os.system('pip install yt-dlp --quiet')
152+
console.print(
153+
"[d blue]extra [/d blue][d] installed yt-dlp. "
154+
"Use `import yt_dlp` instead of `import youtube_dl`.[/d]"
155+
)
156+
console.print()
157+
158+
console.print(
159+
f"[blue]took {(time.time() - START):.2f}s[/blue]"
160+
)
161+
console.print()
162+
console.print(
163+
" If you want to save some space for your REPL, this might help:"
164+
)
165+
console.print()
166+
console.input(
167+
" [green]?[/green] Cleanup installed contents? [blue](Yn)[/blue] "
168+
)
169+
170+
def rmdir(folder: str):
171+
# https://stackoverflow.com/questions/185936/how-to-delete-the-contents-of-a-folder
172+
for filename in os.listdir(folder):
173+
file_path = os.path.join(folder, filename)
174+
try:
175+
if os.path.isfile(file_path) or os.path.islink(file_path):
176+
os.unlink(file_path)
177+
elif os.path.isdir(file_path):
178+
shutil.rmtree(file_path)
179+
except Exception as e:
180+
console.print(
181+
'[red]failed [/red] '
182+
'cannot delete %s. Reason: %s' % (file_path, e)
183+
)
184+
os.rmdir(folder)
185+
186+
rmdir('opus-1.3.1')
187+
rmdir('ffmpeg-6.0-amd64-static')
188+
189+
console.print("[blue]all done![/blue]")
190+

setup.cfg

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[metadata]
2+
description_file = README.md

setup.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
from setuptools import setup
2+
3+
with open("README.md", "r", encoding="utf-8") as f:
4+
readme = f.read()
5+
6+
setup(
7+
name="replit-ffmpeg",
8+
author="AWeirdDev",
9+
version="0.1",
10+
license="MIT License",
11+
description="Installs FFmpeg for you on Replit.",
12+
long_description=readme,
13+
long_description_content_type="text/markdown",
14+
author_email="aweirdscratcher@gmail.com",
15+
packages=['replit_ffmpeg'],
16+
classifiers=[
17+
"Programming Language :: Python :: 3.9",
18+
"License :: OSI Approved :: MIT License",
19+
"Operating System :: OS Independent",
20+
"Environment :: Console",
21+
],
22+
keywords=["replit", "ffmpeg", "opus", "youtube-dl"],
23+
entry_points={
24+
"console_scripts": [
25+
"replit-ffmpeg=replit_ffmpeg.installer:main"
26+
]
27+
}
28+
)

0 commit comments

Comments
 (0)