-
Notifications
You must be signed in to change notification settings - Fork 0
/
generators.py
93 lines (75 loc) · 2.42 KB
/
generators.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
from api import api
from datetime import datetime
from rfeed import Guid, Item, Feed
from extensions import MediaItem, WebfeedsIcon, WebfeedsCover, MediaContent, Webfeeds
def generate_episode_item(episode):
"""For Item:
episode_air_date -> pubDate as datetime.fromiso
description -> description
title -> title
id -> link as f'https://vrv.co/watch/{id}'
id -> guid
images['thumbnail'][:1] -> image (part of description)
link + '#comments' -> comments
For MediaItem:
images['thumbnail'][:1] -> url (part of description)
'image' -> medium
'image/jpeg' -> type
True -> isDefault
"""
link = f'https://vrv.co/watch/{episode["id"]}'
thumbnail = episode["images"]['thumbnail'][0][-1]["source"]
media_item_info = {
"url": thumbnail,
"medium": "image",
"type": "image/jpeg",
"isDefault": True
}
media_item = MediaItem(**media_item_info)
episode_info = {
"title": episode["title"],
"description": f'<img src="{thumbnail}" />\n<p>{episode["description"]}</p>',
"link": link,
"comments": link + "#comments",
"guid": Guid(link),
# Doesn't like Z
"pubDate": datetime.fromisoformat(episode["episode_air_date"].replace("Z", "")),
"extensions": [media_item]
}
return Item(**episode_info)
def generate_series_feed(series_id):
"""For Feed:
description -> description
title -> title
id -> link as f'https://vrv.co/series/{id}'
For WebfeedsCover:
images['poster_wide'][:1] -> url
For WebfeedsIcon:
images['poster_tall'][0] -> url
"""
series = api.get_series(series_id)
episodes = api.get_all_series_episodes(series_id)
images = series["images"]
cover_url = images['poster_wide'][0][-1]["source"]
icon_url = images['poster_tall'][0][0]["source"]
cover = WebfeedsCover(cover_url)
icon = WebfeedsIcon(icon_url)
feed_info = {
"title": series["title"],
"description": series["description"],
"link": f'https://vrv.co/series/{series["id"]}',
"items": map(lambda x: generate_episode_item(x), episodes),
"extensions": [MediaContent(), Webfeeds(), cover, icon,]
}
return Feed(**feed_info)
def generate_season_feed(season_id):
season = api.get_season(season_id)
episodes = api.get_all_season_episodes(season_id)
feed_info = {
"title": season["title"],
"description": season["description"],
"link": f'https://vrv.co/series/{season["series_id"]}',
"items": map(lambda x: generate_episode_item(x), episodes),
"extensions": [MediaContent(), Webfeeds(),]
}
return Feed(**feed_info)