Repository: crawler-commons/crawler-commons
Pull request #301 (2020-07-16 14:55:26)

Adding duration to the map generated by VideoAttributes.asMap
Adding duration to the map generated by VideoAttributes.asMap.  This is a fix for #300 


Patch:
diff --git a/CHANGES.txt b/CHANGES.txt
index 90d7fb7..f2e6a76 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -3,6 +3,7 @@ Crawler-Commons Change Log
 Current Development 1.2-SNAPSHOT (yyyy-mm-dd)
 - [SiteMapParser] Document options *strict* and *allowPartial* in SiteMapParser constructors (sebastian-nagel) #267
 - [Robots] Maximum values (crawl-delay and warnings): document and make visible (sebastian-nagel, Avi Hayun) #276
+- [Sitemaps] Adding duration to the map generated by VideoAttributes.asMap (evanhalley)  #300
 
 Release 1.1 (2020-06-29)
 - [sitemaps] Sitemaps to implement Serializable (cdalexndr, sebastian-nagel) #244
diff --git a/src/main/java/crawlercommons/sitemaps/extension/VideoAttributes.java b/src/main/java/crawlercommons/sitemaps/extension/VideoAttributes.java
index f4f1c0f..5098edb 100644
--- a/src/main/java/crawlercommons/sitemaps/extension/VideoAttributes.java
+++ b/src/main/java/crawlercommons/sitemaps/extension/VideoAttributes.java
@@ -57,6 +57,7 @@ public class VideoAttributes extends ExtensionMetadata {
     public static final String ALLOWED_PLATFORMS = "allowed_platforms";
     public static final String RESTRICTED_PLATFORMS = "restricted_platforms";
     public static final String IS_LIVE = "is_live";
+    public static final String DURATION = "duration";
     
     /**
      * Video thumbnail URL found under video/thumbnail_loc (required)
@@ -678,6 +679,10 @@ public class VideoAttributes extends ExtensionMetadata {
         if (isLive != null) {
             map.put(IS_LIVE, new String[]{ isLive.toString() });
         }
+
+        if (duration != null) {
+            map.put(DURATION, new String[]{ duration.toString() });
+        }
         return Collections.unmodifiableMap(map);
     }
 }


Test patch:
diff --git a/src/test/java/crawlercommons/sitemaps/extension/VideoAttributesTest.java b/src/test/java/crawlercommons/sitemaps/extension/VideoAttributesTest.java
index 33a4809..00ae4a7 100644
--- a/src/test/java/crawlercommons/sitemaps/extension/VideoAttributesTest.java
+++ b/src/test/java/crawlercommons/sitemaps/extension/VideoAttributesTest.java
@@ -36,6 +36,7 @@ public class VideoAttributesTest {
         attributes.setUploader("GrillyMcGrillerson");
         attributes.setUploaderInfo(new URL("http://www.example.com/users/grillymcgrillerson"));
         attributes.setLive(false);
+        attributes.setDuration(54321);
         Map<String, String[]> map = attributes.asMap();
 
         assertEquals(attributes.getThumbnailLoc().toString(), map.get(VideoAttributes.THUMBNAIL_LOC)[0]);
@@ -63,6 +64,7 @@ public class VideoAttributesTest {
         assertArrayEquals(attributes.getAllowedPlatforms(), map.get(VideoAttributes.ALLOWED_PLATFORMS));
         assertArrayEquals(attributes.getRestrictedPlatforms(), map.get(VideoAttributes.RESTRICTED_PLATFORMS));
         assertEquals(attributes.getLive().toString(), map.get(VideoAttributes.IS_LIVE)[0]);
+        assertEquals(attributes.getDuration().toString(), map.get(VideoAttributes.DURATION)[0]);
     }
 
     @Test
@@ -93,5 +95,6 @@ public class VideoAttributesTest {
         assertNull(map.get(VideoAttributes.ALLOWED_PLATFORMS));
         assertNull(map.get(VideoAttributes.RESTRICTED_PLATFORMS));
         assertNull(map.get(VideoAttributes.IS_LIVE));
+        assertNull(map.get(VideoAttributes.DURATION));
     }
 }
\ No newline at end of file