Skip to content

Commit 3c63646

Browse files
committed
Changes
- reordering the attributes - airdate now only show year, month and date instead of full ISO format
1 parent d7e680e commit 3c63646

File tree

1 file changed

+11
-38
lines changed
  • custom_components/plex_recently_added

1 file changed

+11
-38
lines changed

custom_components/plex_recently_added/parser.py

Lines changed: 11 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ def parse_data(data, max, base_url, token, identifier, section_key, images_base_
3131

3232
output = []
3333
for item in sorted_data:
34-
date = datetime.strptime(item.get("originallyAvailableAt", "1900-01-01"), "%Y-%m-%d").strftime('%Y-%m-%dT%H:%M:%SZ')
3534
thumb = item.get("thumb", item.get("parentThumb", item.get("grandparentThumb", None)))
3635
art = item.get("art", item.get("grandparentArt", None))
3736
deep_link_position = -1
@@ -44,58 +43,32 @@ def parse_data(data, max, base_url, token, identifier, section_key, images_base_
4443
data_output = {}
4544

4645
data_output["airdate"] = datetime.utcfromtimestamp(int(item.get("addedAt", 0))).strftime('%Y-%m-%dT%H:%M:%SZ')
47-
data_output["title"] = item.get("grandparentTitle", item.get("parentTitle", item.get("title", "")))
46+
data_output["aired"] = item.get("originallyAvailableAt", "")
4847
data_output["release"] = '$day, $date $time'
48+
data_output["flag"] = "viewCount" not in item
49+
data_output["title"] = item.get("grandparentTitle", item.get("parentTitle", item.get("title", "")))
4950
if item.get("title", None):
5051
data_output["episode"] = item["title"]
5152
else:
5253
data_output["episode"] = ''
53-
if item.get("parentIndex", None) and item.get("index", None):
54-
data_output["number"] = f'S{"{:0>2}".format(item.get("parentIndex", "1"))}E{"{:0>2}".format(item.get("index", "1"))}'
55-
else:
56-
data_output["number"] = ''
5754
if item.get("parentIndex", None):
5855
data_output["season_num"] = item["parentIndex"]
5956
if item.get("index", None):
6057
data_output["episode_num"] = item["index"]
61-
data_output["genres"] = ", ".join([genre['tag'] for genre in item.get('Genre', [])][:3])
62-
data_output["rating"] = ('\N{BLACK STAR} ' + str(item.get("rating"))) if int(float(item.get("rating", 0))) > 0 else ''
63-
data_output["studio"] = item.get("studio", "")
64-
data_output["aired"] = date
58+
if item.get("parentIndex", None) and item.get("index", None):
59+
data_output["number"] = f'S{"{:0>2}".format(item.get("parentIndex", "1"))}E{"{:0>2}".format(item.get("index", "1"))}'
60+
else:
61+
data_output["number"] = ''
6562
if int(item.get('duration', 0)) > 0:
6663
data_output["runtime"] = math.floor(int(item["duration"]) / 60000)
64+
data_output["studio"] = item.get("studio", "")
65+
data_output["genres"] = ", ".join([genre['tag'] for genre in item.get('Genre', [])][:3])
66+
data_output["rating"] = ('\N{BLACK STAR} ' + str(item.get("rating"))) if int(float(item.get("rating", 0))) > 0 else ''
67+
data_output['summary'] = item.get('summary', '')
6768
data_output["poster"] = (f'{images_base_url}?path={thumb}') if thumb else ""
6869
data_output["fanart"] = (f'{images_base_url}?path={art}') if art else ""
69-
data_output["flag"] = "viewCount" not in item
7070
data_output["deep_link"] = deep_link if identifier else None
7171

72-
73-
74-
75-
"""
76-
output.append(
77-
{
78-
"airdate": datetime.utcfromtimestamp(int(item.get("addedAt", 0))).strftime('%Y-%m-%dT%H:%M:%SZ'),
79-
"title": item.get("grandparentTitle", item.get("parentTitle", item.get("title", ""))),
80-
"release": '$day, $date $time',
81-
"episode": item.get("title", ""),
82-
"number": f'S{"{:0>2}".format(item.get("parentIndex", "1"))}E{"{:0>2}".format(item.get("index", "1"))}' if item.get("parentIndex", None) and item.get("index", None) else "",
83-
"season_num": item.get("parentIndex", ""),
84-
"season_num": item.get("parentIndex", "1"),
85-
"episode_num": item.get("index", "1"),
86-
"genres": ", ".join([genre['tag'] for genre in item.get('Genre', [])][:3]),
87-
"rating": ('\N{BLACK STAR} ' + str(item.get("rating"))) if int(float(item.get("rating", 0))) > 0 else '',
88-
"studio": item.get("studio", ""),
89-
"aired": date,
90-
"runtime": math.floor(int(item.get("duration", 0)) / 60000),
91-
"poster": (f'{images_base_url}?path={thumb}') if thumb else "",
92-
"fanart": (f'{images_base_url}?path={art}') if art else "",
93-
"flag": "viewCount" not in item,
94-
"deep_link": deep_link if identifier else None
95-
}
96-
)
97-
"""
98-
9972
output.append(data_output)
10073

10174
return output

0 commit comments

Comments
 (0)