Skip to content

Commit

Permalink
new naming conventions
Browse files Browse the repository at this point in the history
  • Loading branch information
Tetrax-10 committed Dec 25, 2023
1 parent 1429156 commit 9932254
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 27 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ This python script removes all metadata from mp4 and mkv files and sets the titl

Need a website, tool, or script that you've always dreamed of having? contact me and I will create it for you.

[u/Raghavan_Rave10](https://www.reddit.com/user/Raghavan_Rave10) (or) Send friend request to `@tetrax10` on Discord, I will get in touch ASAP.
message me on reddit - [u/Raghavan_Rave10](https://www.reddit.com/user/Raghavan_Rave10) (or) Send friend request to `@tetrax10` on Discord, I will get in touch ASAP.

## Video file naming conventions:

1. Blade Runner 2049 2160p [2017]
2. Kill Bill: Vol. 1 720p [2003]
3. Titanic 1080p EXTENDED [1997]
4. Fall 1080p DC [2022]
5. Moby Dick 720p UNRATED [1998]
6. The Good, the Bad and the Ugly 1080p REMASTERED [1966]
3. Titanic EXTENDED 1080p [1997]
4. Fall DC 1080p [2022]
5. Moby Dick UNRATED 720p [1998]
6. The Good, the Bad and the Ugly REMASTERED 1080p [1966]

## Output:

Expand Down
Binary file modified assets/1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified assets/2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified assets/terminal.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
68 changes: 46 additions & 22 deletions script.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,44 @@
import os
import re
import sys
import subprocess
from pathlib import Path


def colored(text, color):
if color == "blue":
return f"\033[94m{text}\033[0m"
elif color == "green":
return f"\033[92m{text}\033[0m"
elif color == "red":
return f"\033[91m{text}\033[0m"


def run_cmd(cmd):
return subprocess.run(cmd, check=False, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True, shell=True)


def check(cmd):
output = run_cmd(cmd)
if ("not recognized" in output.stderr):

unavailable_tool = ""
if ("atomicParsley" in output.stderr):
unavailable_tool = "AtomicParsley"
else:
unavailable_tool = "mkvpropedit"

print(colored(f"{unavailable_tool} not found!", "red"))
print()
print(f"Please add \"{r"C:\Program Files\metadata-editor"}\" to PATH environmental variable")
print(colored("Tutorial: https://github.com/Tetrax-10/batch-metadata-editor?tab=readme-ov-file#installation", "blue"))
print()

return False

return True


def get_file_name(file, type="name"):
if type == "ext":
return Path(file).suffix[1:]
Expand Down Expand Up @@ -31,32 +66,21 @@ def get_all_video_files(path):


def extract_movie_info(filename):
pattern = re.compile(r'^(.+) (\d+p)(?: (\S+))? \[(\d{4})\]$')
pattern = re.compile(r'^(\S+(?:\s+\S+)*) (\d+p) \[(\d{4})\]$')
match = pattern.match(filename)

if match:
movie_name, resolution, version, year = match.groups()
version = version or ""

return [movie_name, resolution, version, year]
movie_name, movie_resolution, movie_year = match.groups()
return [movie_name, movie_resolution, movie_year]
else:
return False


def run_cmd(cmd):
return subprocess.run(cmd, check=False, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True, shell=True)


def colored(text, color):
if color == "blue":
return f"\033[94m{text}\033[0m"
elif color == "green":
return f"\033[92m{text}\033[0m"
elif color == "red":
return f"\033[91m{text}\033[0m"


if __name__ == "__main__":
print()
if not check("mkvpropedit --version") or not check("atomicParsley -v"):
sys.exit()

input_path = input(colored("Enter file or folder path: ", "blue"))
print()

Expand All @@ -68,15 +92,15 @@ def colored(text, color):
file_extension = get_file_name(video_file, "ext").lower()

movie_info = extract_movie_info(file_name)
if (movie_info != False and len(movie_info[0]) and len(movie_info[3])):
movie_name, movie_resolution, movie_version, movie_year = movie_info
if (movie_info != False and len(movie_info[0]) and len(movie_info[2])):
movie_name, movie_resolution, movie_year = movie_info

if (file_extension == "mkv"):
run_cmd(f"mkvpropedit \"{video_file}\" --tags all:") # removes all metadata
run_cmd(f"mkvpropedit \"{video_file}\" --edit info --set \"title={movie_name + (f" {movie_version}" if movie_version else "")}\" --set \"date={movie_year}-01-01T00:00:00+00:00\"")
run_cmd(f"mkvpropedit \"{video_file}\" --edit info --set \"title={movie_name + " " + f"[{movie_year}]"}\" --set \"date={movie_year}-01-01T00:00:00+00:00\"")
elif (file_extension == "mp4"):
run_cmd(f"AtomicParsley \"{video_file}\" --overWrite --metaEnema") # removes all metadata
run_cmd(f"AtomicParsley \"{video_file}\" --overWrite --title \"{movie_name + (f" {movie_version}" if movie_version else "")}\" --year {movie_year}")
run_cmd(f"AtomicParsley \"{video_file}\" --overWrite --title \"{movie_name + " " + f"[{movie_year}]"}\" --year {movie_year}")

print(colored(f"Done: {file_base_name}", "green"))
else:
Expand Down

0 comments on commit 9932254

Please sign in to comment.