Skip to content

Commit 1de1f97

Browse files
Royosefwb9688
authored andcommitted
Add parent channel info to StreamExtractor: name, url & avatar url
1 parent 4234740 commit 1de1f97

7 files changed

Lines changed: 176 additions & 6 deletions

File tree

extractor/src/main/java/org/schabi/newpipe/extractor/services/media_ccc/extractors/MediaCCCStreamExtractor.java

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,25 @@ public String getUploaderAvatarUrl() {
112112

113113
@Nonnull
114114
@Override
115-
public String getDashMpdUrl() {
115+
public String getParentChannelUrl() throws ParsingException {
116+
return "";
117+
}
118+
119+
@Nonnull
120+
@Override
121+
public String getParentChannelName() throws ParsingException {
122+
return "";
123+
}
124+
125+
@Nonnull
126+
@Override
127+
public String getParentChannelAvatarUrl() throws ParsingException {
128+
return "";
129+
}
130+
131+
@Nonnull
132+
@Override
133+
public String getDashMpdUrl() throws ParsingException {
116134
return "";
117135
}
118136

extractor/src/main/java/org/schabi/newpipe/extractor/services/peertube/extractors/PeertubeAccountExtractor.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,21 @@ public String getDescription() throws ParsingException {
7575
}
7676
}
7777

78+
@Override
79+
public String getParentChannelName() throws ParsingException {
80+
return "";
81+
}
82+
83+
@Override
84+
public String getParentChannelUrl() throws ParsingException {
85+
return "";
86+
}
87+
88+
@Override
89+
public String getParentChannelAvatarUrl() throws ParsingException {
90+
return "";
91+
}
92+
7893
@Override
7994
public InfoItemsPage<StreamInfoItem> getInitialPage() throws IOException, ExtractionException {
8095
super.fetchPage();

extractor/src/main/java/org/schabi/newpipe/extractor/services/peertube/extractors/PeertubeStreamExtractor.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,29 @@ public String getUploaderAvatarUrl() throws ParsingException {
147147
return baseUrl + value;
148148
}
149149

150+
@Override
151+
public String getParentChannelUrl() throws ParsingException {
152+
return JsonUtils.getString(json, "channel.url");
153+
}
154+
155+
@Nonnull
156+
@Override
157+
public String getParentChannelName() throws ParsingException {
158+
return JsonUtils.getString(json, "channel.displayName");
159+
}
160+
161+
@Nonnull
162+
@Override
163+
public String getParentChannelAvatarUrl() throws ParsingException {
164+
String value;
165+
try {
166+
value = JsonUtils.getString(json, "channel.avatar.path");
167+
} catch (Exception e) {
168+
value = "/client/assets/images/default-avatar.png";
169+
}
170+
return baseUrl + value;
171+
}
172+
150173
@Override
151174
public String getDashMpdUrl() throws ParsingException {
152175
return "";

extractor/src/main/java/org/schabi/newpipe/extractor/services/soundcloud/extractors/SoundcloudStreamExtractor.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,24 @@ public String getUploaderAvatarUrl() {
142142
return SoundcloudParsingHelper.getAvatarUrl(track);
143143
}
144144

145+
@Nonnull
146+
@Override
147+
public String getParentChannelUrl() throws ParsingException {
148+
return "";
149+
}
150+
151+
@Nonnull
152+
@Override
153+
public String getParentChannelName() throws ParsingException {
154+
return "";
155+
}
156+
157+
@Nonnull
158+
@Override
159+
public String getParentChannelAvatarUrl() throws ParsingException {
160+
return "";
161+
}
162+
145163
@Nonnull
146164
@Override
147165
public String getDashMpdUrl() {

extractor/src/main/java/org/schabi/newpipe/extractor/services/youtube/extractors/YoutubeStreamExtractor.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,24 @@ public String getUploaderAvatarUrl() throws ParsingException {
352352
}
353353
}
354354

355+
@Nonnull
356+
@Override
357+
public String getParentChannelUrl() throws ParsingException {
358+
return "";
359+
}
360+
361+
@Nonnull
362+
@Override
363+
public String getParentChannelName() throws ParsingException {
364+
return "";
365+
}
366+
367+
@Nonnull
368+
@Override
369+
public String getParentChannelAvatarUrl() throws ParsingException {
370+
return "";
371+
}
372+
355373
@Nonnull
356374
@Override
357375
public String getDashMpdUrl() throws ParsingException {

extractor/src/main/java/org/schabi/newpipe/extractor/stream/StreamExtractor.java

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,39 @@ public StreamExtractor(StreamingService service, LinkHandler linkHandler) {
178178
@Nonnull
179179
public abstract String getUploaderAvatarUrl() throws ParsingException;
180180

181+
/**
182+
* The Url to the page of the parent chanel of the stream. This must not be a homepage,
183+
* but the page offered by the service the extractor handles. This url will be handled by the
184+
* <a href="https://teamnewpipe.github.io/documentation/03_Implement_a_service/#channel">ChannelExtractor</a>,
185+
* so be sure to implement that one before you return a value here, otherwise NewPipe will crash if one selects
186+
* this url.
187+
*
188+
* @return the url to the page of the parent chanel of the stream or an empty String
189+
* @throws ParsingException
190+
*/
191+
@Nonnull
192+
public abstract String getParentChannelUrl() throws ParsingException;
193+
194+
/**
195+
* The name of the parent chanel of the stream.
196+
* If the name is not available you can simply return an empty string.
197+
*
198+
* @return the name of the parent chanel of the stream or an empty String
199+
* @throws ParsingException
200+
*/
201+
@Nonnull
202+
public abstract String getParentChannelName() throws ParsingException;
203+
204+
/**
205+
* The url to the image file/profile picture/avatar of the parent chanel of the stream.
206+
* If the url is not available you can return an empty String.
207+
*
208+
* @return The url of the image file of the parent chanel or an empty String
209+
* @throws ParsingException
210+
*/
211+
@Nonnull
212+
public abstract String getParentChannelAvatarUrl() throws ParsingException;
213+
181214
/**
182215
* Get the dash mpd url. If you don't know what a dash MPD is you can read about it
183216
* <a href="https://www.brendanlong.com/the-structure-of-an-mpeg-dash-mpd.html">here</a>.

extractor/src/main/java/org/schabi/newpipe/extractor/stream/StreamInfo.java

Lines changed: 50 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -224,27 +224,44 @@ private static StreamInfo extractOptionalData(StreamInfo streamInfo, StreamExtra
224224
streamInfo.addError(e);
225225
}
226226
try {
227-
streamInfo.setDescription(extractor.getDescription());
227+
streamInfo.setUploaderAvatarUrl(extractor.getUploaderAvatarUrl());
228228
} catch (Exception e) {
229229
streamInfo.addError(e);
230230
}
231+
231232
try {
232-
streamInfo.setViewCount(extractor.getViewCount());
233+
streamInfo.setParentChannelName(extractor.getParentChannelName());
233234
} catch (Exception e) {
234235
streamInfo.addError(e);
235236
}
236237
try {
237-
streamInfo.setTextualUploadDate(extractor.getTextualUploadDate());
238+
streamInfo.setParentChannelUrl(extractor.getParentChannelUrl());
238239
} catch (Exception e) {
239240
streamInfo.addError(e);
240241
}
241242
try {
242-
streamInfo.setUploadDate(extractor.getUploadDate());
243+
streamInfo.setParentChannelAvatarUrl(extractor.getParentChannelAvatarUrl());
243244
} catch (Exception e) {
244245
streamInfo.addError(e);
245246
}
247+
246248
try {
247-
streamInfo.setUploaderAvatarUrl(extractor.getUploaderAvatarUrl());
249+
streamInfo.setDescription(extractor.getDescription());
250+
} catch (Exception e) {
251+
streamInfo.addError(e);
252+
}
253+
try {
254+
streamInfo.setViewCount(extractor.getViewCount());
255+
} catch (Exception e) {
256+
streamInfo.addError(e);
257+
}
258+
try {
259+
streamInfo.setTextualUploadDate(extractor.getTextualUploadDate());
260+
} catch (Exception e) {
261+
streamInfo.addError(e);
262+
}
263+
try {
264+
streamInfo.setUploadDate(extractor.getUploadDate());
248265
} catch (Exception e) {
249266
streamInfo.addError(e);
250267
}
@@ -332,6 +349,10 @@ private static StreamInfo extractOptionalData(StreamInfo streamInfo, StreamExtra
332349
private String uploaderUrl = "";
333350
private String uploaderAvatarUrl = "";
334351

352+
private String parentChannelName = "";
353+
private String parentChannelUrl = "";
354+
private String parentChannelAvatarUrl = "";
355+
335356
private List<VideoStream> videoStreams = new ArrayList<>();
336357
private List<AudioStream> audioStreams = new ArrayList<>();
337358
private List<VideoStream> videoOnlyStreams = new ArrayList<>();
@@ -486,6 +507,30 @@ public void setUploaderAvatarUrl(String uploaderAvatarUrl) {
486507
this.uploaderAvatarUrl = uploaderAvatarUrl;
487508
}
488509

510+
public String getParentChannelName() {
511+
return parentChannelName;
512+
}
513+
514+
public void setParentChannelName(String parentChannelName) {
515+
this.parentChannelName = parentChannelName;
516+
}
517+
518+
public String getParentChannelUrl() {
519+
return parentChannelUrl;
520+
}
521+
522+
public void setParentChannelUrl(String parentChannelUrl) {
523+
this.parentChannelUrl = parentChannelUrl;
524+
}
525+
526+
public String getParentChannelAvatarUrl() {
527+
return parentChannelAvatarUrl;
528+
}
529+
530+
public void setParentChannelAvatarUrl(String parentChannelAvatarUrl) {
531+
this.parentChannelAvatarUrl = parentChannelAvatarUrl;
532+
}
533+
489534
public List<VideoStream> getVideoStreams() {
490535
return videoStreams;
491536
}

0 commit comments

Comments
 (0)