Skip to content

Commit

Permalink
Release 0.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
donmai-me committed Jul 11, 2022
1 parent fce0716 commit ac87f18
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 63 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.3.0] - 2022-07-11
### Added
- Support for H.264 USM creation. Courtesy of [keikei14][https://github.com/keikei14]
- Command `createusm` also now takes m4v h264 files as input.

## [0.2.5] - 2022-04-08
### Added
- New operation in command-line called `encryptusm` which encrypts an existing USM file.
Expand Down
126 changes: 63 additions & 63 deletions wannacri/wannacri.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,69 @@
from .usm import is_usm, Usm, Vp9, H264, OpMode, generate_keys


def create_usm():
parser = argparse.ArgumentParser("WannaCRI Create USM", allow_abbrev=False)
parser.add_argument(
"operation",
metavar="operation",
type=str,
choices=OP_LIST,
help="Specify operation.",
)
parser.add_argument(
"input",
metavar="input file path",
type=existing_file,
help="Path to video file.",
)
parser.add_argument(
"-e",
"--encoding",
type=str,
default="shift-jis",
help="Character encoding used in creating USM. Defaults to shift-jis.",
)
parser.add_argument(
"-o",
"--output",
type=dir_path,
default=None,
help="Output path. Defaults to the same place as input.",
)
parser.add_argument(
"--ffprobe",
type=str,
default=".",
help="Path to ffprobe executable or directory. Defaults to CWD.",
)
parser.add_argument(
"-k", "--key", type=key, default=None, help="Encryption key for encrypted USMs."
)
args = parser.parse_args()

ffprobe_path = find_ffprobe(args.ffprobe)

# TODO: Add support for more video codecs and audio codecs
codec = Sofdec2Codec.from_file(args.input)
if codec is Sofdec2Codec.VP9:
video = Vp9(args.input, ffprobe_path=ffprobe_path)
elif codec is Sofdec2Codec.H264:
video = H264(args.input, ffprobe_path=ffprobe_path)
else:
raise NotImplementedError("Non-Vp9/H.264 files are not yet implemented.")

filename = os.path.splitext(args.input)[0]

usm = Usm(videos=[video], key=args.key)
with open(filename + ".usm", "wb") as f:
mode = OpMode.NONE if args.key is None else OpMode.ENCRYPT

for packet in usm.stream(mode, encoding=args.encoding):
f.write(packet)

print("Done creating USM file.")


def extract_usm():
"""One of the main functions in the command-line program. Extracts a USM or extracts
multiple USMs given a path as input."""
Expand Down Expand Up @@ -242,69 +305,6 @@ def probe_usm():
print(f'Probe complete. All logs are stored in "{args.output}" folder')


def create_usm():
parser = argparse.ArgumentParser("WannaCRI Create USM", allow_abbrev=False)
parser.add_argument(
"operation",
metavar="operation",
type=str,
choices=OP_LIST,
help="Specify operation.",
)
parser.add_argument(
"input",
metavar="input file path",
type=existing_file,
help="Path to video file.",
)
parser.add_argument(
"-e",
"--encoding",
type=str,
default="shift-jis",
help="Character encoding used in creating USM. Defaults to shift-jis.",
)
parser.add_argument(
"-o",
"--output",
type=dir_path,
default=None,
help="Output path. Defaults to the same place as input.",
)
parser.add_argument(
"--ffprobe",
type=str,
default=".",
help="Path to ffprobe executable or directory. Defaults to CWD.",
)
parser.add_argument(
"-k", "--key", type=key, default=None, help="Encryption key for encrypted USMs."
)
args = parser.parse_args()

ffprobe_path = find_ffprobe(args.ffprobe)

# TODO: Add support for more video codecs and audio codecs
codec = Sofdec2Codec.from_file(args.input)
if codec is Sofdec2Codec.VP9 or codec is Sofdec2Codec.H264:
if codec is Sofdec2Codec.VP9:
video = Vp9(args.input, ffprobe_path=ffprobe_path)
elif codec is Sofdec2Codec.H264:
video = H264(args.input, ffprobe_path=ffprobe_path)
filename = os.path.splitext(args.input)[0]

usm = Usm(videos=[video], key=args.key)
with open(filename + ".usm", "wb") as f:
mode = OpMode.NONE if args.key is None else OpMode.ENCRYPT

for packet in usm.stream(mode, encoding=args.encoding):
f.write(packet)
else:
raise NotImplementedError("Non-Vp9/H.264 files are not yet implemented.")

print("Done creating USM file.")


def encrypt_usm():
parser = argparse.ArgumentParser("WannaCRI Encrypt USM/s", allow_abbrev=False)
parser.add_argument(
Expand Down

0 comments on commit ac87f18

Please sign in to comment.