From 073f26e618084f92ebc0b87a3c411b48671ed56c Mon Sep 17 00:00:00 2001 From: Harald Gustafsson Date: Fri, 10 Aug 2018 13:09:47 +0200 Subject: [PATCH] Added broadcast/publishing datetime to metadata extraction and NFO file creation. --- lib/svtplay_dl/service/__init__.py | 2 +- lib/svtplay_dl/service/svtplay.py | 4 ++++ lib/svtplay_dl/utils/nfo.py | 3 +++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/svtplay_dl/service/__init__.py b/lib/svtplay_dl/service/__init__.py index 4e14dbd..279f7b8 100644 --- a/lib/svtplay_dl/service/__init__.py +++ b/lib/svtplay_dl/service/__init__.py @@ -25,7 +25,7 @@ class Service(object): "id": None, "service": self.__class__.__name__.lower(), "tvshow": None, "title_nice": None, "showdescription": None, "episodedescription": None, "showthumbnailurl": None, - "episodethumbnailurl": None} + "episodethumbnailurl": None, "publishing_datetime": None} if not http: self.http = HTTP(config) else: diff --git a/lib/svtplay_dl/service/svtplay.py b/lib/svtplay_dl/service/svtplay.py index e1e186c..b3bb9a6 100644 --- a/lib/svtplay_dl/service/svtplay.py +++ b/lib/svtplay_dl/service/svtplay.py @@ -271,6 +271,10 @@ class Svtplay(Service, MetadataThumbMixin): def extrametadata(self, data): self.output["tvshow"] = (self.output["season"] is not None and self.output["episode"] is not None) + try: + self.output["publishing_datetime"] = data["video"]["broadcastDate"] / 1000 + except KeyError: + pass try: title = data["video"]["programTitle"] self.output["title_nice"] = title diff --git a/lib/svtplay_dl/utils/nfo.py b/lib/svtplay_dl/utils/nfo.py index 6dfbb63..820e415 100644 --- a/lib/svtplay_dl/utils/nfo.py +++ b/lib/svtplay_dl/utils/nfo.py @@ -3,6 +3,7 @@ import logging import xml.etree.ElementTree as ET from svtplay_dl.utils.output import formatname from svtplay_dl.utils.parser import Options +from datetime import datetime def write_nfo_episode(output, config): @@ -12,6 +13,8 @@ def write_nfo_episode(output, config): ET.SubElement(root, "season").text = output["season"] ET.SubElement(root, "episode").text = output["episode"] ET.SubElement(root, "plot").text = output["showdescription"] + if output["publishing_datetime"] is not None: + ET.SubElement(root, "aired").text = datetime.fromtimestamp(output["publishing_datetime"]).isoformat() if not config.get("thumbnail"): # Set the thumbnail path to download link if not thumbnail downloaded ET.SubElement(root, "thumb").text = output["showthumbnailurl"]