如需在创建或更新 Feed 时验证实体,请使用以下 JSON 架构。这些架构基于 JSON 架构规范。通过添加单元测试来验证您生成的实体,您可以检测会影响 Feed 质量的问题。您还可以在 Feed 开发过程中使用这些架构,以避免常见错误。
选择“媒体操作”架构
- 视频点播架构会验证
Movie
、TVEpisode
、TVSeries
和TVSeason
实体。 - 直播电视架构会验证
BroadcastEvent
、BroadcastService
、CableOrSatelliteService
、Movie
、Organization
、SportsEvent
、TelevisionChannel
、TVEpisode
、TVSeason
和TVSeries
实体。 - 音乐架构用于验证
MusicAlbum
、MusicGroup
、MusicPlaylist
和MusicRecording
实体。 - Radio 架构用于验证
RadioBroadcastService
实体。
请将此网站上的规范用作可信来源,因为这些架构可能未实现所有功能。
选择验证器
您可以在 json-schema.org 上找到验证程序实现列表。
所提供的架构采用草稿 7 编写,因此您选择的实现需要支持此版本才能正常运行。
验证示例
以下示例展示了如何使用架构文件 schema.json
和 jsonschema Python 模块验证文件 feed.json
中的所有实体。这些实体位于数据 Feed 封装容器文档中指定的属性 dataFeedElement
中。
import json
from jsonschema import validate
# Loading the schema file
with open("schema.json", "r") as fp:
schema = json.load(fp)
# Opening the feed
with open("feed.json", "r") as fp:
feed = json.load(fp)
# Validating each entity in the feed
for entity in feed["dataFeedElement"] :
try:
validate(schema=schema, instance=entity)
print("Entity validated successfully")
except Exception as e:
# e may contain an explanation as to why the entity wasn't valid
print("Failed to validate the entity")