Updated
This commit is contained in:
parent
fe47168718
commit
b80ee038b2
@ -150,12 +150,14 @@ class MessageHandlerThread(threading.Thread):
|
|||||||
baseName = messageData["sanitizedName"]
|
baseName = messageData["sanitizedName"]
|
||||||
title = messageData["title"]
|
title = messageData["title"]
|
||||||
|
|
||||||
|
eventId = self.message.value["eventId"]
|
||||||
|
|
||||||
logger.info("Searching for %s", title)
|
logger.info("Searching for %s", title)
|
||||||
result = self.get_metadata(title)
|
result = self.get_metadata(title, eventId)
|
||||||
if (result is None):
|
if (result is None):
|
||||||
logger.info("No result for %s", title)
|
logger.info("No result for %s", title)
|
||||||
logger.info("Searching for %s", baseName)
|
logger.info("Searching for %s", baseName)
|
||||||
result = self.get_metadata(baseName)
|
result = self.get_metadata(baseName, eventId)
|
||||||
|
|
||||||
producerMessage = self.compose_message(referenceId=self.message.value["referenceId"], result=result)
|
producerMessage = self.compose_message(referenceId=self.message.value["referenceId"], result=result)
|
||||||
|
|
||||||
@ -175,7 +177,7 @@ class MessageHandlerThread(threading.Thread):
|
|||||||
else:
|
else:
|
||||||
logger.warn("No status present for %s", self.message.value)
|
logger.warn("No status present for %s", self.message.value)
|
||||||
|
|
||||||
def get_metadata(self, name: str) -> Optional[DataResult]:
|
def get_metadata(self, name: str, evnetId: str) -> Optional[DataResult]:
|
||||||
result = None
|
result = None
|
||||||
logger.info("Checking cache for offloading")
|
logger.info("Checking cache for offloading")
|
||||||
cache_result = ResultCache.get(name)
|
cache_result = ResultCache.get(name)
|
||||||
@ -185,7 +187,7 @@ class MessageHandlerThread(threading.Thread):
|
|||||||
else:
|
else:
|
||||||
logger.info("Not in cache: %s", name)
|
logger.info("Not in cache: %s", name)
|
||||||
logger.info("Searching in sources for information about %s", name)
|
logger.info("Searching in sources for information about %s", name)
|
||||||
result: Optional[DataResult] = UseSource(title=name).select_result()
|
result: Optional[DataResult] = UseSource(title=name, eventId=evnetId).select_result()
|
||||||
if (result.status == "COMPLETED"):
|
if (result.status == "COMPLETED"):
|
||||||
logger.info("Storing response for %s in in-memory cache", name)
|
logger.info("Storing response for %s in in-memory cache", name)
|
||||||
ResultCache.add(name, result)
|
ResultCache.add(name, result)
|
||||||
|
|||||||
@ -7,6 +7,7 @@ from .imdb import metadata as ImdbMetadata
|
|||||||
from .mal import metadata as MalMetadata
|
from .mal import metadata as MalMetadata
|
||||||
from fuzzywuzzy import fuzz
|
from fuzzywuzzy import fuzz
|
||||||
from unidecode import unidecode
|
from unidecode import unidecode
|
||||||
|
import json
|
||||||
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
@ -23,7 +24,8 @@ class DataAndScore:
|
|||||||
|
|
||||||
class UseSource():
|
class UseSource():
|
||||||
title: str
|
title: str
|
||||||
def __init__(self, title) -> None:
|
evnetId: str
|
||||||
|
def __init__(self, title, eventId) -> None:
|
||||||
self.title = title
|
self.title = title
|
||||||
|
|
||||||
def __perform_search(self, title)-> List[WeightedData]:
|
def __perform_search(self, title)-> List[WeightedData]:
|
||||||
@ -63,13 +65,21 @@ class UseSource():
|
|||||||
scored = self.__calculate_score(title=self.title, weightData=weightResult)
|
scored = self.__calculate_score(title=self.title, weightData=weightResult)
|
||||||
scored.sort(key=lambda x: x.score, reverse=True)
|
scored.sort(key=lambda x: x.score, reverse=True)
|
||||||
|
|
||||||
|
try:
|
||||||
|
jsr = json.dumps(scored, indent=4)
|
||||||
|
with open(f"./logs/{self.evnetId}.json", "w", encoding="utf-8") as f:
|
||||||
|
f.write(jsr)
|
||||||
|
except:
|
||||||
|
logger.info("Couldn't dump log..")
|
||||||
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
titles: List[str] = []
|
titles: List[str] = []
|
||||||
for wd in weightResult:
|
for wd in weightResult:
|
||||||
titles.append(wd.result.data.title)
|
titles.append(wd.result.data.title)
|
||||||
titles.extend(wd.result.data.altTitle)
|
titles.extend(wd.result.data.altTitle)
|
||||||
joinedTitles = "\n\t".join(titles)
|
joinedTitles = "\n\t" + "\n\t".join(titles)
|
||||||
logger.info(f"Title {self.title} gave the result: {joinedTitles} \nTitle selected: \n\t{scored[0].result.data.title}\n")
|
logger.info(f"[Title]: {self.title} gave the result: {joinedTitles} \nTitle selected: \n\t{scored[0].result.data.title}\n")
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|||||||
@ -14,6 +14,8 @@ RUN pip3 install -r ./requirements.txt
|
|||||||
# Kopier resten av prosjektfilene
|
# Kopier resten av prosjektfilene
|
||||||
COPY ./apps/${MODULE_NAME}/ .
|
COPY ./apps/${MODULE_NAME}/ .
|
||||||
|
|
||||||
|
RUN mkdir ./apps/logs
|
||||||
|
|
||||||
# Start applikasjonen
|
# Start applikasjonen
|
||||||
CMD ["python3", "-u", "app.py"]
|
CMD ["python3", "-u", "app.py"]
|
||||||
|
|
||||||
|
|||||||
@ -81,8 +81,10 @@ class FileNameParser(val fileName: String) {
|
|||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
fun removeResolutionAndTags(text: String): String {
|
fun removeResolutionAndTags(input: String): String {
|
||||||
return Regex("(.*?)(?=\\d+[pk]\\b)").replace(text, " ")
|
var text = Regex("(?i)(\\d+[pk]\\b|(hd|uhd))", RegexOption.IGNORE_CASE).replace(input, " ")
|
||||||
|
text = Regex("(?i)(\\s(bluray|laserdisc|dvd|web))", RegexOption.IGNORE_CASE).replace(text, " ")
|
||||||
|
return text
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user