Skip to content

Commit

Permalink
added tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Jacoblightning committed Jan 21, 2024
1 parent bf20f32 commit 161395b
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 26 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.idea
venv
__pycache__
/*.bnd
/*.mp4
15 changes: 15 additions & 0 deletions test_mainfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from yt2flp import *

def test_startup():
assert startup_and_options(True) == {"boost": True, "debug": True, "name": "output"}



class TestUrls:
def test_valid_url(self):
assert stripurl("https://www.youtube.com/watch?v=EIyixC9NsLI&si=ksjrhgksjrbg") == "https://youtu.be/EIyixC9NsLI"

def test_random_url(self):
import secrets
urldata = secrets.token_hex(15)
assert stripurl(f"https://www.youtube.com/watch?v={urldata}&si={secrets.token_hex(10)}") == f"https://youtu.be/{urldata}"
87 changes: 61 additions & 26 deletions yt2flp.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import shutil
import sys
from sys import argv
import os
from yt_dlp import YoutubeDL
Expand Down Expand Up @@ -33,29 +34,63 @@
}


if len(argv) < 2:
raise RuntimeError("NEED MORE ARGUMENTS, IM HUNGRY 4 THE ARGUMENTS")

b = False
if input("Would you like to boost the volume? Y/N").lower() == "y":
b = True
short = (
argv[1]
.replace("youtube.com/watch?v=", "youtu.be/")
.replace("https://www.", "https://")
)
if "si=" in short:
short = short.split("si=")[0][:-1]
name = input("What should the file name be? ")

with YoutubeDL(yt_options) as ydl:
ydl.download([short])
if b:
os.system('ffmpeg -i vid.mp4 -af "volume=3" -c:v copy output.mp4')
os.unlink("vid.mp4")
else:
shutil.move("vid.mp4", "output.mp4")

os.system(f"python helper1.py output.mp4 {name}.bnd")
if input("Delete Intermediate File? [N/y]").strip().lower().startswith("y"):
os.unlink("output.mp4")
def startup_and_options(DEBUG=False):
if not DEBUG:
if len(argv) < 3:
if (len(argv) == 2 and "DEBUG" in argv) or len(argv) < 2:
raise RuntimeError("NEED MORE ARGUMENTS, IM HUNGRY 4 THE ARGUMENTS")
DEBUG = "DEBUG" in argv or DEBUG
boost = False
if DEBUG or input("Would you like to boost the volume? Y/N").lower() == "y":
boost = True
if not DEBUG:
name = input("What should the file name be? ")
else:
name = "output"
return {"boost": boost, "debug": DEBUG, "name": name}


def stripurl(url):
short = url.replace("youtube.com/watch?v=", "youtu.be/").replace(
"https://www.", "https://"
)
if "si=" in short:
short = short.split("si=")[0][:-1]
return short


def download(url):
shorturl = stripurl(url)
with YoutubeDL(yt_options) as ydl:
ydl.download([shorturl])


def boost(doIt):
if doIt:
os.system('ffmpeg -i vid.mp4 -af "volume=3" -c:v copy output.mp4')
os.unlink("vid.mp4")
else:
shutil.move("vid.mp4", "output.mp4")


def convert(toName):
os.system(f"python helper1.py output.mp4 {toName}.bnd")


def main():
options = startup_and_options()
boo = options["boost"]
debug = options["debug"]
name = options["name"]
url = argv[1]
download(url)
boost(boo)
convert(name)
if debug or input("Delete Intermediate File? [N/y]").strip().lower().startswith(
"y"
):
os.unlink("output.mp4")


if __name__ == "__main__":
main()

0 comments on commit 161395b

Please sign in to comment.