Restructure project

This commit is contained in:
Augusto Gunsch 2021-11-14 18:06:21 -03:00
parent 7120d76aad
commit cb142d3e30
No known key found for this signature in database
GPG Key ID: F7EEFE29825C72DC
7 changed files with 108 additions and 54 deletions

3
.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
dist/
*.egg-info/
__pycache__/

View File

@ -1,6 +1,12 @@
# fsub
`fsub` is a Python script for cleaning, editing and fixing a SubRip (.srt) file
# Installation
Through Python's pip:
```
pip install fsub
```
# Usage
```
usage: fsub [-h] [-c] [-s MS] [-n] [-f FILE] file [file ...]

6
build.sh Executable file
View File

@ -0,0 +1,6 @@
#!/bin/sh
rm -rv dist
python3 -m build
# Upload to PyPI with:
# python3 -m twine upload --repository pypi dist/*

6
pyproject.toml Normal file
View File

@ -0,0 +1,6 @@
[build-system]
requires = [
"setuptools>=42",
"wheel"
]
build-backend = "setuptools.build_meta"

28
setup.cfg Normal file
View File

@ -0,0 +1,28 @@
[metadata]
name = fsub
version = 0.0.1
author = Augusto Lenz Gunsch
author_email = augustogunsch@tutanota.com
description = CLI SubRip editor
long_description = file: README.md
long_description_content_type = text/markdown
url = https://github.com/augustogunsch/fsub
project_urls =
Bug Tracker = https://github.com/augustogunsch/fsub/issues
classifiers =
Programming Language :: Python :: 3
License :: OSI Approved :: GNU General Public License v3 (GPLv3)
Operating System :: OS Independent
[options]
package_dir =
= src
packages = find:
python_requires = >=3.9
[options.packages.find]
where = src
[options.entry_points]
console_scripts =
fsub = fsub.fsub:main

0
src/fsub/__init__.py Normal file
View File

View File

@ -188,67 +188,72 @@ def process_file(args, file):
output.write(os.linesep)
parser = argparse.ArgumentParser(
description='Fix, edit and clean SubRip (.srt) files.',
add_help=True
)
def main():
parser = argparse.ArgumentParser(
description='Fix, edit and clean SubRip (.srt) files.',
add_help=True
)
parser.add_argument(
'-c', '--clean',
help='removes subtitles matching regular expressions ' +
'listed in ~/.config/fsubrc (this is the default ' +
'behavior if no other flag is passed)',
action='store_true'
)
parser.add_argument(
'-c', '--clean',
help='removes subtitles matching regular expressions ' +
'listed in ~/.config/fsubrc (this is the default ' +
'behavior if no other flag is passed)',
action='store_true'
)
parser.add_argument(
'-s', '--shift',
help='shifts all subtitles by MS milliseconds, which ' +
'may be positive or negative',
metavar='MS',
action='store',
type=int
)
parser.add_argument(
'-s', '--shift',
help='shifts all subtitles by MS milliseconds, which ' +
'may be positive or negative',
metavar='MS',
action='store',
type=int
)
parser.add_argument(
'-n', '--no-html',
help='strips HTML tags from subtitles content',
action='store_true'
)
parser.add_argument(
'-n', '--no-html',
help='strips HTML tags from subtitles content',
action='store_true'
)
parser.add_argument(
'-f', '--config-file',
help='overwrites the default config file (~/.config/fsubrc)',
metavar='FILE',
action='store',
type=argparse.FileType('r')
)
parser.add_argument(
'-f', '--config-file',
help='overwrites the default config file (~/.config/fsubrc)',
metavar='FILE',
action='store',
type=argparse.FileType('r')
)
parser.add_argument(
'files',
help='list of input files (they all must be SubRip files)',
metavar='file',
type=argparse.FileType('rb+'),
nargs='+'
)
parser.add_argument(
'files',
help='list of input files (they all must be SubRip files)',
metavar='file',
type=argparse.FileType('rb+'),
nargs='+'
)
args = parser.parse_args()
args = parser.parse_args()
# Make sure --clean is the default
if not args.shift and not args.no_html:
args.clean = True
# Make sure --clean is the default
if not args.shift and not args.no_html:
args.clean = True
# Validate options
if not args.clean and args.config_file:
print('-f requires -c', file=sys.stderr)
exit(1)
# Validate options
if not args.clean and args.config_file:
print('-f requires -c', file=sys.stderr)
exit(1)
# Check if all files are .srt
for file in args.files:
if file.name[-4:] != '.srt':
print('File {} is not a SubRip file'.format(file.name),
file=sys.stderr)
sys.exit(1)
# Check if all files are .srt
for file in args.files:
if file.name[-4:] != '.srt':
print('File {} is not a SubRip file'.format(file.name),
file=sys.stderr)
sys.exit(1)
for file in args.files:
process_file(args, file)
for file in args.files:
process_file(args, file)
if __name__ == '__main__':
main()