This commit is contained in:
bskjon 2024-07-20 12:34:29 +02:00
parent 072cb2b192
commit 8bf709d899
2 changed files with 9 additions and 10 deletions

View File

@ -1,6 +1,6 @@
import json import json
from dataclasses import dataclass, asdict from dataclasses import dataclass, asdict
from typing import Any, List, Optional from typing import Any, Dict, List, Optional
from datetime import datetime from datetime import datetime
# Definer dataclassene for strukturen # Definer dataclassene for strukturen
@ -46,7 +46,7 @@ def event_data_to_json(event_data: EventData) -> str:
def json_to_media_event(json_data: str) -> MediaEvent: def json_to_media_event(json_data: str) -> MediaEvent:
data_dict = json.loads(json_data) data_dict = json.loads(json_data)
metadata_dict = data_dict['metadata'] metadata_dict: Dict[str, str] = data_dict['metadata']
event_data_dict = data_dict['data'] event_data_dict = data_dict['data']
metadata = EventMetadata( metadata = EventMetadata(
@ -55,7 +55,7 @@ def json_to_media_event(json_data: str) -> MediaEvent:
referenceId=metadata_dict['referenceId'], referenceId=metadata_dict['referenceId'],
status=metadata_dict['status'], status=metadata_dict['status'],
created=parse_datetime(metadata_dict['created']), created=parse_datetime(metadata_dict['created']),
source=metadata_dict['source'] source= metadata_dict.get('source', None)
) )
event_data = EventData( event_data = EventData(

View File

@ -30,11 +30,11 @@ class Anii(SourceBase):
if givenId: if givenId:
idToTitle[givenId] = _title idToTitle[givenId] = _title
results[givenId] = result results[givenId] = result
except IndexError as notFound: except IndexError:
pass pass
except Exception as e: except Exception as e:
log.exception(e) log.exception(e)
except IndexError as notFound: except IndexError:
self.logNoMatch("Anii", titles=self.titles) self.logNoMatch("Anii", titles=self.titles)
pass pass
except Exception as e: except Exception as e:
@ -43,7 +43,7 @@ class Anii(SourceBase):
if not idToTitle or not results: if not idToTitle or not results:
self.logNoMatch("Anii", titles=self.titles) self.logNoMatch("Anii", titles=self.titles)
return None return None
best_match_id, best_match_title = await asyncio.to_thread(self.findBestMatchAcrossTitles, idToTitle, self.titles) best_match_id, best_match_title = await asyncio.to_thread(self.findBestMatchAcrossTitles, idToTitle, self.titles)
return await self.__getMetadata(results[best_match_id]) return await self.__getMetadata(results[best_match_id])
@ -73,11 +73,10 @@ class Anii(SourceBase):
log.exception(e) log.exception(e)
return None return None
async def generate_id(self, text: str) -> Optional[str]: def generate_id(self, text: str) -> Optional[str]:
if text: if text:
return await asyncio.to_thread(hashlib.md5, text.encode()).hexdigest() return hashlib.md5(text.encode()).hexdigest()
return None return None
def getMediaType(self, type: str) -> str: def getMediaType(self, type: str) -> str:
return 'movie' if type.lower() == 'movie' else 'serie' return 'movie' if type.lower() == 'movie' else 'serie'