diff --git a/README.md b/README.md index 75b61fc..e147f79 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,5 @@ # pymplschapters + Extract chapters from a blu-ray mpls to a matroska recognized xml file ## Installation @@ -9,7 +10,7 @@ Extract chapters from a blu-ray mpls to a matroska recognized xml file pymplschapters -p "C:/A Path/To/The/Playlist.mpls" -It will place any found chapters next to the input playlist file. +It will place any found chapters next to the input playlist file or to a specified directory with `-d`. ## Credit diff --git a/package-and-deploy.sh b/package-and-deploy.sh new file mode 100755 index 0000000..66b9a66 --- /dev/null +++ b/package-and-deploy.sh @@ -0,0 +1,5 @@ +rm -r build +rm -r dist +rm -r "pyd2v.egg-info" +python3 setup.py sdist bdist_wheel +python3 -m twine upload dist/* \ No newline at end of file diff --git a/package-and-install.sh b/package-and-install.sh new file mode 100755 index 0000000..ca4c953 --- /dev/null +++ b/package-and-install.sh @@ -0,0 +1,5 @@ +rm -r build +rm -r dist +rm -r "pyd2v.egg-info" +python3 setup.py sdist bdist_wheel +sudo pip install . \ No newline at end of file diff --git a/pymplschapters/__init__.py b/pymplschapters/__init__.py index 06cb5d6..0e0a842 100644 --- a/pymplschapters/__init__.py +++ b/pymplschapters/__init__.py @@ -11,23 +11,33 @@ # -------------------------------- def main(): ArgParser = argparse.ArgumentParser() - ArgParser.add_argument('-p', '--playlist', help='Input path to an MPLS playlist', required=True) + ArgParser.add_argument( + "-p", "--playlist", help="Input path to an MPLS playlist", required=True + ) + ArgParser.add_argument( + "-d", + "--directory", + help="Specify an output directory, by default it will save next to the playlist.", + required=False + ) args = ArgParser.parse_args() def get_chapters(mpls): header, _ = MPLS.load_header(mpls) - mpls.seek(header['PlayListStartAddress'], os.SEEK_SET) + mpls.seek(header["PlayListStartAddress"], os.SEEK_SET) pl, _ = MPLS.load_PlayList(mpls) - pl = pl['PlayItems'] + pl = pl["PlayItems"] - mpls.seek(header['PlayListMarkStartAddress'], os.SEEK_SET) + mpls.seek(header["PlayListMarkStartAddress"], os.SEEK_SET) marks, _ = MPLS.load_PlayListMark(mpls) marks = marks["PlayListMarks"] for i, playItem in enumerate(pl): chapters = [] - playItemMarks = [x for x in marks if x["MarkType"] == 1 and x["RefToPlayItemID"] == i] + playItemMarks = [ + x for x in marks if x["MarkType"] == 1 and x["RefToPlayItemID"] == i + ] offset = playItemMarks[0]["MarkTimeStamp"] if playItem["INTime"] < offset: offset = playItem["INTime"] @@ -35,14 +45,14 @@ def get_chapters(mpls): duration = ((mark["MarkTimeStamp"] - offset) / 45000) * 1000 timespan = str(datetime.timedelta(milliseconds=duration)) if timespan == "0:00:00": - timespan = timespan + ".000000" + timespan = f"{timespan}.000000" if timespan.startswith("0:"): - timespan = "0" + timespan + timespan = f"0{timespan}" chapters.append({ - "clip": playItem["ClipInformationFileName"] + "." + playItem["ClipCodecIdentifier"].lower(), - "number": n+1, + "clip": f"{playItem['ClipInformationFileName']}.{playItem['ClipCodecIdentifier'].lower()}", + "number": n + 1, "duration": duration, - "timespan": timespan + "timespan": timespan, }) yield chapters @@ -61,7 +71,7 @@ def get_chapters(mpls): ChapterAtom = etree.SubElement(EditionEntry, "ChapterAtom") ChapterDisplay = etree.SubElement(ChapterAtom, "ChapterDisplay") ChapterString = etree.SubElement(ChapterDisplay, "ChapterString") - ChapterString.text = "Chapter " + str(chapter["number"]).zfill(2) + ChapterString.text = f"Chapter {str(chapter['number']).zfill(2)}" ChapterLanguage = etree.SubElement(ChapterDisplay, "ChapterLanguage") ChapterLanguage.text = "eng" ChapterTimeStart = etree.SubElement(ChapterAtom, "ChapterTimeStart") @@ -71,7 +81,18 @@ def get_chapters(mpls): ChapterFlagEnabled = etree.SubElement(ChapterAtom, "ChapterFlagEnabled") ChapterFlagEnabled.text = "1" clip = file_with_chapter[0]["clip"] - with open(os.path.join(os.path.dirname(args.playlist), os.path.splitext(os.path.basename(args.playlist))[0] + "_" + clip.split('.')[0] + ".xml"), 'wb') as f: - f.write(etree.tostring(Chapters, encoding='utf-8', doctype="", xml_declaration=True, pretty_print=True)) + with open(os.path.join( + args.directory or os.path.dirname(args.playlist), + f"{os.path.splitext(os.path.basename(args.playlist))[0]}_{clip.split('.')[0]}.xml" + ), "wb") as f: + f.write( + etree.tostring( + Chapters, + encoding="utf-8", + doctype='', + xml_declaration=True, + pretty_print=True, + ) + ) print("Extracted chapters for " + clip) print("Finished...") diff --git a/setup.py b/setup.py index 7abea18..2fdf45b 100644 --- a/setup.py +++ b/setup.py @@ -5,23 +5,19 @@ setup( name="pymplschapters", - version="1.0.2", - author="PRAGMA", - author_email="pragma.exe@gmail.com", + version="1.0.4", + author="PHOENiX", + author_email="rlaphoenix@pm.me", description="Extract chapters from a blu-ray mpls to a matroska recognized xml file", - license='MIT', + license="MIT", long_description=readme, long_description_content_type="text/markdown", - url="https://github.com/imPRAGMA/pymplschapters", + url="https://github.com/rlaPHOENiX/pymplschapters", packages=find_packages(), - install_requires=[ - 'lxml>=4.4.1' - ], - entry_points={ - 'console_scripts': ['pymplschapters=pymplschapters.__init__:main'], - }, + install_requires=["lxml>=4.4.1"], + entry_points={"console_scripts": ["pymplschapters=pymplschapters.__init__:main"]}, classifiers=[ "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", - ] + ], )