Commit 9fdcc59d authored by Matthias Klumpp's avatar Matthias Klumpp
Browse files

validator: Validate the new video screenshot element

CC: #175
parent b9d11934
......@@ -179,14 +179,26 @@ AsValidatorIssueTag as_validator_issue_tag_list[] = {
N_("Unable to reach the screenshot image on its remote location - does the image exist?")
},
{ "screenshot-image-url-insecure",
{ "screenshot-video-not-found",
AS_ISSUE_SEVERITY_WARNING,
N_("Unable to reach the screenshot video on its remote location - does the video file exist?")
},
{ "screenshot-media-url-insecure",
AS_ISSUE_SEVERITY_INFO,
N_("Consider using a secure (HTTPS) URL to reference this screenshot image.")
N_("Consider using a secure (HTTPS) URL to reference this screenshot image or video.")
},
{ "screenshot-no-media",
AS_ISSUE_SEVERITY_ERROR,
/* TRANSLATORS: Please do not translate AppStream tag and property names. */
N_("A screenshot must contain at least one image or video in order to be useful. Please add an <image/> to it.")
},
{ "screenshot-no-images",
{ "screenshot-mixed-images-videos",
AS_ISSUE_SEVERITY_ERROR,
N_("A screenshot must contain at least one image in order to be useful. Please add an <image/> to it.")
N_("A screenshot must contain either images or videos, but not both at the same time. Please use this screenshot exclusively "
"for either static images or for videos.")
},
{ "screenshot-no-caption",
......@@ -194,6 +206,38 @@ AsValidatorIssueTag as_validator_issue_tag_list[] = {
N_("The screenshot does not have a caption text. Consider adding one.")
},
{ "screenshot-video-codec-missing",
AS_ISSUE_SEVERITY_INFO,
/* TRANSLATORS: Please do not translate AppStream tag and property names. */
N_("The screenshot video does not specify which video codec was used in a 'codec' property.")
},
{ "screenshot-video-container-missing",
AS_ISSUE_SEVERITY_PEDANTIC,
/* TRANSLATORS: Please do not translate AppStream tag and property names. */
N_("The screenshot video does not specify which container format was used in a 'container' property.")
},
{ "screenshot-video-codec-invalid",
AS_ISSUE_SEVERITY_WARNING,
/* TRANSLATORS: Please do not translate AppStream tag and property names. */
N_("The selected video codec is not supported by AppStream and software centers may not be able to play the video. "
"Only the AV1 and VP9 codecs are currently supported, using 'av1' and 'vp9' as values for the 'codec' property.")
},
{ "screenshot-video-container-invalid",
AS_ISSUE_SEVERITY_WARNING,
/* TRANSLATORS: Please do not translate AppStream tag and property names. */
N_("The selected video container format is not supported by AppStream and software centers may not be able to play the video. "
"Only the WebM and Matroska video containers are currently supported, using 'webm' and 'mkv' as values for the 'container' property.")
},
{ "screenshot-video-file-wrong-container",
AS_ISSUE_SEVERITY_WARNING,
N_("For videos, only the WebM and Matroska (.mkv) container formats are currently supported. The file extension of the referenced "
"video does not belong to either of these formats.")
},
{ "relation-invalid-tag",
AS_ISSUE_SEVERITY_WARNING,
N_("Found an unknown tag in a requires/recommends group. This is likely an error, because a component relation of this type is unknown.")
......
......@@ -867,11 +867,10 @@ static void
as_validator_check_screenshots (AsValidator *validator, xmlNode *node, AsComponent *cpt)
{
xmlNode *iter;
as_validator_check_children_quick (validator, node, "screenshot", FALSE);
for (iter = node->children; iter != NULL; iter = iter->next) {
xmlNode *iter2;
gboolean image_found = FALSE;
gboolean video_found = FALSE;
gboolean caption_found = FALSE;
if (iter->type != XML_ELEMENT_NODE)
......@@ -905,10 +904,58 @@ as_validator_check_screenshots (AsValidator *validator, xmlNode *node, AsCompone
if (!as_validate_is_secure_url (image_url)) {
as_validator_add_issue (validator, iter2,
"screenshot-image-url-insecure",
"screenshot-media-url-insecure",
image_url);
}
} else if (g_strcmp0 (node_name, "video") == 0) {
g_autofree gchar *codec_str = NULL;
g_autofree gchar *container_str = NULL;
g_autofree gchar *video_url_basename = NULL;
g_autofree gchar *video_url_base_lower = NULL;
g_autofree gchar *video_url = (gchar*) xmlNodeGetContent (iter2);
video_found = TRUE;
if (!as_validator_web_url_exists (validator, video_url)) {
as_validator_add_issue (validator, iter2,
"screenshot-video-not-found",
video_url);
}
if (!as_validate_is_secure_url (video_url)) {
as_validator_add_issue (validator, iter2,
"screenshot-media-url-insecure",
video_url);
}
codec_str = (gchar*) xmlGetProp (iter2, (xmlChar*) "codec");
if (codec_str == NULL) {
as_validator_add_issue (validator, iter2, "screenshot-video-codec-missing", NULL);
} else {
AsVideoCodec codec = as_video_codec_from_string (codec_str);
if (codec == AS_VIDEO_CODEC_UNKNOWN)
as_validator_add_issue (validator, iter2, "screenshot-video-codec-invalid", codec_str);
}
container_str = (gchar*) xmlGetProp (iter2, (xmlChar*) "container");
if (container_str == NULL) {
as_validator_add_issue (validator, iter2, "screenshot-video-container-missing", NULL);
} else {
AsVideoContainer container = as_video_container_from_string (container_str);
if (container == AS_VIDEO_CONTAINER_UNKNOWN)
as_validator_add_issue (validator, iter2, "screenshot-video-container-invalid", container_str);
}
video_url_basename = g_path_get_basename (video_url);
video_url_base_lower = g_utf8_strdown (video_url_basename, -1);
if (g_strstr_len (video_url_base_lower, -1, ".") != NULL) {
if (!g_str_has_suffix (video_url_base_lower, ".mkv") &&
!g_str_has_suffix (video_url_base_lower, ".webm")) {
as_validator_add_issue (validator, iter2, "screenshot-video-file-wrong-container", video_url_basename);
}
}
} else if (g_strcmp0 (node_name, "caption") == 0) {
caption_found = TRUE;
} else {
......@@ -921,8 +968,10 @@ as_validator_check_screenshots (AsValidator *validator, xmlNode *node, AsCompone
}
}
if (!image_found)
as_validator_add_issue (validator, iter, "screenshot-no-images", NULL);
if (!image_found && !video_found)
as_validator_add_issue (validator, iter, "screenshot-no-media", NULL);
else if (image_found && video_found)
as_validator_add_issue (validator, iter, "screenshot-mixed-images-videos", NULL);
if (!caption_found)
as_validator_add_issue (validator, iter, "screenshot-no-caption", NULL);
......
Supports Markdown
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