|
1 | 1 | package org.schabi.newpipe.extractor.services.media_ccc.extractors; |
2 | 2 |
|
| 3 | +import com.grack.nanojson.JsonArray; |
3 | 4 | import com.grack.nanojson.JsonObject; |
| 5 | +import org.schabi.newpipe.extractor.MediaFormat; |
| 6 | +import org.schabi.newpipe.extractor.MetaInfo; |
| 7 | +import org.schabi.newpipe.extractor.StreamingService; |
| 8 | +import org.schabi.newpipe.extractor.downloader.Downloader; |
| 9 | +import org.schabi.newpipe.extractor.exceptions.ExtractionException; |
4 | 10 | import org.schabi.newpipe.extractor.exceptions.ParsingException; |
| 11 | +import org.schabi.newpipe.extractor.linkhandler.LinkHandler; |
5 | 12 | import org.schabi.newpipe.extractor.localization.DateWrapper; |
6 | | -import org.schabi.newpipe.extractor.stream.StreamInfoItemExtractor; |
7 | | -import org.schabi.newpipe.extractor.stream.StreamType; |
| 13 | +import org.schabi.newpipe.extractor.stream.*; |
8 | 14 |
|
| 15 | +import javax.annotation.Nonnull; |
9 | 16 | import javax.annotation.Nullable; |
| 17 | +import java.io.IOException; |
| 18 | +import java.util.ArrayList; |
| 19 | +import java.util.Collections; |
| 20 | +import java.util.List; |
| 21 | +import java.util.Locale; |
10 | 22 |
|
11 | | -public class MediaCCCLiveStreamExtractor implements StreamInfoItemExtractor { |
| 23 | +public class MediaCCCLiveStreamExtractor extends StreamExtractor { |
| 24 | + private JsonArray doc = null; |
| 25 | + private JsonObject conference = null; |
| 26 | + private String group = ""; |
| 27 | + private JsonObject room = null; |
12 | 28 |
|
13 | | - private final JsonObject conferenceInfo; |
14 | | - private final String group; |
15 | | - private final JsonObject roomInfo; |
| 29 | + public MediaCCCLiveStreamExtractor(StreamingService service, LinkHandler linkHandler) { |
| 30 | + super(service, linkHandler); |
| 31 | + } |
16 | 32 |
|
17 | | - public MediaCCCLiveStreamExtractor(JsonObject conferenceInfo, String group, JsonObject roomInfo) { |
18 | | - this.conferenceInfo = conferenceInfo; |
19 | | - this.group = group; |
20 | | - this.roomInfo = roomInfo; |
| 33 | + @Override |
| 34 | + public void onFetchPage(@Nonnull Downloader downloader) throws IOException, ExtractionException { |
| 35 | + doc = MediaCCCParsingHelper.getLiveStreams(downloader, getExtractorLocalization()); |
| 36 | + // find correct room |
| 37 | + for (int c = 0; c < doc.size(); c++) { |
| 38 | + final JsonObject conference = doc.getObject(c); |
| 39 | + final JsonArray groups = conference.getArray("groups"); |
| 40 | + for (int g = 0; g < groups.size(); g++) { |
| 41 | + final String group = groups.getObject(g).getString("group"); |
| 42 | + final JsonArray rooms = groups.getObject(g).getArray("rooms"); |
| 43 | + for (int r = 0; r < rooms.size(); r++) { |
| 44 | + final JsonObject room = rooms.getObject(r); |
| 45 | + if (getId().equals(conference.getString("slug") + "/" + room.getString("slug"))) { |
| 46 | + this.conference = conference; |
| 47 | + this.group = group; |
| 48 | + this.room = room; |
| 49 | + return; |
| 50 | + } |
| 51 | + } |
| 52 | + } |
| 53 | + } |
| 54 | + throw new ExtractionException("Could not find room matching id: '" + getId() + "'"); |
21 | 55 | } |
22 | 56 |
|
| 57 | + @Nonnull |
23 | 58 | @Override |
24 | 59 | public String getName() throws ParsingException { |
25 | | - return roomInfo.getString("schedulename"); |
| 60 | + return room.getString("display"); |
| 61 | + } |
| 62 | + |
| 63 | + @Nullable |
| 64 | + @Override |
| 65 | + public String getTextualUploadDate() throws ParsingException { |
| 66 | + return null; |
26 | 67 | } |
27 | 68 |
|
| 69 | + @Nullable |
28 | 70 | @Override |
29 | | - public String getUrl() throws ParsingException { |
30 | | - return roomInfo.getString("link"); |
| 71 | + public DateWrapper getUploadDate() throws ParsingException { |
| 72 | + return null; |
31 | 73 | } |
32 | 74 |
|
| 75 | + @Nonnull |
33 | 76 | @Override |
34 | 77 | public String getThumbnailUrl() throws ParsingException { |
35 | | - return roomInfo.getString("thumb"); |
| 78 | + return room.getString("thumb"); |
36 | 79 | } |
37 | 80 |
|
| 81 | + @Nonnull |
38 | 82 | @Override |
39 | | - public StreamType getStreamType() throws ParsingException { |
40 | | - boolean isVideo = false; |
41 | | - for (Object stream : roomInfo.getArray("streams")) { |
42 | | - if ("video".equals(((JsonObject) stream).getString("type"))) { |
43 | | - isVideo = true; |
44 | | - break; |
45 | | - } |
46 | | - } |
47 | | - return isVideo ? StreamType.LIVE_STREAM : StreamType.AUDIO_LIVE_STREAM; |
| 83 | + public Description getDescription() throws ParsingException { |
| 84 | + return new Description(conference.getString("description") + " - " + group, Description.PLAIN_TEXT); |
48 | 85 | } |
49 | 86 |
|
50 | 87 | @Override |
51 | | - public boolean isAd() throws ParsingException { |
52 | | - return false; |
| 88 | + public int getAgeLimit() { |
| 89 | + return 0; |
| 90 | + } |
| 91 | + |
| 92 | + @Override |
| 93 | + public long getLength() { |
| 94 | + return 0; |
53 | 95 | } |
54 | 96 |
|
55 | 97 | @Override |
56 | | - public long getDuration() throws ParsingException { |
| 98 | + public long getTimeStamp() throws ParsingException { |
57 | 99 | return 0; |
58 | 100 | } |
59 | 101 |
|
60 | 102 | @Override |
61 | | - public long getViewCount() throws ParsingException { |
| 103 | + public long getViewCount() { |
62 | 104 | return -1; |
63 | 105 | } |
64 | 106 |
|
65 | 107 | @Override |
66 | | - public String getUploaderName() throws ParsingException { |
67 | | - return conferenceInfo.getString("conference"); |
| 108 | + public long getLikeCount() { |
| 109 | + return -1; |
| 110 | + } |
| 111 | + |
| 112 | + @Override |
| 113 | + public long getDislikeCount() { |
| 114 | + return -1; |
68 | 115 | } |
69 | 116 |
|
| 117 | + @Nonnull |
70 | 118 | @Override |
71 | 119 | public String getUploaderUrl() throws ParsingException { |
72 | | - return "https://media.ccc.de/c/" + conferenceInfo.getString("slug"); |
| 120 | + return "https://streaming.media.ccc.de/" + conference.getString("slug"); |
| 121 | + } |
| 122 | + |
| 123 | + @Nonnull |
| 124 | + @Override |
| 125 | + public String getUploaderName() throws ParsingException { |
| 126 | + return conference.getString("conference"); |
| 127 | + } |
| 128 | + |
| 129 | + @Nonnull |
| 130 | + @Override |
| 131 | + public String getUploaderAvatarUrl() { |
| 132 | + return ""; |
| 133 | + } |
| 134 | + |
| 135 | + @Nonnull |
| 136 | + @Override |
| 137 | + public String getSubChannelUrl() { |
| 138 | + return ""; |
| 139 | + } |
| 140 | + |
| 141 | + @Nonnull |
| 142 | + @Override |
| 143 | + public String getSubChannelName() { |
| 144 | + return ""; |
| 145 | + } |
| 146 | + |
| 147 | + @Nonnull |
| 148 | + @Override |
| 149 | + public String getSubChannelAvatarUrl() { |
| 150 | + return ""; |
| 151 | + } |
| 152 | + |
| 153 | + @Nonnull |
| 154 | + @Override |
| 155 | + public String getDashMpdUrl() throws ParsingException { |
| 156 | + return ""; |
| 157 | + } |
| 158 | + |
| 159 | + @Nonnull |
| 160 | + @Override |
| 161 | + public String getHlsUrl() { |
| 162 | + // TODO: There are multiple HLS streams. |
| 163 | + // Make getHlsUrl() and getDashMpdUrl() return lists of VideoStreams, so the user can choose a resolution. |
| 164 | + for (int s = 0; s < room.getArray("streams").size(); s++) { |
| 165 | + final JsonObject stream = room.getArray("streams").getObject(s); |
| 166 | + if (stream.getString("type").equals("video")) { |
| 167 | + final String resolution = stream.getArray("videoSize").getInt(0) + "x" |
| 168 | + + stream.getArray("videoSize").getInt(1); |
| 169 | + if (stream.has("hls")) { |
| 170 | + return stream.getObject("urls").getObject("hls").getString("url"); |
| 171 | + } |
| 172 | + } |
| 173 | + } |
| 174 | + return ""; |
| 175 | + } |
| 176 | + |
| 177 | + @Override |
| 178 | + public List<AudioStream> getAudioStreams() throws IOException, ExtractionException { |
| 179 | + final List<AudioStream> audioStreams = new ArrayList<>(); |
| 180 | + for (int s = 0; s < room.getArray("streams").size(); s++) { |
| 181 | + final JsonObject stream = room.getArray("streams").getObject(s); |
| 182 | + if (stream.getString("type").equals("audio")) { |
| 183 | + for (final String type :stream.getObject("urls").keySet()) { |
| 184 | + final JsonObject url = stream.getObject("urls").getObject(type); |
| 185 | + audioStreams.add(new AudioStream(url.getString("url"), MediaFormat.getFromSuffix(type), -1)); |
| 186 | + } |
| 187 | + } |
| 188 | + } |
| 189 | + return audioStreams; |
| 190 | + } |
| 191 | + |
| 192 | + @Override |
| 193 | + public List<VideoStream> getVideoStreams() throws IOException, ExtractionException { |
| 194 | + final List<VideoStream> videoStreams = new ArrayList<>(); |
| 195 | + for (int s = 0; s < room.getArray("streams").size(); s++) { |
| 196 | + final JsonObject stream = room.getArray("streams").getObject(s); |
| 197 | + if (stream.getString("type").equals("video")) { |
| 198 | + final String resolution = stream.getArray("videoSize").getInt(0) + "x" |
| 199 | + + stream.getArray("videoSize").getInt(1); |
| 200 | + for (final String type :stream.getObject("urls").keySet()) { |
| 201 | + if (!type.equals("hls")) { |
| 202 | + final JsonObject url = stream.getObject("urls").getObject(type); |
| 203 | + videoStreams.add(new VideoStream( |
| 204 | + url.getString("url"), |
| 205 | + MediaFormat.getFromSuffix(type), |
| 206 | + resolution)); |
| 207 | + } |
| 208 | + } |
| 209 | + } |
| 210 | + } |
| 211 | + return videoStreams; |
| 212 | + } |
| 213 | + |
| 214 | + @Override |
| 215 | + public List<VideoStream> getVideoOnlyStreams() throws IOException, ExtractionException { |
| 216 | + return null; |
| 217 | + } |
| 218 | + |
| 219 | + @Nonnull |
| 220 | + @Override |
| 221 | + public List<SubtitlesStream> getSubtitlesDefault(){ |
| 222 | + return Collections.emptyList(); |
| 223 | + } |
| 224 | + |
| 225 | + @Nonnull |
| 226 | + @Override |
| 227 | + public List<SubtitlesStream> getSubtitles(MediaFormat format) { |
| 228 | + return Collections.emptyList(); |
| 229 | + } |
| 230 | + |
| 231 | + @Override |
| 232 | + public StreamType getStreamType() throws ParsingException { |
| 233 | + return StreamType.LIVE_STREAM; // TODO: video and audio only streams are both available |
73 | 234 | } |
74 | 235 |
|
75 | 236 | @Nullable |
76 | 237 | @Override |
77 | | - public String getTextualUploadDate() throws ParsingException { |
| 238 | + public StreamInfoItemsCollector getRelatedStreams() { |
| 239 | + return null; |
| 240 | + } |
| 241 | + |
| 242 | + @Override |
| 243 | + public String getErrorMessage() { |
78 | 244 | return null; |
79 | 245 | } |
80 | 246 |
|
| 247 | + @Nonnull |
| 248 | + @Override |
| 249 | + public String getHost() throws ParsingException { |
| 250 | + return null; |
| 251 | + } |
| 252 | + |
| 253 | + @Nonnull |
| 254 | + @Override |
| 255 | + public String getPrivacy() { |
| 256 | + return "Public"; |
| 257 | + } |
| 258 | + |
| 259 | + @Nonnull |
| 260 | + @Override |
| 261 | + public String getCategory() { |
| 262 | + return group; |
| 263 | + } |
| 264 | + |
| 265 | + @Nonnull |
| 266 | + @Override |
| 267 | + public String getLicence() { |
| 268 | + return ""; |
| 269 | + } |
| 270 | + |
81 | 271 | @Nullable |
82 | 272 | @Override |
83 | | - public DateWrapper getUploadDate() throws ParsingException { |
| 273 | + public Locale getLanguageInfo() { |
84 | 274 | return null; |
85 | 275 | } |
| 276 | + |
| 277 | + @Nonnull |
| 278 | + @Override |
| 279 | + public List<String> getTags() { |
| 280 | + return Collections.emptyList(); |
| 281 | + } |
| 282 | + |
| 283 | + @Nonnull |
| 284 | + @Override |
| 285 | + public String getSupportInfo() { |
| 286 | + return ""; |
| 287 | + } |
| 288 | + |
| 289 | + @Nonnull |
| 290 | + @Override |
| 291 | + public List<StreamSegment> getStreamSegments() { |
| 292 | + return Collections.emptyList(); |
| 293 | + } |
| 294 | + |
| 295 | + @Nonnull |
| 296 | + @Override |
| 297 | + public List<MetaInfo> getMetaInfo() { |
| 298 | + return Collections.emptyList(); |
| 299 | + } |
86 | 300 | } |
0 commit comments