[Draft] Add live extractor
This commit is contained in:
parent
ed9402c002
commit
80f4d42226
|
@ -102,6 +102,16 @@ public class MediaCCCService extends StreamingService {
|
|||
}
|
||||
}, new MediaCCCRecentListLinkHandlerFactory(), "recent");
|
||||
|
||||
list.addKioskEntry(new KioskList.KioskExtractorFactory() {
|
||||
@Override
|
||||
public KioskExtractor createNewKiosk(final StreamingService streamingService,
|
||||
final String url, final String kioskId)
|
||||
throws ExtractionException {
|
||||
return new MediaCCCLiveStreamKiosk(MediaCCCService.this,
|
||||
new MediaCCCLiveStreamListLinkHandlerFactory().fromUrl(url), kioskId);
|
||||
}
|
||||
}, new MediaCCCLiveStreamListLinkHandlerFactory(), "live");
|
||||
|
||||
list.setDefaultKiosk("recent");
|
||||
} catch (Exception e) {
|
||||
throw new ExtractionException(e);
|
||||
|
|
|
@ -0,0 +1,86 @@
|
|||
package org.schabi.newpipe.extractor.services.media_ccc.extractors;
|
||||
|
||||
import com.grack.nanojson.JsonObject;
|
||||
import org.schabi.newpipe.extractor.exceptions.ParsingException;
|
||||
import org.schabi.newpipe.extractor.localization.DateWrapper;
|
||||
import org.schabi.newpipe.extractor.stream.StreamInfoItemExtractor;
|
||||
import org.schabi.newpipe.extractor.stream.StreamType;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public class MediaCCCLiveStreamExtractor implements StreamInfoItemExtractor {
|
||||
|
||||
private final JsonObject conferenceInfo;
|
||||
private final String group;
|
||||
private final JsonObject roomInfo;
|
||||
|
||||
public MediaCCCLiveStreamExtractor(JsonObject conferenceInfo, String group, JsonObject roomInfo) {
|
||||
this.conferenceInfo = conferenceInfo;
|
||||
this.group = group;
|
||||
this.roomInfo = roomInfo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() throws ParsingException {
|
||||
return roomInfo.getString("schedulename");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUrl() throws ParsingException {
|
||||
return roomInfo.getString("link");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getThumbnailUrl() throws ParsingException {
|
||||
return roomInfo.getString("thumb");
|
||||
}
|
||||
|
||||
@Override
|
||||
public StreamType getStreamType() throws ParsingException {
|
||||
boolean isVideo = false;
|
||||
for (Object stream : roomInfo.getArray("streams")) {
|
||||
if ("video".equals(((JsonObject) stream).getString("type"))) {
|
||||
isVideo = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return isVideo ? StreamType.LIVE_STREAM : StreamType.AUDIO_LIVE_STREAM;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAd() throws ParsingException {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getDuration() throws ParsingException {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getViewCount() throws ParsingException {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUploaderName() throws ParsingException {
|
||||
return conferenceInfo.getString("conference");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUploaderUrl() throws ParsingException {
|
||||
return "https://media.ccc.de/c/" + conferenceInfo.getString("slug");
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getTextualUploadDate() throws ParsingException {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public DateWrapper getUploadDate() throws ParsingException {
|
||||
return null;
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,27 @@
|
|||
package org.schabi.newpipe.extractor.services.media_ccc.linkHandler;
|
||||
|
||||
import org.schabi.newpipe.extractor.exceptions.ParsingException;
|
||||
import org.schabi.newpipe.extractor.linkhandler.ListLinkHandlerFactory;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class MediaCCCLiveStreamListLinkHandlerFactory extends ListLinkHandlerFactory {
|
||||
private static final String streamPattern = "^(https?://)?streaming.media.ccc.de$";
|
||||
|
||||
@Override
|
||||
public String getId(String url) throws ParsingException {
|
||||
return "live";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onAcceptUrl(String url) throws ParsingException {
|
||||
return Pattern.matches(streamPattern, url);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUrl(String id, List<String> contentFilter, String sortFilter) throws ParsingException {
|
||||
// FIXME: wrong URL; should be https://streaming.media.ccc.de/{conference_slug}/{room_slug}
|
||||
return "https://streaming.media.ccc.de/" + id;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
package org.schabi.newpipe.extractor.services.media_ccc;
|
||||
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.schabi.newpipe.DownloaderTestImpl;
|
||||
import org.schabi.newpipe.extractor.InfoItem;
|
||||
import org.schabi.newpipe.extractor.ListExtractor;
|
||||
import org.schabi.newpipe.extractor.NewPipe;
|
||||
import org.schabi.newpipe.extractor.kiosk.KioskExtractor;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.schabi.newpipe.extractor.ServiceList.MediaCCC;
|
||||
|
||||
public class MediaCCCLiveStreamListExtractorTest {
|
||||
private static KioskExtractor extractor;
|
||||
|
||||
@BeforeClass
|
||||
public static void setUpClass() throws Exception {
|
||||
NewPipe.init(DownloaderTestImpl.getInstance());
|
||||
extractor = MediaCCC.getKioskList().getExtractorById("live", null);
|
||||
extractor.fetchPage();
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void getConferencesListTest() throws Exception {
|
||||
final List<InfoItem> a = extractor.getInitialPage().getItems();
|
||||
assertTrue(a.size() > 2);
|
||||
for (int i = 0; i < a.size(); i++) {
|
||||
final InfoItem b = a.get(i);
|
||||
assertNotNull(a.get(i).getName());
|
||||
assertTrue(a.get(i).getName().length() >= 1);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue