Added Tools.py for basic functions. More progress on VideoService
This commit is contained in:
parent
3a77d7c348
commit
43e05f1858
17
Universal/tools.py
Normal file
17
Universal/tools.py
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
from jmespath import search
|
||||||
|
from pyparsing import replace_with
|
||||||
|
|
||||||
|
|
||||||
|
def replace(input_str, search_key, replace_str, checkspaces=False):
|
||||||
|
if replace_str is None:
|
||||||
|
input_str = replace(input_str, search_key, "", checkspaces)
|
||||||
|
else:
|
||||||
|
while input_str.find(search_key) != -1:
|
||||||
|
if checkspaces:
|
||||||
|
if input_str[input_str.index(search_key) - 1] != " ":
|
||||||
|
input_str = input_str.replace(search_key, " " + replace_str)
|
||||||
|
else:
|
||||||
|
input_str = input_str.replace(search_key, replace_str)
|
||||||
|
else:
|
||||||
|
input_str = input_str.replace(search, replace_str)
|
||||||
|
return input_str
|
@ -3,6 +3,7 @@ import re
|
|||||||
import time
|
import time
|
||||||
import default
|
import default
|
||||||
import subprocess
|
import subprocess
|
||||||
|
from Universal import tools
|
||||||
from Universal import ioservice
|
from Universal import ioservice
|
||||||
from Universal import loggingservice
|
from Universal import loggingservice
|
||||||
from Video.Services import tmdbservice
|
from Video.Services import tmdbservice
|
||||||
@ -75,7 +76,12 @@ class VideoService:
|
|||||||
tmp_success = True
|
tmp_success = True
|
||||||
if not tmp_isDeleted:
|
if not tmp_isDeleted:
|
||||||
tmp_current_file_info = self.extractVideoInformation(self.current_file)
|
tmp_current_file_info = self.extractVideoInformation(self.current_file)
|
||||||
self.constructOutputPath()
|
# self.constructOutputPath(tmp_current_file_info)
|
||||||
|
if tmp_current_file_info["Episode"] is None and tmp_current_file_info["Season"] is None:
|
||||||
|
self.logger.infoReport("[Video] " + tmp_current_file_info["Name"] + " " + str(tmp_current_file_info["Year"]))
|
||||||
|
else:
|
||||||
|
self.logger.infoReport("[Video] " + tmp_current_file_info["Name"] + " Season: " + str(tmp_current_file_info["Season"]) + " Episode: " + str(tmp_current_file_info["Episode"]))
|
||||||
|
self.find_srts()
|
||||||
|
|
||||||
def extractVideoInformation(self, file):
|
def extractVideoInformation(self, file):
|
||||||
self.logger.debugReport("[Video] extractVideoInformation")
|
self.logger.debugReport("[Video] extractVideoInformation")
|
||||||
@ -161,9 +167,63 @@ class VideoService:
|
|||||||
tmp_episode_title = tmp_episode_title.replace(":", "")
|
tmp_episode_title = tmp_episode_title.replace(":", "")
|
||||||
return {"Name": tmp_name, "Season": tmp_season, "Episode": tmp_episode, "Episode Title": tmp_episode_title, "Episode Year": tmp_episode_year, "Input Format": tmp_input_format}
|
return {"Name": tmp_name, "Season": tmp_season, "Episode": tmp_episode, "Episode Title": tmp_episode_title, "Episode Year": tmp_episode_year, "Input Format": tmp_input_format}
|
||||||
|
|
||||||
def constructOutputPath(self, subtitles=False, num=0):
|
def constructOutputPath(self, file_info, subtitles=False, num=0):
|
||||||
self.logger.debugReport("[Video] constructOutputPath")
|
self.logger.debugReport("[Video] constructOutputPath")
|
||||||
### TODO: Implement this next
|
self.current_output_path = self.video_settings.library["Output"] + self.video_settings.library["Directory"]
|
||||||
|
self.current_output_path = tools.replace(self.current_output_path, "${NAME}", file_info["Name"])
|
||||||
|
self.current_output_path = tools.replace(self.current_output_path, "${YEAR}", file_info["Year"])
|
||||||
|
self.current_output_path = tools.replace(self.current_output_path, "${SEASON}", file_info["Season"])
|
||||||
|
if isinstance(file_info["Episode"], list):
|
||||||
|
tmp_episodes = None
|
||||||
|
for eps in file_info["Episode"]:
|
||||||
|
if eps != file_info["Episode"][-1]:
|
||||||
|
if not tmp_episodes:
|
||||||
|
tmp_episodes = str(eps) + "-"
|
||||||
|
else:
|
||||||
|
tmp_episodes = tmp_episodes + str(eps) + "-"
|
||||||
|
else:
|
||||||
|
if not tmp_episodes:
|
||||||
|
tmp_episodes = str(eps)
|
||||||
|
else:
|
||||||
|
tmp_episodes = tmp_episodes + str(eps)
|
||||||
|
self.current_output_path = tools.replace(self.current_output_path, "${EPISODE}", tmp_episodes)
|
||||||
|
else:
|
||||||
|
self.current_output_path = tools.replace(self.current_output_path, "${EPISODE}", file_info["Episode"])
|
||||||
|
self.current_output_path = tools.replace(self.current_output_path, "${EPISODE_YEAR}", file_info["Episode Year"])
|
||||||
|
self.current_output_path = tools.replace(self.current_output_path, "${EPISODE_NAME}", file_info["Episode Name"])
|
||||||
|
if not subtitles:
|
||||||
|
if self.current_output_path[self.current_output_path.index("${FORMAT}") - 1] != ".":
|
||||||
|
if file_info["Format"].startswith("."):
|
||||||
|
self.current_output_path = tools.replace(self.current_output_path, "${FORMAT}", file_info["Format"])
|
||||||
|
else:
|
||||||
|
self.current_output_path = tools.replace(self.current_output_path, "${FORMAT}", "." + file_info["Format"])
|
||||||
|
else:
|
||||||
|
if file_info["Format"].startswith("."):
|
||||||
|
self.current_output_path = tools.replace(self.current_output_path, ".${FORMAT}", file_info["Format"])
|
||||||
|
else:
|
||||||
|
self.current_output_path = tools.replace(self.current_output_path, ".${FORMAT}", "." + file_info["Format"])
|
||||||
|
else:
|
||||||
|
if self.current_output_path[self.current_output_path.index("${FORMAT}") - 1] != ".":
|
||||||
|
self.current_output_path = tools.replace(self.current_output_path, "${FORMAT}", " - " + self.srt_language[num] + ".srt")
|
||||||
|
elif self.current_output_path[self.current_output_path.index("${FORMAT}" - 1)] == ".":
|
||||||
|
self.current_output_path = tools.replace(self.current_output_path, ".${FORMAT}", " - " + self.srt_language[num] + ".srt")
|
||||||
|
self.logger.debugReport("[Video] Output Path: " + self.current_output_path)
|
||||||
|
return self.current_output_path
|
||||||
|
|
||||||
|
def findSRTs(self):
|
||||||
|
self.logger.debugReport("[Video] findSRTs")
|
||||||
|
tmp_srt_lang = ["aar", "abk", "afr", "aka", "alb", "amh", "ara", "arg", "arm", "asm", "ava", "ave", "aym", "aze", "bak", "bam", "baq",
|
||||||
|
"bel", "ben", "bih", "bis", "bos", "bre", "bul", "bur", "cat", "cha", "che", "chi", "chu", "chv", "cor", "cos", "cre",
|
||||||
|
"cze", "dan", "div", "dut", "dzo", "eng", "epo", "est", "ewe", "fao", "fij", "fin", "fre", "fry", "ful", "geo", "ger",
|
||||||
|
"gla", "gle", "glg", "glv", "gre", "grn", "guj", "hat", "hau", "heb", "her", "hin", "hmo", "hrv", "hun", "ibo", "ice",
|
||||||
|
"ido", "iii", "iku", "ile", "ina", "ind", "ipk", "ita", "jav", "jpn", "kal", "kan", "kas", "kau", "kaz", "khm", "kik",
|
||||||
|
"kin", "kir", "kom", "kon", "kor", "kua", "kur", "lao", "lat", "lav", "lim", "lin", "lit", "ltz", "lub", "lug", "mac",
|
||||||
|
"mah", "mal", "mao", "mar", "may", "mlg", "mlt", "mon", "nau", "nav", "nbl", "nde", "ndo", "nep", "nno", "nob", "nor",
|
||||||
|
"nya", "oci", "oji", "ori", "orm", "oss", "pan", "per", "pli", "pol", "por", "pus", "que", "roh", "rum", "run", "rus",
|
||||||
|
"sag", "san", "sin", "slo", "slv", "sme", "smo", "sna", "snd", "som", "sot", "spa", "srd", "srp", "ssw", "sun", "swa",
|
||||||
|
"swe", "tah", "tam", "tat", "tel", "tgk", "tgl", "tha", "tib", "tir", "ton", "tsn", "tso", "tuk", "tur", "twi", "uig",
|
||||||
|
"ukr", "urd", "uzb", "ven", "vie", "vol", "wel", "wln", "wol", "xho", "yid", "yor", "zha", "zul"]
|
||||||
|
|
||||||
|
|
||||||
def getVideoLength(self):
|
def getVideoLength(self):
|
||||||
self.logger.debugReport("[Video] getVideoLength")
|
self.logger.debugReport("[Video] getVideoLength")
|
||||||
|
Loading…
Reference in New Issue
Block a user