Commit 939e446b authored by Sam Bowen's avatar Sam Bowen Committed by Commit Bot

A few more small fixes for media feeds.

* Don't require an action status, as it's not required in the spec.
* Add an override for duration type to allow time values so validator
  doesn't delete it.
* Set live details before checking whether they are there.
* Check the URL values for interaction type instead of string.

All of the example media feed items are fetched with these changes.

Change-Id: I891afc2d1f6650a164f28a402b30ce248be5aa4f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2149906
Commit-Queue: Sam Bowen <sgbowen@google.com>
Reviewed-by: default avatarBecca Hughes <beccahughes@chromium.org>
Cr-Commit-Position: refs/heads/master@{#759445}
parent 708ee836
......@@ -383,9 +383,9 @@ bool GetIdentifiers(const Property& property, T* item) {
// string.
base::Optional<mojom::InteractionCounterType> GetInteractionType(
const Property& property) {
if (property.values->string_values.empty())
if (property.values->url_values.empty())
return base::nullopt;
GURL type = GURL(property.values->string_values[0]);
GURL type = property.values->url_values[0];
if (!type.SchemeIsHTTPOrHTTPS() || type.host() != "schema.org")
return base::nullopt;
......@@ -509,9 +509,6 @@ bool GetAction(mojom::MediaFeedItemActionStatus action_status,
return false;
item->action->url = target->values->url_values[0];
if (action_status == mojom::MediaFeedItemActionStatus::kUnknown)
return false;
if (action_status == mojom::MediaFeedItemActionStatus::kActive) {
auto* start_time =
GetProperty(action.get(), schema_org::property::kStartTime);
......@@ -632,9 +629,8 @@ base::Optional<EpisodeCandidate> GetEpisodeCandidate(const EntityPtr& entity) {
candidate.entity = entity.get();
auto action_status = GetActionStatus(entity.get());
if (!action_status)
return base::nullopt;
candidate.action_status = action_status.value();
candidate.action_status =
action_status.value_or(mojom::MediaFeedItemActionStatus::kUnknown);
auto episode_number = GetPositiveIntegerFromProperty(
entity.get(), schema_org::property::kEpisodeNumber);
......@@ -907,15 +903,15 @@ void GetDataFeedItems(
base::BindOnce(&GetMediaItemAuthor))) {
continue;
}
if (!convert_property.Run(schema_org::property::kPublication, false,
base::BindOnce(&GetLiveDetails))) {
continue;
}
if (!convert_property.Run(
schema_org::property::kDuration, !converted_item->live,
base::BindOnce(&GetDuration<mojom::MediaFeedItem>))) {
continue;
}
if (!convert_property.Run(schema_org::property::kPublication, false,
base::BindOnce(&GetLiveDetails))) {
continue;
}
} else if (converted_item->type == mojom::MediaFeedItemType::kMovie) {
if (!convert_property.Run(schema_org::property::kPublication, false,
base::BindOnce(&GetLiveDetails))) {
......@@ -946,13 +942,12 @@ void GetDataFeedItems(
item->type == schema_org::entity::kTVSeries && converted_item->action;
if (!has_embedded_action) {
auto action_status = GetActionStatus(item.get());
if (!action_status.has_value())
continue;
converted_item->action_status = action_status.value();
if (!convert_property.Run(schema_org::property::kPotentialAction,
!has_embedded_action,
base::BindOnce(&GetAction<mojom::MediaFeedItem>,
action_status.value()))) {
converted_item->action_status =
action_status.value_or(mojom::MediaFeedItemActionStatus::kUnknown);
if (!convert_property.Run(
schema_org::property::kPotentialAction, !has_embedded_action,
base::BindOnce(&GetAction<mojom::MediaFeedItem>,
converted_item->action_status))) {
continue;
}
}
......
......@@ -462,8 +462,8 @@ TEST_F(MediaFeedsConverterTest, SucceedsItemWithInteractionStatistic) {
EntityPtr interaction_statistic = Entity::New();
interaction_statistic->type = schema_org::entity::kInteractionCounter;
interaction_statistic->properties.push_back(
CreateStringProperty(schema_org::property::kInteractionType,
"https://schema.org/WatchAction"));
CreateUrlProperty(schema_org::property::kInteractionType,
GURL("https://schema.org/WatchAction")));
interaction_statistic->properties.push_back(
CreateDoubleProperty(schema_org::property::kUserInteractionCount, 1.0));
item->properties.push_back(
......
......@@ -41,11 +41,17 @@ compiled_action("schema_org_name_data") {
rebase_path("$target_gen_dir/schema_org_name_data.json", root_build_dir),
]
inputs = [
rebase_path("//third_party/schema_org/schema.jsonld", root_build_dir),
rebase_path("//third_party/schema_org/overrides.jsonld", root_build_dir),
]
outputs = [ "$target_gen_dir/schema_org_name_data.json" ]
}
action("generate_schema_org_code") {
script = "//components/schema_org/generate_schema_org_code.py"
sources = [
"templates/schema_org_entity_names.cc.tmpl",
"templates/schema_org_entity_names.h.tmpl",
......@@ -56,6 +62,7 @@ action("generate_schema_org_code") {
"templates/schema_org_property_names.cc.tmpl",
"templates/schema_org_property_names.h.tmpl",
]
args =
[
"--schema-file",
......@@ -70,6 +77,12 @@ action("generate_schema_org_code") {
rebase_path("$target_gen_dir", root_build_dir),
"--templates",
] + sources
inputs = [
rebase_path("//third_party/schema_org/schema.jsonld", root_build_dir),
rebase_path("//third_party/schema_org/overrides.jsonld", root_build_dir),
]
outputs = [
"$target_gen_dir/schema_org_entity_names.h",
"$target_gen_dir/schema_org_entity_names.cc",
......@@ -80,6 +93,7 @@ action("generate_schema_org_code") {
"$target_gen_dir/schema_org_enums.h",
"$target_gen_dir/schema_org_enums.cc",
]
deps = [ ":schema_org_name_data" ]
}
......
......@@ -368,4 +368,20 @@ TEST_F(SchemaOrgValidatorTest, InvalidEnumPropertyValue) {
EXPECT_TRUE(entity->properties.empty());
}
TEST_F(SchemaOrgValidatorTest, ValidDurationPropertyValue) {
EntityPtr entity = Entity::New();
entity->type = entity::kAction;
PropertyPtr property = Property::New();
property->name = property::kDuration;
property->values = Values::New();
property->values->time_values.push_back(base::TimeDelta::FromHours(2));
entity->properties.push_back(std::move(property));
bool validated_entity = ValidateEntity(entity.get());
EXPECT_TRUE(validated_entity);
EXPECT_EQ(1u, entity->properties.size());
}
} // namespace schema_org
......@@ -39,6 +39,54 @@
],
"rdfs:comment": "The Action representing the type of interaction. For up votes, +1s, etc. use <a class=\"localLink\" href=\"http://schema.org/LikeAction\">LikeAction</a>. For down votes use <a class=\"localLink\" href=\"http://schema.org/DislikeAction\">DislikeAction</a>. Otherwise, use the most specific Action.",
"rdfs:label": "interactionType"
},
{
"@id": "http://schema.org/duration",
"@type": "rdf:Property",
"http://purl.org/dc/terms/source": [
{
"@id": "https://github.com/schemaorg/schemaorg/issues/1698"
},
{
"@id": "https://github.com/schemaorg/schemaorg/issues/1457"
}
],
"http://schema.org/category": [
"issue-1457",
"issue-1698"
],
"http://schema.org/domainIncludes": [
{
"@id": "http://schema.org/QuantitativeValueDistribution"
},
{
"@id": "http://schema.org/Event"
},
{
"@id": "http://schema.org/Movie"
},
{
"@id": "http://schema.org/Schedule"
},
{
"@id": "http://schema.org/Audiobook"
},
{
"@id": "http://schema.org/MusicRecording"
},
{
"@id": "http://schema.org/MediaObject"
},
{
"@id": "http://schema.org/MusicRelease"
}
],
"http://schema.org/rangeIncludes": [
{"@id": "http://schema.org/Duration"},
{"@id": "http://schema.org/Time"}
],
"rdfs:comment": "The duration of the item (movie, audio recording, event, etc.) in <a href=\"http://en.wikipedia.org/wiki/ISO_8601\">ISO 8601 date format</a>.",
"rdfs:label": "duration"
}
]
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment