-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
168 additions
and
129 deletions.
There are no files selected for viewing
Submodule data
updated
3 files
+21 −4 | character/student/Yuuka/bond/1.json | |
+5 −0 | constant/platform.json | |
+3 −0 | i18n/zh_cn/other.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,101 +1,39 @@ | ||
from data_model.types.url import UrlModel | ||
from data_model.loader import i18n_translator | ||
from data_model.tool.to_json import IToJson | ||
from data_model.constant.platform import BILIBILI, YOUTUBE | ||
from collections import UserList | ||
|
||
|
||
class StoryVideoInfo(IToJson): | ||
"""兼容 UrlModel 模型""" | ||
def __init__(self, data): | ||
""" | ||
data = {"url": "https://youtube.com/watch?v=Fsdfjisdjfio", "short_desc": "fjsdifajio"} | ||
""" | ||
self.data = data | ||
|
||
self.value = data.get("value", "") | ||
self.platform = self._detect_platform(self.value) | ||
self.short_desc = i18n_translator.query(data.get("short_desc", "")) | ||
|
||
@staticmethod | ||
def _detect_platform(url): | ||
if "bilibili.com" in url: | ||
return BILIBILI | ||
elif "youtube.com" in url or "youtu.be" in url: | ||
return YOUTUBE | ||
|
||
raise ValueError | ||
|
||
def to_json(self): | ||
return { | ||
"value": self.url, | ||
"platform": int(self.platform), | ||
"short_desc": self.short_desc.to_json() | ||
} | ||
|
||
def to_json_basic(self): | ||
return self.to_json() | ||
|
||
|
||
class StoryVideoLanguageInfo(IToJson): | ||
class StoryInfoSourceList(UserList, IToJson): | ||
def __init__(self, data: list): | ||
self.data = [StoryVideoInfo(i) for i in data] | ||
|
||
def to_json(self): | ||
return [i.to_json() for i in self.data] | ||
|
||
def to_json_basic(self): | ||
return self.to_json() | ||
|
||
def __len__(self): | ||
return len(self.data) | ||
|
||
def __iter__(self): | ||
return iter(self.data) | ||
|
||
def __getitem__(self, key): | ||
return self.data[key] | ||
|
||
|
||
|
||
|
||
class StoryInfoVideoType(IToJson): | ||
_component = [] | ||
|
||
def __init__(self, data: dict): | ||
for i in self._component: | ||
setattr(self, i, StoryVideoLanguageInfo(data.get(i, []))) | ||
super().__init__() | ||
for i in data: | ||
obj = UrlModel() | ||
obj.load(i) | ||
self.append(obj) | ||
|
||
def to_json(self): | ||
return [getattr(self, i).to_json() for i in self._component] | ||
return [i.to_json() for i in self] | ||
|
||
def to_json_basic(self): | ||
return self.to_json() | ||
|
||
|
||
class StoryInfoVideoTypeOfficial(StoryInfoVideoType): | ||
_component = ["zh_cn_cn", "zh_tw", "en"] | ||
|
||
def __init__(self, data: dict): | ||
super().__init__(data) | ||
return [i.to_json_basic() for i in self] | ||
|
||
|
||
class StoryInfoVideoTypeUnofficial(StoryInfoVideoType): | ||
_component = ["zh_cn_jp", "en"] | ||
class StoryInfoSource(IToJson): | ||
_component = ["en", "zh_tw", "zh_cn_cn", "zh_cn_jp"] | ||
|
||
def __init__(self, data: dict): | ||
super().__init__(data) | ||
|
||
|
||
class StoryInfoVideo(IToJson): | ||
def __init__(self, data): | ||
self.data = data | ||
self.video_official = StoryInfoVideoTypeOfficial(data.get("official", {})) | ||
self.video_unofficial = StoryInfoVideoTypeUnofficial(data.get("unofficial", {})) | ||
self.en = StoryInfoSourceList(data.get("en", [])) | ||
self.zh_tw = StoryInfoSourceList(data.get("zh_tw", [])) | ||
self.zh_cn_cn = StoryInfoSourceList(data.get("zh_cn_cn", [])) | ||
self.zh_cn_jp = StoryInfoSourceList(data.get("zh_cn_jp", [])) | ||
|
||
def to_json(self): | ||
return { | ||
"official": self.video_official.to_json(), | ||
"unofficial": self.video_unofficial.to_json() | ||
} | ||
d = {} | ||
for i in self._component: | ||
d[i] = getattr(self, i).to_json() | ||
return d | ||
|
||
def to_json_basic(self): | ||
return self.to_json() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,89 @@ | ||
from data_model.loader import i18n_translator | ||
from data_model.types.url import UrlModel | ||
from data_model.loader import i18n_translator, constant_manager | ||
from data_model.tool.to_json import IToJson | ||
from data_model.constant.platform import BILIBILI, YOUTUBE | ||
from data_model.constant.platform import BILIBILI, YOUTUBE, BLUEARCHIVE_IO | ||
from .story_source_all import StoryInfoSource, StoryInfoSourceList | ||
from collections import UserList | ||
from urllib.parse import urlparse, parse_qs, urlunparse, urlencode | ||
|
||
|
||
class StoryInfoPartVideo(IToJson): | ||
def __init__(self, data, story_obj): | ||
self.part_video = data | ||
self.story_video = story_obj.video | ||
class StoryInfoPartSourceEntry(IToJson): | ||
VIDEO_SITES = [BILIBILI, YOUTUBE] | ||
|
||
def __init__(self, part_data: dict, story_data: UrlModel): | ||
self.part_data = part_data | ||
self.story_data = story_data | ||
|
||
try: | ||
self.base_url = part_data["value"] | ||
self.platform = part_data["platform"] | ||
self.desc = i18n_translator.query(part_data["short_desc"]) | ||
except KeyError: | ||
self.base_url = story_data.value | ||
self.platform = story_data.platform | ||
self.desc = story_data.short_desc | ||
|
||
self.url = self.get_url() | ||
|
||
def get_url(self): | ||
parsed_url = urlparse(self.base_url) | ||
parameters = parse_qs(parsed_url.query) | ||
|
||
if str(self.platform) in self.VIDEO_SITES: | ||
parameters["t"] = self.part_data["timestamp"] | ||
elif str(self.platform) == BLUEARCHIVE_IO: | ||
parameters["changeIndex"] = self.part_data["script_index"] | ||
else: | ||
raise ValueError | ||
|
||
modified_query = urlencode(parameters, doseq=True) | ||
|
||
modified_url = urlunparse((parsed_url.scheme, parsed_url.netloc, parsed_url.path, parsed_url.params, | ||
modified_query, parsed_url.fragment)) | ||
return modified_url | ||
|
||
def to_json(self): | ||
t = { | ||
"platform": constant_manager.query("platform", self.platform).to_json(), | ||
"value": self.url, | ||
"short_desc": self.desc.to_json() | ||
} | ||
return t | ||
|
||
def to_json_basic(self): | ||
return self.to_json() | ||
|
||
|
||
class StoryInfoPartSourceList(UserList, IToJson): | ||
def __init__(self, part_data: list, story_data: StoryInfoSourceList): | ||
super().__init__() | ||
for i, j in zip(part_data, story_data): | ||
self.append(StoryInfoPartSourceEntry(i, j)) | ||
|
||
def to_json(self): | ||
return [i.to_json() for i in self] | ||
|
||
def to_json_basic(self): | ||
return self.to_json() | ||
|
||
|
||
class StoryInfoPartSource(IToJson): | ||
_component = ["en", "zh_tw", "zh_cn_cn", "zh_cn_jp"] | ||
|
||
def __init__(self, part_data: dict, story_data: StoryInfoSource): | ||
self.part_data = part_data | ||
self.story_data = story_data | ||
|
||
self.en = StoryInfoPartSourceList(part_data.get("en", []), story_data.en) | ||
self.zh_tw = StoryInfoPartSourceList(part_data.get("zh_tw", []), story_data.zh_tw) | ||
self.zh_cn_cn = StoryInfoPartSourceList(part_data.get("zh_cn_cn", []), story_data.zh_cn_cn) | ||
self.zh_cn_jp = StoryInfoPartSourceList(part_data.get("zh_cn_jp", []), story_data.zh_cn_jp) | ||
|
||
def to_json(self): | ||
d = {} | ||
for i in self._component: | ||
d[i] = getattr(self, i).to_json() | ||
return d | ||
|
||
def to_json_basic(self): | ||
return self.to_json() |
Oops, something went wrong.