Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support cross-platform apps and directories #3

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[tool.poetry]
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please exclude this python poetry configuration file from your commit

name = "mp4combine-2.5.0"
version = "0.1.0"
description = ""
authors = ["Sverrir Sigmundarson", "felciano <[email protected]>"]

[tool.poetry.dependencies]
python = "^3.10"
humanize = "^4.4.0"
colorama = "^0.4.5"
termcolor = "^2.0.1"

[tool.poetry.dev-dependencies]

[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"
35 changes: 22 additions & 13 deletions src/combine.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@
from datetime import timedelta # To store the parsed duration of files and calculate the accumulated duration
from random import shuffle # To be able to shuffle the list of files if the user requests it
import csv # To use for the cutpoint files they are CSV files
import platform # identify which platform we're running on
import tempfile # platform-independent tempoary files and directories

# default filenames
MP4BOX_DEFAULT_FILENAME = "mp4box" if not (platform.system() == "Windows") else "mp4box.exe"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider simplifying the conditional here to not use a negative, easier to read, also consider making the comparison case insensitive, i.e.

"mp4box.exe" if platform.system().casefold() == "Windows".casefold() else "mp4box"


#
# Provides natural string sorting (numbers inside strings are sorted in the correct order)
# http://stackoverflow.com/a/3033342/779521
Expand All @@ -55,6 +61,8 @@ def runMain():

# Construct the argument parser for the commandline
args = parseArguments()

print(args)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove print statement


# The burnsubs and cuts cannot be used together, they will produce incorrect subtitles to be burned into the video
if( args.burnsubs == True and not args.cuts is None):
Expand Down Expand Up @@ -267,35 +275,35 @@ def parseMp4boxMediaInfo(file_name, mp4box_path, regex_mp4box_duration):

#
# Locates the mp4box executable and returns a full path to it
def findMp4Box(path_to_gpac_install=None, working_dir=None):
def findMp4Box(path_to_gpac_install=None, working_dir=None, mpbox_filename=MP4BOX_DEFAULT_FILENAME):

if( not path_to_gpac_install is None and os.path.isfile(os.path.join(path_to_gpac_install, "mp4box.exe")) ):
return os.path.join(path_to_gpac_install, "mp4box.exe")
if( not path_to_gpac_install is None and os.path.isfile(os.path.join(path_to_gpac_install, mpbox_filename)) ):
return os.path.join(path_to_gpac_install, mpbox_filename)

# Attempts to search for it under the bin folder
bin_dist = os.path.join(working_dir, "..\\bin\\GPAC\\mp4box.exe")
bin_dist = os.path.join(working_dir, f"..\\bin\\GPAC\\{mpbox_filename}")
if( os.path.isfile(bin_dist)):
return str(Path(bin_dist).resolve())

# Attempts to search for it under C:\Program Files\GPAC
if( os.path.isfile("C:\\Program Files\\GPAC\\mp4box.exe")):
return "C:\\Program Files\\GPAC\\mp4box.exe"
if( os.path.isfile(f"C:\\Program Files\\GPAC\\{mpbox_filename}")):
return f"C:\\Program Files\\GPAC\\{mpbox_filename}"

# For 32 bit installs
if( os.path.isfile("C:\\Program Files\\GPAC\\mp4box.exe")):
return "C:\\Program Files (x86)\\GPAC\\mp4box.exe"
if( os.path.isfile(f"C:\\Program Files\\GPAC\\{mpbox_filename}")):
return f"C:\\Program Files (x86)\\GPAC\\{mpbox_filename}"

# Throw an error
raise ValueError('Could not locate GPAC install, please use the --gpac switch to specify the path to the mp4box.exe file on your system.')

#
# Locates the ffmpeg executable and returns a full path to it
def findffmpeg(path_to_ffmpeg_install=None, working_dir=None):
if( not path_to_ffmpeg_install is None and os.path.isfile(os.path.join(path_to_ffmpeg_install, "ffmpeg.exe")) ):
return os.path.join(path_to_ffmpeg_install, "ffmpeg.exe")
def findffmpeg(path_to_ffmpeg_install=None, working_dir=None, ffmpeg_filename="ffmpeg"):
Copy link
Owner

@sverrirs sverrirs Nov 28, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please make the same type of constant for FFMPEG as you've done for mp4box otherwise the script breaks on Windows

if( not path_to_ffmpeg_install is None and os.path.isfile(os.path.join(path_to_ffmpeg_install, ffmpeg_filename)) ):
return os.path.join(path_to_ffmpeg_install, ffmpeg_filename)

# Attempts to search for it under the bin folder
bin_dist = os.path.join(working_dir, "..\\bin\\ff\\ffmpeg.exe")
bin_dist = os.path.join(working_dir, f"..\\bin\\ff\\{ffmpeg_filename}")
if( os.path.isfile(bin_dist)):
return str(Path(bin_dist).resolve())

Expand Down Expand Up @@ -455,7 +463,7 @@ def addChaptersToVideoFile(mp4box_path, path_video_file, path_chapters_file):
# Overwrite the default temporary folder to somewhere we
# know that the current user has write privileges
prog_args.append("-tmp")
prog_args.append("{0}".format(os.environ['TMP']))
prog_args.append("{0}".format(tempfile.TemporaryDirectory()))

# Add the chapter file
prog_args.append("-add")
Expand Down Expand Up @@ -611,4 +619,5 @@ def parseArguments():

# If the script file is called by itself then execute the main function
if __name__ == '__main__':
print("HELLO")
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove this print statement

runMain()