Skip to content

Instantly share code, notes, and snippets.

@werrpy
Last active March 1, 2020 00:49
Show Gist options
  • Save werrpy/02504a4abc7093769ed2380ed2d0cfc7 to your computer and use it in GitHub Desktop.
Save werrpy/02504a4abc7093769ed2380ed2d0cfc7 to your computer and use it in GitHub Desktop.
shitty names
import argparse, re, os
import torrent_parser as tp
def get_title(name):
# remove extension
title = os.path.splitext(name)[0]
# replace dots with spaces that are between:
# 1) letter and letter
# 2) number and letter
# 3) . 4 numbers (.year)
# 4) 4 numbers and 3 or 4 numbers followed by i or p (year and resolution, 2020.1080p)
# 5) S . 2 numbers . 3 or 4 numbers followed by i or p (season and resolution, S01.720p)
# 6) 2 letters . number . number (DD.2.0 or AAC.2.0 or DD+.2.0 or DTS-X.7.1)
# each of the cases is separated by a vertical bar | (aka "OR") in the regex
# letter here means any non-digit
title = re.sub(r"(?<=[\D])\.(?=[\D])|(?<=\d)\.(?=[\D])|\.(?=[\d]{4})|(?<=\d{4})\.(?=\d{3,4}[ip])|(?<=S\d{2})\.(?=\d{3,4}[ip])|(?<=[\D]{2})\.(?=\d\.\d)", " ", title)
# fixes:
title = title.replace("DTS-HDMA", "DTS-HD MA")
# make sure COMPLETE is all caps
title = re.sub("(?i)complete", "COMPLETE", title)
# TODO: add more?
return title
# setup script args
parser = argparse.ArgumentParser()
parser.add_argument("file", help="torrent file")
args = parser.parse_args()
# torrent bencode data
#data = tp.parse_torrent_file(args.file)
# filename from torrent
#name = data['info']['name']
name = args.file
# proper torrent title
title = get_title(name)
print(title)
@werrpy
Copy link
Author

werrpy commented Feb 29, 2020

python3 -m pip install torrent_parser

python3 shittynames.py file.torrent

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment