Skip to content

Commit

Permalink
Fixed a bug with white space directories
Browse files Browse the repository at this point in the history
  • Loading branch information
cheezos committed Mar 25, 2023
1 parent f016b51 commit 1951104
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 31 deletions.
16 changes: 9 additions & 7 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def __init__(self) -> None:
self._label_log.setWordWrap(True)
self._label_log.setAlignment(Qt.AlignmentFlag.AlignCenter)
self._label_log.setStyleSheet("border: 1px solid black; margin: 1px")
self._button_foot = QPushButton(f"v{g.VERSION} | Created by Cheezos", self)
self._button_foot = QPushButton(f"v{g.VERSION}", self)
self._button_foot.resize(SBW, SBH)
X, Y = g.B_FOOT_POS
self._button_foot.move(X, Y)
Expand Down Expand Up @@ -159,14 +159,14 @@ def _verify_directories(self):
print("Verifying directories...")
g.dir_root = os.path.dirname(os.path.abspath(__file__))
print(f"Root: {g.dir_root}")
g.dir_bin = f"{g.dir_root}/bin"
g.dir_bin = os.path.join(g.dir_root, "bin")

if not os.path.exists(g.dir_bin):
os.mkdir(g.dir_bin)
print(f"Created bin directory")

print(f"Bin: {g.dir_bin}")
g.dir_output = f"{g.dir_root}/output"
g.dir_output = os.path.join(g.dir_root, "output")

if not os.path.exists(g.dir_output):
os.mkdir(g.dir_output)
Expand All @@ -177,14 +177,16 @@ def _verify_directories(self):

def _handle_windows(self):
print("Windows detected")
FFMPEG_PATH = f"{g.dir_bin}/ffmpeg.exe"
FFPROBE_PATH = f"{g.dir_bin}/ffprobe.exe"
FFMPEG_PATH = os.path.join(g.dir_bin, "ffmpeg.exe")
print(f"FFmpeg: {FFMPEG_PATH}")
FFPROBE_PATH = os.path.join(g.dir_bin, "ffprobe.exe")
print(f"FFprobe: {FFPROBE_PATH}")

if os.path.exists(FFMPEG_PATH) and os.path.exists(FFPROBE_PATH):
BIN_PATH = g.dir_bin
g.ffmpeg_installed = True
g.ffmpeg_path = f"{BIN_PATH}/ffmpeg.exe"
g.ffprobe_path = f"{BIN_PATH}/ffprobe.exe"
g.ffmpeg_path = FFMPEG_PATH
g.ffprobe_path = FFPROBE_PATH
self._button_select.setEnabled(True)
else:
self._download_thread = DownloadThread()
Expand Down
Binary file modified preview.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion src/globals.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
VERSION = "3.0.0"
VERSION = "3.0.1"
FFMPEG_DL = "https://github.com/BtbN/FFmpeg-Builds/releases/download/latest/ffmpeg-master-latest-win64-gpl.zip"
TITLE = f"Cheezos Video Compressor v{VERSION}"
READY_TEXT = f"Select your videos to get started."
Expand Down
20 changes: 5 additions & 15 deletions src/thread.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,28 +20,18 @@ def _run_pass(self, file_path, bitrate, pass_1: bool):
PASS = "1" if pass_1 else "2"
MSG = f"Compressing, please wait...\n\nVideo queue: {COMPLETED_COUNT}/{QUEUE_COUNT}\nPass: {PASS}/2"
FILE_NAME = file_path.split("/")[-1]
FFMPEG = g.ffmpeg_path
INPUT = file_path
FFMPEG_PATH = g.ffmpeg_path
INPUT_PATH = file_path
BITRATE = f"{bitrate}k"
print(f"New bitrate: {BITRATE}")
OUTPUT = rf"{g.dir_output}/{FILE_NAME}-compressed.mp4"
OUTPUT_PATH = os.path.join(g.dir_output, f"{FILE_NAME}-compressed.mp4")
print(MSG)
cmd = ""

if pass_1:
cmd = r""""%s" -i "%s" -y -b:v %s -an -pass 1 -f mp4 TEMP""" % (
FFMPEG,
INPUT,
BITRATE,
)
cmd = f'"{FFMPEG_PATH}" -i "{INPUT_PATH}" -y -b:v {BITRATE} -an -pass 1 -f mp4 TEMP'
else:
cmd = r""""%s" -i "%s" -y -b:v %sk -b:a %sk -pass 2 "%s" """ % (
g.ffmpeg_path,
file_path,
bitrate,
128,
OUTPUT,
)
cmd = f'"{FFMPEG_PATH}" -i "{INPUT_PATH}" -y -b:v {BITRATE} -b:a 128k -pass 2 "{OUTPUT_PATH}"'

print(cmd)
self.update_label.emit(MSG)
Expand Down
13 changes: 5 additions & 8 deletions src/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,8 @@


def get_video_length(file_path):
VIDEO = '"%s"' % file_path
CMD = (
"%s -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 %s"
% (g.ffprobe_path, VIDEO)
)
VIDEO = "%s" % file_path
CMD = f'"{g.ffprobe_path}" -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 "{file_path}"'
PROCESS = subprocess.Popen(CMD, stdout=subprocess.PIPE, shell=True)
LENGTH = float(PROCESS.stdout.readline())
print(f"Video duration: {LENGTH}")
Expand All @@ -28,9 +25,9 @@ def get_video_bitrate(file_path, target_file_size):

def clean():
try:
os.remove("TEMP")
os.remove("ffmpeg2pass-0.log")
os.remove("ffmpeg2pass-0.log.mbtree")
os.remove(os.path.join(g.dir_root, "TEMP"))
os.remove(os.path.join(g.dir_root, "ffmpeg2pass-0.log"))
os.remove(os.path.join(g.dir_root, "ffmpeg2pass-0.log.mbtree"))
except:
print("No temporary files to remove")

Expand Down

0 comments on commit 1951104

Please sign in to comment.