|
1 | 1 | package org.schabi.newpipe.extractor.services.soundcloud; |
2 | 2 |
|
| 3 | +import static org.junit.jupiter.api.Assertions.assertEquals; |
| 4 | +import static org.junit.jupiter.api.Assertions.assertTrue; |
| 5 | +import static org.schabi.newpipe.extractor.ServiceList.SoundCloud; |
| 6 | + |
3 | 7 | import org.junit.jupiter.api.BeforeAll; |
4 | 8 | import org.junit.jupiter.api.Disabled; |
5 | 9 | import org.junit.jupiter.api.Test; |
6 | 10 | import org.schabi.newpipe.downloader.DownloaderTestImpl; |
7 | 11 | import org.schabi.newpipe.extractor.ExtractorAsserts; |
8 | | -import org.schabi.newpipe.extractor.MediaFormat; |
9 | 12 | import org.schabi.newpipe.extractor.NewPipe; |
10 | 13 | import org.schabi.newpipe.extractor.StreamingService; |
11 | 14 | import org.schabi.newpipe.extractor.exceptions.GeographicRestrictionException; |
12 | 15 | import org.schabi.newpipe.extractor.exceptions.SoundCloudGoPlusContentException; |
13 | 16 | import org.schabi.newpipe.extractor.services.DefaultStreamExtractorTest; |
14 | | -import org.schabi.newpipe.extractor.stream.AudioStream; |
15 | | -import org.schabi.newpipe.extractor.stream.DeliveryMethod; |
16 | 17 | import org.schabi.newpipe.extractor.stream.StreamExtractor; |
17 | | -import org.schabi.newpipe.extractor.stream.StreamType; |
| 18 | +import org.schabi.newpipe.extractor.streamdata.delivery.ProgressiveHTTPDeliveryData; |
| 19 | +import org.schabi.newpipe.extractor.streamdata.format.registry.AudioFormatRegistry; |
| 20 | +import org.schabi.newpipe.extractor.streamdata.stream.AudioStream; |
18 | 21 |
|
19 | 22 | import java.util.Arrays; |
20 | 23 | import java.util.Collections; |
21 | 24 | import java.util.List; |
22 | 25 |
|
23 | 26 | import javax.annotation.Nullable; |
24 | 27 |
|
25 | | -import static org.junit.jupiter.api.Assertions.*; |
26 | | -import static org.schabi.newpipe.extractor.ServiceList.SoundCloud; |
27 | | - |
28 | 28 | public class SoundcloudStreamExtractorTest { |
29 | 29 | private static final String SOUNDCLOUD = "https://soundcloud.com/"; |
30 | 30 |
|
@@ -186,29 +186,33 @@ public static void setUp() throws Exception { |
186 | 186 | @Test |
187 | 187 | public void testAudioStreams() throws Exception { |
188 | 188 | super.testAudioStreams(); |
| 189 | + |
189 | 190 | final List<AudioStream> audioStreams = extractor.getAudioStreams(); |
190 | 191 | assertEquals(2, audioStreams.size()); |
191 | | - audioStreams.forEach(audioStream -> { |
192 | | - final DeliveryMethod deliveryMethod = audioStream.getDeliveryMethod(); |
193 | | - final String mediaUrl = audioStream.getContent(); |
194 | | - if (audioStream.getFormat() == MediaFormat.OPUS) { |
| 192 | + |
| 193 | + for (final AudioStream audioStream : audioStreams) { |
| 194 | + assertTrue(audioStream.deliveryData() instanceof ProgressiveHTTPDeliveryData, |
| 195 | + "Wrong delivery method for mediaFormat=" + audioStream.mediaFormat() |
| 196 | + + " , avgBR=" + audioStream.averageBitrate() |
| 197 | + + " , deliverDataType=" + audioStream.deliveryData().getClass() |
| 198 | + ); |
| 199 | + |
| 200 | + final ProgressiveHTTPDeliveryData deliveryData = |
| 201 | + (ProgressiveHTTPDeliveryData) audioStream.deliveryData(); |
| 202 | + |
| 203 | + final String mediaUrl = deliveryData.url(); |
| 204 | + if (audioStream.mediaFormat() == AudioFormatRegistry.OPUS) { |
195 | 205 | // Assert that it's an OPUS 64 kbps media URL with a single range which comes |
196 | 206 | // from an HLS SoundCloud CDN |
197 | 207 | ExtractorAsserts.assertContains("-hls-opus-media.sndcdn.com", mediaUrl); |
198 | 208 | ExtractorAsserts.assertContains(".64.opus", mediaUrl); |
199 | | - assertSame(DeliveryMethod.HLS, deliveryMethod, |
200 | | - "Wrong delivery method for stream " + audioStream.getId() + ": " |
201 | | - + deliveryMethod); |
202 | | - } else if (audioStream.getFormat() == MediaFormat.MP3) { |
| 209 | + } else if (audioStream.mediaFormat() == AudioFormatRegistry.MP3) { |
203 | 210 | // Assert that it's a MP3 128 kbps media URL which comes from a progressive |
204 | 211 | // SoundCloud CDN |
205 | 212 | ExtractorAsserts.assertContains("-media.sndcdn.com/bKOA7Pwbut93.128.mp3", |
206 | 213 | mediaUrl); |
207 | | - assertSame(DeliveryMethod.PROGRESSIVE_HTTP, deliveryMethod, |
208 | | - "Wrong delivery method for stream " + audioStream.getId() + ": " |
209 | | - + deliveryMethod); |
210 | 214 | } |
211 | | - }); |
| 215 | + } |
212 | 216 | } |
213 | 217 | } |
214 | 218 | } |
0 commit comments