|
| 1 | +package org.schabi.newpipe.extractor.services.youtube; |
| 2 | + |
| 3 | +import com.grack.nanojson.JsonObject; |
| 4 | +import com.grack.nanojson.JsonParser; |
| 5 | +import org.junit.jupiter.api.Test; |
| 6 | +import org.schabi.newpipe.extractor.MultiInfoItemsCollector; |
| 7 | +import org.schabi.newpipe.extractor.linkhandler.ChannelTabs; |
| 8 | +import org.schabi.newpipe.extractor.services.youtube.extractors.YoutubeChannelTabExtractor; |
| 9 | + |
| 10 | +import java.lang.reflect.Method; |
| 11 | +import java.util.Arrays; |
| 12 | + |
| 13 | +import static org.junit.jupiter.api.Assertions.assertEquals; |
| 14 | +import static org.schabi.newpipe.extractor.ServiceList.YouTube; |
| 15 | + |
| 16 | +public class YoutubeChannelTabExtractorLockupParsingTest { |
| 17 | + |
| 18 | + @Test |
| 19 | + public void testCollectItemHandlesRichItemLockupViewModel() throws Exception { |
| 20 | + final YoutubeChannelTabExtractor extractor = (YoutubeChannelTabExtractor) YouTube |
| 21 | + .getChannelTabExtractorFromId("UCpodcastTabFixture0000000", ChannelTabs.PODCASTS); |
| 22 | + |
| 23 | + final Method method = YoutubeChannelTabExtractor.class.getDeclaredMethod( |
| 24 | + "collectItem", |
| 25 | + MultiInfoItemsCollector.class, |
| 26 | + JsonObject.class, |
| 27 | + java.util.List.class); |
| 28 | + method.setAccessible(true); |
| 29 | + |
| 30 | + final MultiInfoItemsCollector collector = new MultiInfoItemsCollector(YouTube.getServiceId()); |
| 31 | + method.invoke(extractor, |
| 32 | + collector, |
| 33 | + buildRichItemLockupContent(), |
| 34 | + Arrays.asList("Memoire Vive", "https://www.youtube.com/channel/UCTFUnkRlNBCHwE0oD_6PM7g")); |
| 35 | + |
| 36 | + assertEquals(1, collector.getItems().size()); |
| 37 | + } |
| 38 | + |
| 39 | + @Test |
| 40 | + public void testCollectItemHandlesVideoLockupViewModel() throws Exception { |
| 41 | + final YoutubeChannelTabExtractor extractor = (YoutubeChannelTabExtractor) YouTube |
| 42 | + .getChannelTabExtractorFromId("UCpodcastTabFixture0000000", ChannelTabs.PODCASTS); |
| 43 | + |
| 44 | + final Method method = YoutubeChannelTabExtractor.class.getDeclaredMethod( |
| 45 | + "collectItem", |
| 46 | + MultiInfoItemsCollector.class, |
| 47 | + JsonObject.class, |
| 48 | + java.util.List.class); |
| 49 | + method.setAccessible(true); |
| 50 | + |
| 51 | + final MultiInfoItemsCollector collector = new MultiInfoItemsCollector(YouTube.getServiceId()); |
| 52 | + method.invoke(extractor, |
| 53 | + collector, |
| 54 | + buildVideoLockupContent(), |
| 55 | + Arrays.asList("Memoire Vive", "https://www.youtube.com/channel/UCTFUnkRlNBCHwE0oD_6PM7g")); |
| 56 | + |
| 57 | + assertEquals(1, collector.getItems().size()); |
| 58 | + } |
| 59 | + |
| 60 | + @Test |
| 61 | + public void testCollectItemHandlesNestedRichItemShelfContent() throws Exception { |
| 62 | + final YoutubeChannelTabExtractor extractor = (YoutubeChannelTabExtractor) YouTube |
| 63 | + .getChannelTabExtractorFromId("UCpodcastTabFixture0000000", ChannelTabs.PODCASTS); |
| 64 | + |
| 65 | + final Method method = YoutubeChannelTabExtractor.class.getDeclaredMethod( |
| 66 | + "collectItem", |
| 67 | + MultiInfoItemsCollector.class, |
| 68 | + JsonObject.class, |
| 69 | + java.util.List.class); |
| 70 | + method.setAccessible(true); |
| 71 | + |
| 72 | + final MultiInfoItemsCollector collector = new MultiInfoItemsCollector(YouTube.getServiceId()); |
| 73 | + method.invoke(extractor, |
| 74 | + collector, |
| 75 | + buildNestedRichItemShelfLockupContent(), |
| 76 | + Arrays.asList("Memoire Vive", "https://www.youtube.com/channel/UCTFUnkRlNBCHwE0oD_6PM7g")); |
| 77 | + |
| 78 | + assertEquals(1, collector.getItems().size()); |
| 79 | + } |
| 80 | + |
| 81 | + private static JsonObject buildRichItemLockupContent() throws Exception { |
| 82 | + return JsonParser.object().from("{\"richItemRenderer\":{\"content\":{\"lockupViewModel\":{" |
| 83 | + + "\"contentType\":\"LOCKUP_CONTENT_TYPE_PODCAST\"," |
| 84 | + + "\"contentId\":\"PL1234567890ABCDE\"," |
| 85 | + + "\"contentImage\":{\"collectionThumbnailViewModel\":{\"primaryThumbnail\":{" |
| 86 | + + "\"thumbnailViewModel\":{\"image\":{\"sources\":[{\"url\":\"https://i.ytimg.com/vi/test/default.jpg\"}]}," |
| 87 | + + "\"overlays\":[{\"thumbnailOverlayBadgeViewModel\":{\"thumbnailBadges\":[{\"thumbnailBadgeViewModel\":{\"text\":\"12\"}}]}}]" |
| 88 | + + "}}}}," |
| 89 | + + "\"metadata\":{\"lockupMetadataViewModel\":{" |
| 90 | + + "\"title\":{\"content\":\"Test podcast\"}," |
| 91 | + + "\"metadata\":{\"contentMetadataViewModel\":{\"metadataRows\":[{}]}}" |
| 92 | + + "}}" |
| 93 | + + "}}}}"); |
| 94 | + } |
| 95 | + |
| 96 | + private static JsonObject buildVideoLockupContent() throws Exception { |
| 97 | + return JsonParser.object().from("{\"lockupViewModel\":{" |
| 98 | + + "\"contentType\":\"LOCKUP_CONTENT_TYPE_VIDEO\"," |
| 99 | + + "\"contentId\":\"dQw4w9WgXcQ\"," |
| 100 | + + "\"contentImage\":{\"thumbnailViewModel\":{" |
| 101 | + + "\"image\":{\"sources\":[{\"url\":\"https://i.ytimg.com/vi/dQw4w9WgXcQ/default.jpg\"}]}," |
| 102 | + + "\"overlays\":[]" |
| 103 | + + "}}," |
| 104 | + + "\"metadata\":{\"lockupMetadataViewModel\":{" |
| 105 | + + "\"title\":{\"content\":\"Episode 1\"}," |
| 106 | + + "\"metadata\":{\"contentMetadataViewModel\":{\"metadataRows\":[]}}" |
| 107 | + + "}}" |
| 108 | + + "}}"); |
| 109 | + } |
| 110 | + |
| 111 | + private static JsonObject buildNestedRichItemShelfLockupContent() throws Exception { |
| 112 | + return JsonParser.object().from("{\"richItemRenderer\":{\"content\":{\"shelfRenderer\":{" |
| 113 | + + "\"content\":{\"horizontalListRenderer\":{\"items\":[{\"lockupViewModel\":{" |
| 114 | + + "\"contentType\":\"LOCKUP_CONTENT_TYPE_PODCAST\"," |
| 115 | + + "\"contentId\":\"PL1234567890ABCDE\"," |
| 116 | + + "\"contentImage\":{\"collectionThumbnailViewModel\":{\"primaryThumbnail\":{" |
| 117 | + + "\"thumbnailViewModel\":{\"image\":{\"sources\":[{\"url\":\"https://i.ytimg.com/vi/test/default.jpg\"}]}," |
| 118 | + + "\"overlays\":[{\"thumbnailOverlayBadgeViewModel\":{\"thumbnailBadges\":[{\"thumbnailBadgeViewModel\":{\"text\":\"12\"}}]}}]" |
| 119 | + + "}}}}," |
| 120 | + + "\"metadata\":{\"lockupMetadataViewModel\":{" |
| 121 | + + "\"title\":{\"content\":\"Test podcast\"}," |
| 122 | + + "\"metadata\":{\"contentMetadataViewModel\":{\"metadataRows\":[{}]}}" |
| 123 | + + "}}" |
| 124 | + + "}}]}}}}}}}"); |
| 125 | + } |
| 126 | +} |
0 commit comments