mirror of
https://github.com/bellingcat/auto-archiver.git
synced 2026-06-11 20:58:29 +03:00
telethon_archiver working for multiple media
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
|
||||
from __future__ import annotations
|
||||
from ast import List
|
||||
from typing import Any, Union, Dict
|
||||
from dataclasses import dataclass
|
||||
from datetime import datetime
|
||||
|
||||
|
||||
@dataclass
|
||||
@@ -15,8 +17,8 @@ class Metadata:
|
||||
metadata: Dict[str, Any]
|
||||
|
||||
# TODO: remove and use default?
|
||||
def __init__(self) -> None:
|
||||
self.status = ""
|
||||
def __init__(self, status="") -> None:
|
||||
self.status = status
|
||||
self.metadata = {}
|
||||
|
||||
# @staticmethod
|
||||
@@ -27,14 +29,38 @@ class Metadata:
|
||||
pass
|
||||
|
||||
# TODO: setters?
|
||||
def set(self, key: str, val: Any) -> Union[Metadata, str]:
|
||||
def set(self, key: str, val: Any) -> Metadata:
|
||||
# goes through metadata and returns the Metadata available
|
||||
self.metadata[key] = val
|
||||
return self
|
||||
|
||||
def get(self, key: str, default: Any = None) -> Union[Metadata, str]:
|
||||
# goes through metadata and returns the Metadata available
|
||||
return self.metadata.get(key, default)
|
||||
|
||||
# custom getter/setters
|
||||
|
||||
def set_url(self, url: str) -> Metadata:
|
||||
assert type(url) is str and len(url) > 0, "invalid URL"
|
||||
return self.set("url", url)
|
||||
|
||||
def get_url(self) -> str:
|
||||
url = self.get("url")
|
||||
assert type(url) is str and len(url) > 0, "invalid URL"
|
||||
return url
|
||||
|
||||
def get_media(self) -> List:
|
||||
return self.get("media", [])
|
||||
|
||||
def set_title(self, title: str) -> Metadata:
|
||||
return self.set("title", title)
|
||||
|
||||
def set_timestamp(self, title: datetime) -> Metadata:
|
||||
return self.set("title", title)
|
||||
|
||||
def add_media(self, filename: str) -> Metadata:
|
||||
return self.get_media().append(filename)
|
||||
|
||||
def as_json(self) -> str:
|
||||
# converts all metadata and data into JSON
|
||||
pass
|
||||
|
||||
Reference in New Issue
Block a user