123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- import requests
- import sys
- from plugins.plugin import Plugin
- from src.history import History
- from src.config import Config
- sys.path.append("..")
- from src.playlist import Playlist
- from src.video import Video
- class SovetRomanticaOngoings(Plugin):
- def __init__(self, history: History=History(), config: Config=Config()):
- super().__init__(history, config)
- self.history = history
- self.config = config
- self.name = "[+] SovetRomantica: Ongoings"
- self.category = "SovetRomantica"
- self.params = {}
- self.flag = "-sro"
- self.full_flag = "--srongoins"
- self.flag_help = "show all sovetromantica ongoings"
- self.flag_action = "store_true"
- self.save_config()
- self.api_instance = self.config.get_option(self.category, 'api-instance')
- def get_episodes(self, anime_id):
- resp = requests.get(
- f"{self.api_instance}/anime/{anime_id}/episodes"
- )
- if resp.status_code != 200: return list()
- episodes = resp.json()
- return episodes
- def get_animes(self, ids):
- resp = requests.post(
- f"{self.api_instance}/animes",
- data={'anime_id_array' : ids}
- )
- if resp.status_code != 200: return list()
- return resp.json()
- def get_ongoings(self):
- resp = requests.get(f"{self.api_instance}/ongoing")
- if resp.status_code != 200: return list()
- anime_list = resp.json()
- items = []
- anime_list = self.get_animes(str(anime_list))
- for it in anime_list:
- if type(it) != dict: continue
- title = f"{it['anime_name']} ({it['anime_name_russian']})"
- anime_id = it['anime_id']
- episodes = list()
- episodes_js = self.get_episodes(anime_id)
- for episode in episodes_js:
- if type(episode) != dict or episode['episode_type'] > 0: continue
- ititle = f"Episode {episode['episode_count']}"
- video = Video(
- title=ititle,
- #playlist_title=title,
- url=episode['embed']
- )
- video.isWatched= video.in_history(self.history)
-
- item = video.to_json()
- episodes.append(item)
-
- episodes.sort(key=lambda v: int(v['title'][8:]))
- playlist = Playlist(title, episodes)
- items.append(playlist.to_json())
- return items
- def get_items(self, params):
- return self.get_ongoings()
- def save_config(self):
- self.config.set_option(self.category, 'api-instance', 'https://service.sovetromantica.com/v1')
|