Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some updates and fixes #319

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Wrapping some regex pattern in raw string literal
  • Loading branch information
sirius-sama committed Mar 2, 2024
commit 289debbf9a2f0003b863ac0a5421ee3f75264373
31 changes: 15 additions & 16 deletions src/prep.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,15 +97,15 @@ async def gather_prep(self, meta, mode):
meta['filelist'] = []
try:
guess_name = bdinfo['title'].replace('-',' ')
filename = guessit(re.sub("[^0-9a-zA-Z\[\]]+", " ", guess_name), {"excludes" : ["country", "language"]})['title']
filename = guessit(re.sub(r"[^0-9a-zA-Z\[\]]+", " ", guess_name), {"excludes" : ["country", "language"]})['title']
untouched_filename = bdinfo['title']
try:
meta['search_year'] = guessit(bdinfo['title'])['year']
except Exception:
meta['search_year'] = ""
except Exception:
guess_name = bdinfo['label'].replace('-',' ')
filename = guessit(re.sub("[^0-9a-zA-Z\[\]]+", " ", guess_name), {"excludes" : ["country", "language"]})['title']
filename = guessit(re.sub(r"[^0-9a-zA-Z\[\]]+", " ", guess_name), {"excludes" : ["country", "language"]})['title']
untouched_filename = bdinfo['label']
try:
meta['search_year'] = guessit(bdinfo['label'])['year']
Expand Down Expand Up @@ -164,7 +164,7 @@ async def gather_prep(self, meta, mode):
videopath, meta['filelist'] = self.get_video(videoloc, meta.get('mode', 'discord'))
video, meta['scene'], meta['imdb'] = self.is_scene(videopath, meta.get('imdb', None))
guess_name = ntpath.basename(video).replace('-',' ')
filename = guessit(re.sub("[^0-9a-zA-Z\[\]]+", " ", guess_name), {"excludes" : ["country", "language"]}).get("title", guessit(re.sub("[^0-9a-zA-Z]+", " ", guess_name), {"excludes" : ["country", "language"]})["title"])
filename = guessit(re.sub(r"[^0-9a-zA-Z\[\]]+", " ", guess_name), {"excludes" : ["country", "language"]}).get("title", guessit(re.sub(r"[^0-9a-zA-Z]+", " ", guess_name), {"excludes" : ["country", "language"]})["title"])
untouched_filename = os.path.basename(video)
try:
meta['search_year'] = guessit(video)['year']
Expand Down Expand Up @@ -359,8 +359,8 @@ async def gather_prep(self, meta, mode):

meta['edition'], meta['repack'] = self.get_edition(meta['path'], bdinfo, meta['filelist'], meta.get('manual_edition'))
if "REPACK" in meta.get('edition', ""):
meta['repack'] = re.search("REPACK[\d]?", meta['edition'])[0]
meta['edition'] = re.sub("REPACK[\d]?", "", meta['edition']).strip().replace(' ', ' ')
meta['repack'] = re.search(r"REPACK[\d]?", meta['edition'])[0]
meta['edition'] = re.sub(r"REPACK[\d]?", "", meta['edition']).strip().replace(' ', ' ')



Expand Down Expand Up @@ -1369,7 +1369,7 @@ def get_romaji(self, tmdb_name, mal):
result = {'title' : {}}
difference = 0
for anime in media:
search_name = re.sub("[^0-9a-zA-Z\[\]]+", "", tmdb_name.lower().replace(' ', ''))
search_name = re.sub(r"[^0-9a-zA-Z\[\]]+", "", tmdb_name.lower().replace(' ', ''))
for title in anime['title'].values():
if title != None:
title = re.sub(u'[\u3000-\u303f\u3040-\u309f\u30a0-\u30ff\uff00-\uff9f\u4e00-\u9faf\u3400-\u4dbf]+ (?=[A-Za-z ]+–)', "", title.lower().replace(' ', ''), re.U)
Expand Down Expand Up @@ -1906,7 +1906,7 @@ def get_edition(self, video, bdinfo, filelist, manual_edition):
repack = "RERIP"
# if "HYBRID" in video.upper() and "HYBRID" not in title.upper():
# edition = "Hybrid " + edition
edition = re.sub("(REPACK\d?)?(RERIP)?(PROPER)?", "", edition, flags=re.IGNORECASE).strip()
edition = re.sub(r"(REPACK\d?)?(RERIP)?(PROPER)?", "", edition, flags=re.IGNORECASE).strip()
bad = ['internal', 'limited', 'retail']

if edition.lower() in bad:
Expand Down Expand Up @@ -2010,7 +2010,7 @@ def torf_cb(self, torrent, filepath, pieces_done, pieces_total):
cli_ui.info_progress("Hashing...", pieces_done, pieces_total)

def create_random_torrents(self, base_dir, uuid, num, path):
manual_name = re.sub("[^0-9a-zA-Z\[\]\'\-]+", ".", os.path.basename(path))
manual_name = re.sub(r"[^0-9a-zA-Z\[\]\'\-]+", ".", os.path.basename(path))
base_torrent = Torrent.read(f"{base_dir}/tmp/{uuid}/BASE.torrent")
for i in range(1, int(num) + 1):
new_torrent = base_torrent
Expand All @@ -2020,7 +2020,6 @@ def create_random_torrents(self, base_dir, uuid, num, path):
def create_base_from_existing_torrent(self, torrentpath, base_dir, uuid):
if os.path.exists(torrentpath):
base_torrent = Torrent.read(torrentpath)
base_torrent.creation_date = datetime.now()
base_torrent.trackers = ['https://fake.tracker']
base_torrent.comment = "Created by L4G's Upload Assistant"
base_torrent.created_by = "Created by L4G's Upload Assistant"
Expand Down Expand Up @@ -2491,8 +2490,8 @@ async def get_season_episode(self, video, meta):
for lang, names in values.items():
if lang == "jp":
for name in names:
romaji_check = re.sub("[^0-9a-zA-Z\[\]]+", "", romaji.lower().replace(' ', ''))
name_check = re.sub("[^0-9a-zA-Z\[\]]+", "", name.lower().replace(' ', ''))
romaji_check = re.sub(r"[^0-9a-zA-Z\[\]]+", "", romaji.lower().replace(' ', ''))
name_check = re.sub(r"[^0-9a-zA-Z\[\]]+", "", name.lower().replace(' ', ''))
diff = SequenceMatcher(None, romaji_check, name_check).ratio()
if romaji_check in name_check:
if diff >= difference:
Expand All @@ -2505,8 +2504,8 @@ async def get_season_episode(self, video, meta):
difference = diff
if lang == "us":
for name in names:
eng_check = re.sub("[^0-9a-zA-Z\[\]]+", "", eng_title.lower().replace(' ', ''))
name_check = re.sub("[^0-9a-zA-Z\[\]]+", "", name.lower().replace(' ', ''))
eng_check = re.sub(r"[^0-9a-zA-Z\[\]]+", "", eng_title.lower().replace(' ', ''))
name_check = re.sub(r"[^0-9a-zA-Z\[\]]+", "", name.lower().replace(' ', ''))
diff = SequenceMatcher(None, eng_check, name_check).ratio()
if eng_check in name_check:
if diff >= difference:
Expand Down Expand Up @@ -2623,7 +2622,7 @@ def get_service(self, video, tag, audio, guess_title):
}


video_name = re.sub("[.()]", " ", video.replace(tag, '').replace(guess_title, ''))
video_name = re.sub(r"[.()]", " ", video.replace(tag, '').replace(guess_title, ''))
if "DTS-HD MA" in audio:
video_name = video_name.replace("DTS-HD.MA.", "").replace("DTS-HD MA ", "")
for key, value in services.items():
Expand Down Expand Up @@ -2827,7 +2826,7 @@ async def package(self, meta):
generic.write(f"\nThumbnail Image:\n")
for each in meta['image_list']:
generic.write(f"{each['img_url']}\n")
title = re.sub("[^0-9a-zA-Z\[\]]+", "", meta['title'])
title = re.sub(r"[^0-9a-zA-Z\[\]]+", "", meta['title'])
archive = f"{meta['base_dir']}/tmp/{meta['uuid']}/{title}"
torrent_files = glob.glob1(f"{meta['base_dir']}/tmp/{meta['uuid']}","*.torrent")
if isinstance(torrent_files, list) and len(torrent_files) > 1:
Expand All @@ -2837,7 +2836,7 @@ async def package(self, meta):
try:
if os.path.exists(f"{meta['base_dir']}/tmp/{meta['uuid']}/BASE.torrent"):
base_torrent = Torrent.read(f"{meta['base_dir']}/tmp/{meta['uuid']}/BASE.torrent")
manual_name = re.sub("[^0-9a-zA-Z\[\]\'\-]+", ".", os.path.basename(meta['path']))
manual_name = re.sub(r"[^0-9a-zA-Z\[\]\'\-]+", ".", os.path.basename(meta['path']))
Torrent.copy(base_torrent).write(f"{meta['base_dir']}/tmp/{meta['uuid']}/{manual_name}.torrent", overwrite=True)
# shutil.copy(os.path.abspath(f"{meta['base_dir']}/tmp/{meta['uuid']}/BASE.torrent"), os.path.abspath(f"{meta['base_dir']}/tmp/{meta['uuid']}/{meta['name'].replace(' ', '.')}.torrent").replace(' ', '.'))
filebrowser = self.config['TRACKERS'].get('MANUAL', {}).get('filebrowser', None)
Expand Down
4 changes: 2 additions & 2 deletions src/trackers/FL.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ async def edit_name(self, meta):
fl_name = fl_name.replace('DTS7.1', 'DTS').replace('DTS5.1', 'DTS').replace('DTS2.0', 'DTS').replace('DTS1.0', 'DTS')
fl_name = fl_name.replace('Dubbed', '').replace('Dual-Audio', '')
fl_name = ' '.join(fl_name.split())
fl_name = re.sub("[^0-9a-zA-ZÀ-ÿ. &+'\-\[\]]+", "", fl_name)
fl_name = re.sub(r"[^0-9a-zA-ZÀ-ÿ. &+'\-\[\]]+", "", fl_name)
fl_name = fl_name.replace(' ', '.').replace('..', '.')
return fl_name

Expand Down Expand Up @@ -319,7 +319,7 @@ async def edit_desc(self, meta):
desc = bbcode.convert_code_to_quote(desc)
desc = bbcode.convert_comparison_to_centered(desc, 900)
desc = desc.replace('[img]', '[img]').replace('[/img]', '[/img]')
desc = re.sub("(\[img=\d+)]", "[img]", desc, flags=re.IGNORECASE)
desc = re.sub(r"(\[img=\d+)]", "[img]", desc, flags=re.IGNORECASE)
if meta['is_disc'] != 'BDMV':
url = "https://up.img4k.net/api/description"
data = {
Expand Down
4 changes: 2 additions & 2 deletions src/trackers/HDB.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ async def edit_name(self, meta):
hdb_name = hdb_name.replace('Dubbed', '').replace('Dual-Audio', '')
hdb_name = hdb_name.replace('REMUX', 'Remux')
hdb_name = ' '.join(hdb_name.split())
hdb_name = re.sub("[^0-9a-zA-ZÀ-ÿ. :&+'\-\[\]]+", "", hdb_name)
hdb_name = re.sub(r"[^0-9a-zA-ZÀ-ÿ. :&+'\-\[\]]+", "", hdb_name)
hdb_name = hdb_name.replace(' .', '.').replace('..', '.')

return hdb_name
Expand Down Expand Up @@ -431,7 +431,7 @@ async def edit_desc(self, meta):
desc = bbcode.convert_code_to_quote(desc)
desc = bbcode.convert_spoiler_to_hide(desc)
desc = bbcode.convert_comparison_to_centered(desc, 1000)
desc = re.sub("(\[img=\d+)]", "[img]", desc, flags=re.IGNORECASE)
desc = re.sub(r"(\[img=\d+)]", "[img]", desc, flags=re.IGNORECASE)
descfile.write(desc)
if self.rehost_images == True:
console.print("[green]Rehosting Images...")
Expand Down
2 changes: 1 addition & 1 deletion src/trackers/HDT.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ async def edit_name(self, meta):
hdt_name = hdt_name.replace(' DV ', ' DoVi ')

hdt_name = ' '.join(hdt_name.split())
hdt_name = re.sub("[^0-9a-zA-ZÀ-ÿ. &+'\-\[\]]+", "", hdt_name)
hdt_name = re.sub(r"[^0-9a-zA-ZÀ-ÿ. &+'\-\[\]]+", "", hdt_name)
hdt_name = hdt_name.replace(':', '').replace('..', ' ').replace(' ', ' ')
return hdt_name

Expand Down
2 changes: 1 addition & 1 deletion src/trackers/MTV.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ async def edit_name(self, meta):
if meta['tag'] == "":
mtv_name = f"{mtv_name}-NoGrp"
mtv_name = ' '.join(mtv_name.split())
mtv_name = re.sub("[^0-9a-zA-ZÀ-ÿ. &+'\-\[\]]+", "", mtv_name)
mtv_name = re.sub(r"[^0-9a-zA-ZÀ-ÿ. &+'\-\[\]]+", "", mtv_name)
mtv_name = mtv_name.replace(' ', '.').replace('..', '.')
return mtv_name

Expand Down
2 changes: 1 addition & 1 deletion src/trackers/PTER.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ async def edit_desc(self, meta):
desc = bbcode.convert_spoiler_to_hide(desc)
desc = bbcode.convert_comparison_to_centered(desc, 1000)
desc = desc.replace('[img]', '[img]')
desc = re.sub("(\[img=\d+)]", "[img]", desc, flags=re.IGNORECASE)
desc = re.sub(r"(\[img=\d+)]", "[img]", desc, flags=re.IGNORECASE)
descfile.write(desc)

if self.rehost_images == True:
Expand Down
2 changes: 1 addition & 1 deletion src/trackers/RTF.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ async def upload(self, meta):
# 'description' : meta['overview'] + "\n\n" + desc + "\n\n" + "Uploaded by L4G Upload Assistant",
'description': "this is a description",
# editing mediainfo so that instead of 1 080p its 1,080p as site mediainfo parser wont work other wise.
'mediaInfo': re.sub("(\d+)\s+(\d+)", r"\1,\2", mi_dump) if bd_dump == None else f"{bd_dump}",
'mediaInfo': re.sub(r"(\d+)\s+(\d+)", r"\1,\2", mi_dump) if bd_dump == None else f"{bd_dump}",
"nfo": "",
"url": "https://www.imdb.com/title/" + (meta['imdb_id'] if str(meta['imdb_id']).startswith("tt") else "tt" + meta['imdb_id']) + "/",
# auto pulled from IMDB
Expand Down
2 changes: 1 addition & 1 deletion src/trackers/THR.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ async def upload(self, session, meta):
return
else:
thr_name = thr_name_manually
torrent_name = re.sub("[^0-9a-zA-Z. '\-\[\]]+", " ", thr_name)
torrent_name = re.sub(r"[^0-9a-zA-Z. '\-\[\]]+", " ", thr_name)


if meta.get('is_disc', '') == 'BDMV':
Expand Down
2 changes: 1 addition & 1 deletion src/trackers/TTG.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ async def edit_desc(self, meta):
desc = bbcode.convert_spoiler_to_hide(desc)
desc = bbcode.convert_comparison_to_centered(desc, 1000)
desc = desc.replace('[img]', '[img]')
desc = re.sub("(\[img=\d+)]", "[img]", desc, flags=re.IGNORECASE)
desc = re.sub(r"(\[img=\d+)]", "[img]", desc, flags=re.IGNORECASE)
descfile.write(desc)
images = meta['image_list']
if len(images) > 0:
Expand Down