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 all commits
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
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ beautifulsoup4
pyoxipng
rich
Jinja2
pyotp
pyotp
str2bool
35 changes: 17 additions & 18 deletions src/prep.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
import re
import math
import sys
import distutils.util
import asyncio
from str2bool import str2bool
from guessit import guessit
import ntpath
from pathlib import Path
Expand Down 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 @@ -2772,7 +2771,7 @@ async def tag_override(self, meta):
else:
pass
elif key == 'personalrelease':
meta[key] = bool(distutils.util.strtobool(str(value.get(key, 'False'))))
meta[key] = bool(str2bool(str(value.get(key, 'False'))))
elif key == 'template':
meta['desc_template'] = value.get(key)
else:
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/ACM.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
# import discord
import asyncio
import requests
import distutils.util
import os
import platform
from str2bool import str2bool
from src.trackers.COMMON import COMMON
from src.console import console

Expand Down Expand Up @@ -207,7 +207,7 @@ async def upload(self, meta):
region_id = await common.unit3d_region_ids(meta.get('region'))
distributor_id = await common.unit3d_distributor_ids(meta.get('distributor'))
acm_name = await self.edit_name(meta)
if meta['anon'] == 0 and bool(distutils.util.strtobool(str(self.config['TRACKERS'][self.tracker].get('anon', "False")))) == False:
if meta['anon'] == 0 and bool(str2bool(str(self.config['TRACKERS'][self.tracker].get('anon', "False")))) == False:
anon = 0
else:
anon = 1
Expand Down
4 changes: 2 additions & 2 deletions src/trackers/AITHER.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import asyncio
import requests
from difflib import SequenceMatcher
import distutils.util
from str2bool import str2bool
import json
import os
import platform
Expand Down Expand Up @@ -37,7 +37,7 @@ async def upload(self, meta):
type_id = await self.get_type_id(meta['type'])
resolution_id = await self.get_res_id(meta['resolution'])
name = await self.edit_name(meta)
if meta['anon'] == 0 and bool(distutils.util.strtobool(str(self.config['TRACKERS'][self.tracker].get('anon', "False")))) == False:
if meta['anon'] == 0 and bool(str2bool(str(self.config['TRACKERS'][self.tracker].get('anon', "False")))) == False:
anon = 0
else:
anon = 1
Expand Down
4 changes: 2 additions & 2 deletions src/trackers/ANT.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import os
import asyncio
import requests
import distutils.util
import platform
from str2bool import str2bool
from pymediainfo import MediaInfo

from src.trackers.COMMON import COMMON
Expand Down Expand Up @@ -68,7 +68,7 @@ async def upload(self, meta):
common = COMMON(config=self.config)
await common.edit_torrent(meta, self.tracker, self.source_flag)
flags = await self.get_flags(meta)
if meta['anon'] == 0 and bool(distutils.util.strtobool(str(self.config['TRACKERS'][self.tracker].get('anon', "False")))) is False:
if meta['anon'] == 0 and bool(str2bool(str(self.config['TRACKERS'][self.tracker].get('anon', "False")))) is False:
anon = 0
else:
anon = 1
Expand Down
6 changes: 3 additions & 3 deletions src/trackers/BHD.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import asyncio
import requests
from difflib import SequenceMatcher
import distutils.util
from str2bool import str2bool
import urllib
import os
import platform
Expand Down Expand Up @@ -39,7 +39,7 @@ async def upload(self, meta):
tags = await self.get_tags(meta)
custom, edition = await self.get_edition(meta, tags)
bhd_name = await self.edit_name(meta)
if meta['anon'] == 0 and bool(distutils.util.strtobool(str(self.config['TRACKERS'][self.tracker].get('anon', "False")))) == False:
if meta['anon'] == 0 and bool(str2bool(str(self.config['TRACKERS'][self.tracker].get('anon', "False")))) == False:
anon = 0
else:
anon = 1
Expand Down Expand Up @@ -263,7 +263,7 @@ async def search_existing(self, meta):

async def get_live(self, meta):
draft = self.config['TRACKERS'][self.tracker]['draft_default'].strip()
draft = bool(distutils.util.strtobool(str(draft))) #0 for send to draft, 1 for live
draft = bool(str2bool(str(draft))) #0 for send to draft, 1 for live
if draft:
draft_int = 0
else:
Expand Down
4 changes: 2 additions & 2 deletions src/trackers/BHDTV.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from torf import Torrent
import requests
from src.console import console
import distutils.util
from str2bool import str2bool
from pprint import pprint
import os
import traceback
Expand Down Expand Up @@ -54,7 +54,7 @@ async def upload(self, meta):
# region_id = await common.unit3d_region_ids(meta.get('region'))
# distributor_id = await common.unit3d_distributor_ids(meta.get('distributor'))
if meta['anon'] == 0 and bool(
distutils.util.strtobool(self.config['TRACKERS'][self.tracker].get('anon', "False"))) == False:
str2bool(self.config['TRACKERS'][self.tracker].get('anon', "False"))) == False:
anon = 0
else:
anon = 1
Expand Down
6 changes: 3 additions & 3 deletions src/trackers/BLU.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
# import discord
import asyncio
import requests
import distutils.util
import os
import platform
from str2bool import str2bool

from src.trackers.COMMON import COMMON
from src.console import console
Expand All @@ -26,7 +26,7 @@ def __init__(self, config):
self.upload_url = 'https://blutopia.cc/api/torrents/upload'
self.signature = f"\n[center][url=https://blutopia.cc/forums/topics/3087]Created by L4G's Upload Assistant[/url][/center]"
self.banned_groups = [
'[Oj]', '3LTON', '4yEo', 'AFG', 'AniHLS', 'AnimeRG', 'AniURL', 'AROMA', 'aXXo', 'Brrip', 'CM8', 'CrEwSaDe', 'd3g', 'DeadFish', 'DNL', 'ELiTE', 'eSc', 'FaNGDiNG0', 'FGT', 'Flights',
'[Oj]', '3LTON', '4yEo', 'AFG', 'AniHLS', 'AnimeRG', 'AniURL', 'AROMA', 'aXXo', 'Brrip', 'CHD', 'CM8', 'CrEwSaDe', 'd3g', 'DeadFish', 'DNL', 'ELiTE', 'eSc', 'FaNGDiNG0', 'FGT', 'Flights',
'FRDS', 'FUM', 'HAiKU', 'HD2DVD', 'HDS', 'HDTime', 'Hi10', 'ION10', 'iPlanet', 'JIVE', 'KiNGDOM', 'Leffe', 'LEGi0N', 'LOAD', 'MeGusta', 'mHD', 'mSD', 'NhaNc3', 'nHD', 'nikt0', 'NOIVTC',
'nSD', 'PiRaTeS', 'playBD', 'PlaySD', 'playXD', 'PRODJi', 'RAPiDCOWS', 'RARBG', 'RDN', 'REsuRRecTioN', 'RMTeam', 'SANTi', 'SicFoI', 'SPASM', 'STUTTERSHIT', 'Telly', 'TM', 'TRiToN', 'UPiNSMOKE',
'URANiME', 'WAF', 'x0r', 'xRed', 'XS', 'YIFY', 'ZKBL', 'ZmN', 'ZMNT',
Expand All @@ -49,7 +49,7 @@ async def upload(self, meta):
resolution_id = await self.get_res_id(meta['resolution'])
region_id = await common.unit3d_region_ids(meta.get('region'))
distributor_id = await common.unit3d_distributor_ids(meta.get('distributor'))
if meta['anon'] == 0 and bool(distutils.util.strtobool(str(self.config['TRACKERS'][self.tracker].get('anon', "False")))) == False:
if meta['anon'] == 0 and bool(str2bool(str(self.config['TRACKERS'][self.tracker].get('anon', "False")))) == False:
anon = 0
else:
anon = 1
Expand Down
8 changes: 4 additions & 4 deletions src/trackers/FL.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import re
import os
from pathlib import Path
import distutils.util
from str2bool import str2bool
import json
import glob
import pickle
Expand Down 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 @@ -161,7 +161,7 @@ async def upload(self, meta):
if int(meta.get('imdb_id', '').replace('tt', '')) != 0:
data['imdbid'] = meta.get('imdb_id', '').replace('tt', '')
data['description'] = meta['imdb_info'].get('genres', '')
if self.uploader_name not in ("", None) and bool(distutils.util.strtobool(str(self.config['TRACKERS'][self.tracker].get('anon', "False")))) == False:
if self.uploader_name not in ("", None) and bool(str2bool(str(self.config['TRACKERS'][self.tracker].get('anon', "False")))) == False:
data['epenis'] = self.uploader_name
if has_ro_audio:
data['materialro'] = 'on'
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
6 changes: 3 additions & 3 deletions src/trackers/HDT.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
import glob
import cli_ui
import pickle
import distutils
from pathlib import Path
from str2bool import str2bool
from bs4 import BeautifulSoup
from unidecode import unidecode
from pymediainfo import MediaInfo
Expand Down 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 Expand Up @@ -173,7 +173,7 @@ async def upload(self, meta):
data['season'] = 'false'

# Anonymous check
if meta['anon'] == 0 and bool(distutils.util.strtobool(str(self.config['TRACKERS'][self.tracker].get('anon', "False")))) == False:
if meta['anon'] == 0 and bool(str2bool(str(self.config['TRACKERS'][self.tracker].get('anon', "False")))) == False:
data['anonymous'] = 'false'
else:
data['anonymous'] = 'true'
Expand Down
Loading