2020-06-11 00:04:54 +08:00
|
|
|
#!/usr/bin/env python
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
import logging
|
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
|
|
|
|
from gooey import Gooey, GooeyParser
|
|
|
|
|
2022-01-24 12:07:52 +08:00
|
|
|
from ffsubsync.constants import (
|
2020-06-11 00:04:54 +08:00
|
|
|
RELEASE_URL,
|
|
|
|
WEBSITE,
|
|
|
|
DEV_WEBSITE,
|
|
|
|
DESCRIPTION,
|
|
|
|
LONG_DESCRIPTION,
|
|
|
|
PROJECT_NAME,
|
|
|
|
PROJECT_LICENSE,
|
|
|
|
COPYRIGHT_YEAR,
|
|
|
|
SUBSYNC_RESOURCES_ENV_MAGIC,
|
|
|
|
)
|
2022-01-24 12:07:52 +08:00
|
|
|
|
2020-08-05 10:42:27 +08:00
|
|
|
# set the env magic so that we look for resources in the right place
|
|
|
|
if SUBSYNC_RESOURCES_ENV_MAGIC not in os.environ:
|
2022-01-24 12:07:52 +08:00
|
|
|
os.environ[SUBSYNC_RESOURCES_ENV_MAGIC] = getattr(sys, "_MEIPASS", "")
|
|
|
|
from ffsubsync.ffsubsync import run, add_cli_only_args
|
|
|
|
from ffsubsync.version import get_version, update_available
|
2020-06-11 00:04:54 +08:00
|
|
|
|
|
|
|
logging.basicConfig(level=logging.INFO)
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
|
|
|
_menu = [
|
|
|
|
{
|
2022-01-24 12:07:52 +08:00
|
|
|
"name": "File",
|
|
|
|
"items": [
|
2020-06-11 00:04:54 +08:00
|
|
|
{
|
2022-01-24 12:07:52 +08:00
|
|
|
"type": "AboutDialog",
|
|
|
|
"menuTitle": "About",
|
|
|
|
"name": PROJECT_NAME,
|
|
|
|
"description": LONG_DESCRIPTION,
|
|
|
|
"version": get_version(),
|
|
|
|
"copyright": COPYRIGHT_YEAR,
|
|
|
|
"website": WEBSITE,
|
|
|
|
"developer": DEV_WEBSITE,
|
|
|
|
"license": PROJECT_LICENSE,
|
2020-06-11 00:04:54 +08:00
|
|
|
},
|
|
|
|
{
|
2022-01-24 12:07:52 +08:00
|
|
|
"type": "Link",
|
|
|
|
"menuTitle": "Download latest release",
|
|
|
|
"url": RELEASE_URL,
|
|
|
|
},
|
|
|
|
],
|
2020-06-11 00:04:54 +08:00
|
|
|
}
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
@Gooey(
|
|
|
|
program_name=PROJECT_NAME,
|
2022-01-24 12:07:52 +08:00
|
|
|
image_dir=os.path.join(os.environ[SUBSYNC_RESOURCES_ENV_MAGIC], "img"),
|
2020-06-11 00:04:54 +08:00
|
|
|
menu=_menu,
|
|
|
|
tabbed_groups=True,
|
|
|
|
progress_regex=r"(\d+)%",
|
2022-01-24 12:07:52 +08:00
|
|
|
hide_progress_msg=True,
|
2020-06-11 00:04:54 +08:00
|
|
|
)
|
|
|
|
def make_parser():
|
|
|
|
description = DESCRIPTION
|
|
|
|
if update_available():
|
|
|
|
description += '\nUpdate available! Please go to "File" -> "Download latest release" to update FFsubsync.'
|
|
|
|
parser = GooeyParser(description=description)
|
2022-01-24 12:07:52 +08:00
|
|
|
main_group = parser.add_argument_group("Basic")
|
|
|
|
main_group.add_argument(
|
|
|
|
"reference",
|
|
|
|
help="Reference (video or subtitles file) to which to synchronize input subtitles.",
|
|
|
|
widget="FileChooser",
|
|
|
|
)
|
|
|
|
main_group.add_argument("srtin", help="Input subtitles file", widget="FileChooser")
|
2020-06-11 00:04:54 +08:00
|
|
|
main_group.add_argument(
|
2022-01-24 12:07:52 +08:00
|
|
|
"-o",
|
|
|
|
"--srtout",
|
|
|
|
help="Output subtitles file (default=${srtin}.synced.srt).",
|
|
|
|
widget="FileSaver",
|
2020-06-11 00:04:54 +08:00
|
|
|
)
|
2022-01-24 12:07:52 +08:00
|
|
|
advanced_group = parser.add_argument_group("Advanced")
|
2020-06-11 00:04:54 +08:00
|
|
|
|
|
|
|
# TODO: these are shared between gui and cli; don't duplicate this code
|
|
|
|
advanced_group.add_argument(
|
2022-01-24 12:07:52 +08:00
|
|
|
"--merge-with-reference",
|
|
|
|
"--merge",
|
|
|
|
action="store_true",
|
|
|
|
help="Merge reference subtitles with synced output subtitles.",
|
|
|
|
)
|
|
|
|
advanced_group.add_argument(
|
|
|
|
"--make-test-case",
|
|
|
|
"--create-test-case",
|
|
|
|
action="store_true",
|
|
|
|
help="If specified, create a test archive a few KiB in size "
|
|
|
|
"to send to the developer as a debugging aid.",
|
|
|
|
)
|
|
|
|
advanced_group.add_argument(
|
|
|
|
"--reference-stream",
|
|
|
|
"--refstream",
|
|
|
|
"--reference-track",
|
|
|
|
"--reftrack",
|
|
|
|
default=None,
|
|
|
|
help="Which stream/track in the video file to use as reference, "
|
|
|
|
"formatted according to ffmpeg conventions. For example, s:0 "
|
|
|
|
"uses the first subtitle track; a:3 would use the fourth audio track.",
|
2020-06-11 00:04:54 +08:00
|
|
|
)
|
|
|
|
return parser
|
|
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
parser = make_parser()
|
|
|
|
_ = parser.parse_args() # Fool Gooey into presenting the simpler menu
|
|
|
|
add_cli_only_args(parser)
|
|
|
|
args = parser.parse_args()
|
|
|
|
args.gui_mode = True
|
|
|
|
return run(args)
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
sys.exit(main())
|