From 5948ca1a14894ea3e0d270715e12688f52bcf6d9 Mon Sep 17 00:00:00 2001 From: AWeirdScratcher Date: Tue, 22 Aug 2023 17:10:27 +0800 Subject: [PATCH] happi :) --- .gitignore | 2 + LICENSE | 21 ++++ README.md | 15 +++ dist/replit-ffmpeg-0.1.tar.gz | Bin 0 -> 4679 bytes pyproject.toml | 31 ++++++ replit_ffmpeg/__init__.py | 5 + replit_ffmpeg/__main__.py | 3 + replit_ffmpeg/installer.py | 190 ++++++++++++++++++++++++++++++++++ setup.cfg | 2 + setup.py | 28 +++++ 10 files changed, 297 insertions(+) create mode 100644 .gitignore create mode 100644 LICENSE create mode 100644 README.md create mode 100644 dist/replit-ffmpeg-0.1.tar.gz create mode 100644 pyproject.toml create mode 100644 replit_ffmpeg/__init__.py create mode 100644 replit_ffmpeg/__main__.py create mode 100644 replit_ffmpeg/installer.py create mode 100644 setup.cfg create mode 100644 setup.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..937227c --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +replit_ffmpeg.egg-info/ +start.bat \ No newline at end of file diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..2e5948a --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2023 JC + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..cc19128 --- /dev/null +++ b/README.md @@ -0,0 +1,15 @@ +# replit-ffmpeg + +A simple tool for installing ffmpeg, libopus (opus) and youtube dl (optional) for you on Replit. + +```bash +$ pip install replit-ffmpeg +``` + +To use it, simply run this in your terminal: + +```bash +$ replit-ffmpeg +``` + +That's about it. Enjoy your "FFmpeg." Yup, it sounds weird. diff --git a/dist/replit-ffmpeg-0.1.tar.gz b/dist/replit-ffmpeg-0.1.tar.gz new file mode 100644 index 0000000000000000000000000000000000000000..111cfc273f635c1b0239372b649fa5c32772e07c GIT binary patch literal 4679 zcmZ9QWl+?Cw}zK)5EUd{aglE6mTr)45Xq$kiKSc+K}tHMd+8F8T%;sKaFLb}sRij~ zm;GJ;_s*TUbHAK9AD(%?op+u&;CNC}*PsnYe8AV~m4}-jzq7OFD<>CzApv0lzZbrs zeYxwvMGe%o1zc4fGZB6n@!4mc^^m$r^V_ia8%2)X?Ma$Vb!&<7@44-~-kssCyT0*vZ!hmoMlb2(oqO`~O*$v)Z*Nwc z)`YU&ta`Q{d3&~-OaQuWy|W$%v(;S_^jmXGbpaS6H_tR&_+qo%vW7a7t9= zm4-ta;ovCdl$Ya00;O@jYu7b>9|e^RMFTW?EWMNA54pw|saWEL$6v<|jl3oH>wJ8w z7^n=*9N{ZUhdp)RJG0l*Wsevj3o1T`p5yu!23mY~QARxEDT z^c$8PK;bglhgBloW%$H(b`HKGgczbIt37zE;~ov?24{kGJ>&Vc20z_76D4O$ zd%;oIeK)amo#@^3B~#E_BG_q@^Zc=NOlQ(PreUK&A(xJ$yz>-uogCE&3LC?f;WPU& zSQ63@GRRUZf9kPhwLV2TDaOx2yJVD3dmn9d7PF@c{44@W1sE?@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Q(wF9ta?R09!!Y2!BvQ0FLTMsnperxqN)el zVE)jlCm1qn(P4VW16`=m(C~**X$le;GC%6gUPT# z%QSGd8nOL{m#_@5c?4Eb#8La*NZ^mkPM-O*1Mb0ek>jp`9B;D)6nf_Q%M+sT? zty4dt3PI2oP#FSn-YVceU&2vdYO?5dUkga8V`l^`hT)mVg-%$P|GPeVUI1ue>=pqLO$>Yj z2fk3Cr0!Ja@1`zXz%{h_A_1l)psUN|pPE6Q1nV&s8CWC%RYFW^z0TjZjwOU(5^AK+ z#c!y2b9>^_NvQME-%D&%@VIUC&oHbmv|x7MS~AoQ_qufa?m17DjJ=#8lY@Iq^Fra& zts2*Y|Iq-E+tCfcru!^sLqT>W8JMuF;n)PkQ`!C90PX)F3~{TxfcK*Mq$^++80b9$ zsI@Gnp1_&Wvc1xBD-2CQZ}@HM^Z$(tJ3Uc=A6zq@!5gp*t^erY8lFj@y#<%qWPlpc zOMUnswX_?9Yd$cS(Fwrkq4Oj&D^yQ90Dp(g!mYydu*hiu(|QKryf)#% zzxOQAfc&*x&9WrW(E4$vEge|W*w*_Cf~5dtTRzyA!wYqan=GPVgrRRAXdx!QV%rOf ziQ(ZF=3Uhq1#FwhPXJK44+I-60){yF=%k#S3GUwu;V%wuGy+7+0;_uK$e(>#EX#}* zceB&BxwHiAeX7ari`GH%2zS_yZ*POz?^-OB-`59(8hn;vU-5fxJ@Iiji4YSj@xhYW z+yyJmaMfuM2m@uJ4&SzoMG#YP%|hxm?zxeI|4~$MD8%gC=W~JxxdC|Bo}d3IKmw)GQb@ H0s{RP8?0hJ literal 0 HcmV?d00001 diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..cb982bc --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,31 @@ +[build-system] +requires = ["flit_core >=3.2,<4"] +build-backend = "flit_core.buildapi" + +[project] +name = "replit-ffmpeg" +version = "0.1" +description = "Installs FFmpeg for you on Replit." +keywords = ["replit", "ffmpeg", "opus", "youtube-dl"] +authors = [ + { name = "AWeirdDev", email = "aweirdscratcher@gmail.com" }, +] +license = { file = "LICENSE" } +readme = "README.md" +classifiers = [ + "Programming Language :: Python :: 3.9", + "License :: OSI Approved :: MIT License", + "Operating System :: OS Independent", +] +requires-python = ">=3.9" +dependencies = [ + "rich", + "requests" +] + +[project.scripts] +replit-ffmpeg = "replit_ffmpeg.installer:main" + +[project.urls] +"Homepage" = "https://github.com/AWeirdScratcher/replit-ffmpeg" +"Bug Tracker" = "https://github.com/AWeirdScratcher/replit-ffmpeg/issues" \ No newline at end of file diff --git a/replit_ffmpeg/__init__.py b/replit_ffmpeg/__init__.py new file mode 100644 index 0000000..98e0f6d --- /dev/null +++ b/replit_ffmpeg/__init__.py @@ -0,0 +1,5 @@ +from .installer import main + +__all__ = ( + 'main', +) \ No newline at end of file diff --git a/replit_ffmpeg/__main__.py b/replit_ffmpeg/__main__.py new file mode 100644 index 0000000..31cc036 --- /dev/null +++ b/replit_ffmpeg/__main__.py @@ -0,0 +1,3 @@ +from replit_ffmpeg.installer import main + +main() diff --git a/replit_ffmpeg/installer.py b/replit_ffmpeg/installer.py new file mode 100644 index 0000000..30c2243 --- /dev/null +++ b/replit_ffmpeg/installer.py @@ -0,0 +1,190 @@ +import os +import shutil +import time +import requests + +from rich.console import Console +from rich.markdown import Markdown + +def main(): + console = Console() + + console.print() + console.print( + " I will install [blue]ffmpeg, opus and youtube dl (opt)[/blue] for you." + ) + console.print( + " Make sure this REPL is clear so that nothing will be overwritten." + ) + console.print() + _next: str = console.input( + " [green]?[/green] Continue? [blue](Yn)[/blue] " + ) + console.print() + + if _next.lower() not in ["y", "yes"]: + exit(1) + + _plain_ans_with_ytdl = console.input( + " [green]?[/green] Would you also like me to install " + "[red]youtube dl[/red]? [blue](Yn)[/blue] " + ) + console.print() + + with_ytdl: bool = _plain_ans_with_ytdl.lower() in ["y", "yes"] + + r = None + + headers={ + "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)" + } + + def download_ffmpeg(): + global r + r = requests.get("https://johnvansickle.com/ffmpeg/releases/ffmpeg-release-amd64-static.tar.xz", headers=headers) + + console.print( + "[blue]install[/blue] ffmpeg static " + "[d white](2x attempts)[/d white]" + ) + + START = time.time() + + for _ in range(2): + try: + download_ffmpeg() + break + except requests.exceptions.SSLError: + console.print( + "[d red]error [/d red][d] SSL error: retrying[/d]" + ) + + console.print( + "[blue]unpack [/blue] ffmpeg static " + "[d white]@ ffmpeg.tar.xz[/d white]" + ) + with open('ffmpeg.tar.xz', 'wb') as f: + f.write(r.content) + + os.system('tar -xf ffmpeg.tar.xz') + + console.print( + "[blue]moving [/blue] ffmpeg, ffprobe" + ) + os.system('mv ffmpeg-6.0-amd64-static/ffmpeg ffmpeg') + os.system('mv ffmpeg-6.0-amd64-static/ffprobe ffprobe') + + console.print("[red]remove [/red] ffmpeg.tar.xz") + os.remove('ffmpeg.tar.xz') + + # https://www.linuxfromscratch.org/blfs/view/svn/multimedia/opus.html + + console.print( + "[blue]install[/blue] opus archive" + ) + + opus_r = requests.get("https://archive.mozilla.org/pub/opus/opus-1.3.1.tar.gz", headers=headers) + + with open("opus-1.3.1.tar.gz", "wb") as f: + f.write(opus_r.content) + + console.print( + "[blue]unpack [/blue] opus archive " + "[d white]@ opus-1.3.1.tar.gz[/d white]" + ) + + os.system('tar -xf opus-1.3.1.tar.gz') + os.remove("opus-1.3.1.tar.gz") + + console.print( + "[blue]command[/blue] 'configure' & 'make'" + ) + console.print() + + os.system("""cd opus-1.3.1 && ./configure --prefix=/usr \ + --disable-static \ + --docdir=/usr/share/doc/opus-1.3.1 && make""") + + console.print() + console.print( + "[green]success[/green] built opus" + ) + os.system("""mkdir opus && mv opus-1.3.1/.libs/* opus/""") + console.print( + "[blue]moving [/blue] 'libopus.so', 'libopus.so.0', and many other." + ) + + console.print() + + console.print(Markdown( + """ + # It's DONE! + Congratulations! We've installed ffmpeg and opus for your REPL! + + In constrast, I've: + + - Installed `ffmpeg` and `ffprobe` in this directory + - Installed `opus` + - Created a dir named `opus` that contains `libopus.so` files + + ...that's pretty much it! + + If you're making a Discord bot, whether it's `py-cord` or `discord.py`, use: + + ```python + import discord + + discord.opus.load_opus("opus/libopus.so") + ``` + + That's it, and have fun hacking! <3 + """, + "one-dark" + )) + + console.print() + + if with_ytdl: + console.print( + "[d blue]extra [/d blue][d] downloading yt-dlp[/d]..." + ) + os.system('pip install yt-dlp --quiet') + console.print( + "[d blue]extra [/d blue][d] installed yt-dlp. " + "Use `import yt_dlp` instead of `import youtube_dl`.[/d]" + ) + console.print() + + console.print( + f"[blue]took {(time.time() - START):.2f}s[/blue]" + ) + console.print() + console.print( + " If you want to save some space for your REPL, this might help:" + ) + console.print() + console.input( + " [green]?[/green] Cleanup installed contents? [blue](Yn)[/blue] " + ) + + def rmdir(folder: str): + # https://stackoverflow.com/questions/185936/how-to-delete-the-contents-of-a-folder + for filename in os.listdir(folder): + file_path = os.path.join(folder, filename) + try: + if os.path.isfile(file_path) or os.path.islink(file_path): + os.unlink(file_path) + elif os.path.isdir(file_path): + shutil.rmtree(file_path) + except Exception as e: + console.print( + '[red]failed [/red] ' + 'cannot delete %s. Reason: %s' % (file_path, e) + ) + os.rmdir(folder) + + rmdir('opus-1.3.1') + rmdir('ffmpeg-6.0-amd64-static') + + console.print("[blue]all done![/blue]") + \ No newline at end of file diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 0000000..0f94f37 --- /dev/null +++ b/setup.cfg @@ -0,0 +1,2 @@ +[metadata] +description_file = README.md \ No newline at end of file diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..99ebbaf --- /dev/null +++ b/setup.py @@ -0,0 +1,28 @@ +from setuptools import setup + +with open("README.md", "r", encoding="utf-8") as f: + readme = f.read() + +setup( + name="replit-ffmpeg", + author="AWeirdDev", + version="0.1", + license="MIT License", + description="Installs FFmpeg for you on Replit.", + long_description=readme, + long_description_content_type="text/markdown", + author_email="aweirdscratcher@gmail.com", + packages=['replit_ffmpeg'], + classifiers=[ + "Programming Language :: Python :: 3.9", + "License :: OSI Approved :: MIT License", + "Operating System :: OS Independent", + "Environment :: Console", + ], + keywords=["replit", "ffmpeg", "opus", "youtube-dl"], + entry_points={ + "console_scripts": [ + "replit-ffmpeg=replit_ffmpeg.installer:main" + ] + } +)