mirror of
https://github.com/TeamPiped/Piped-Backend.git
synced 2024-08-14 23:51:41 +00:00
Refractor repeated code.
This commit is contained in:
parent
006d3d3d2b
commit
d6a2d92eeb
1 changed files with 18 additions and 54 deletions
|
@ -174,13 +174,7 @@ public class ResponseHelper {
|
||||||
|
|
||||||
final List<StreamItem> relatedStreams = new ObjectArrayList<>();
|
final List<StreamItem> relatedStreams = new ObjectArrayList<>();
|
||||||
|
|
||||||
info.getRelatedItems().forEach(o -> {
|
info.getRelatedItems().forEach(o -> relatedStreams.add(collectRelatedStream(o)));
|
||||||
StreamInfoItem item = (StreamInfoItem) o;
|
|
||||||
relatedStreams.add(new StreamItem(substringYouTube(item.getUrl()), item.getName(),
|
|
||||||
rewriteURL(item.getThumbnailUrl()), item.getUploaderName(), substringYouTube(item.getUploaderUrl()),
|
|
||||||
rewriteURL(item.getUploaderAvatarUrl()), item.getTextualUploadDate(), item.getDuration(),
|
|
||||||
item.getViewCount(), item.isUploaderVerified()));
|
|
||||||
});
|
|
||||||
|
|
||||||
List<ChapterSegment> segments = new ObjectArrayList<>();
|
List<ChapterSegment> segments = new ObjectArrayList<>();
|
||||||
|
|
||||||
|
@ -210,13 +204,7 @@ public class ResponseHelper {
|
||||||
|
|
||||||
final List<StreamItem> relatedStreams = new ObjectArrayList<>();
|
final List<StreamItem> relatedStreams = new ObjectArrayList<>();
|
||||||
|
|
||||||
info.getRelatedItems().forEach(o -> {
|
info.getRelatedItems().forEach(o -> relatedStreams.add(collectRelatedStream(o)));
|
||||||
StreamInfoItem item = o;
|
|
||||||
relatedStreams.add(new StreamItem(substringYouTube(item.getUrl()), item.getName(),
|
|
||||||
rewriteURL(item.getThumbnailUrl()), item.getUploaderName(), substringYouTube(item.getUploaderUrl()),
|
|
||||||
rewriteURL(item.getUploaderAvatarUrl()), item.getTextualUploadDate(), item.getDuration(),
|
|
||||||
item.getViewCount(), item.isUploaderVerified()));
|
|
||||||
});
|
|
||||||
|
|
||||||
Multithreading.runAsync(() -> {
|
Multithreading.runAsync(() -> {
|
||||||
Session s = DatabaseSessionFactory.createSession();
|
Session s = DatabaseSessionFactory.createSession();
|
||||||
|
@ -270,13 +258,7 @@ public class ResponseHelper {
|
||||||
|
|
||||||
final List<StreamItem> relatedStreams = new ObjectArrayList<>();
|
final List<StreamItem> relatedStreams = new ObjectArrayList<>();
|
||||||
|
|
||||||
info.getItems().forEach(o -> {
|
info.getItems().forEach(o -> relatedStreams.add(collectRelatedStream(o)));
|
||||||
StreamInfoItem item = o;
|
|
||||||
relatedStreams.add(new StreamItem(substringYouTube(item.getUrl()), item.getName(),
|
|
||||||
rewriteURL(item.getThumbnailUrl()), item.getUploaderName(), substringYouTube(item.getUploaderUrl()),
|
|
||||||
rewriteURL(item.getUploaderAvatarUrl()), item.getTextualUploadDate(), item.getDuration(),
|
|
||||||
item.getViewCount(), item.isUploaderVerified()));
|
|
||||||
});
|
|
||||||
|
|
||||||
String nextpage = null;
|
String nextpage = null;
|
||||||
if (info.hasNextPage()) {
|
if (info.hasNextPage()) {
|
||||||
|
@ -304,13 +286,7 @@ public class ResponseHelper {
|
||||||
extractor.fetchPage();
|
extractor.fetchPage();
|
||||||
KioskInfo info = KioskInfo.getInfo(extractor);
|
KioskInfo info = KioskInfo.getInfo(extractor);
|
||||||
|
|
||||||
info.getRelatedItems().forEach(o -> {
|
info.getRelatedItems().forEach(o -> relatedStreams.add(collectRelatedStream(o)));
|
||||||
StreamInfoItem item = o;
|
|
||||||
relatedStreams.add(new StreamItem(substringYouTube(item.getUrl()), item.getName(),
|
|
||||||
rewriteURL(item.getThumbnailUrl()), item.getUploaderName(), substringYouTube(item.getUploaderUrl()),
|
|
||||||
rewriteURL(item.getUploaderAvatarUrl()), item.getTextualUploadDate(), item.getDuration(),
|
|
||||||
item.getViewCount(), item.isUploaderVerified()));
|
|
||||||
});
|
|
||||||
|
|
||||||
return Constants.mapper.writeValueAsBytes(relatedStreams);
|
return Constants.mapper.writeValueAsBytes(relatedStreams);
|
||||||
}
|
}
|
||||||
|
@ -322,13 +298,7 @@ public class ResponseHelper {
|
||||||
|
|
||||||
final List<StreamItem> relatedStreams = new ObjectArrayList<>();
|
final List<StreamItem> relatedStreams = new ObjectArrayList<>();
|
||||||
|
|
||||||
info.getRelatedItems().forEach(o -> {
|
info.getRelatedItems().forEach(o -> relatedStreams.add(collectRelatedStream(o)));
|
||||||
StreamInfoItem item = o;
|
|
||||||
relatedStreams.add(new StreamItem(substringYouTube(item.getUrl()), item.getName(),
|
|
||||||
rewriteURL(item.getThumbnailUrl()), item.getUploaderName(), substringYouTube(item.getUploaderUrl()),
|
|
||||||
rewriteURL(item.getUploaderAvatarUrl()), item.getTextualUploadDate(), item.getDuration(),
|
|
||||||
item.getViewCount(), item.isUploaderVerified()));
|
|
||||||
});
|
|
||||||
|
|
||||||
String nextpage = null;
|
String nextpage = null;
|
||||||
if (info.hasNextPage()) {
|
if (info.hasNextPage()) {
|
||||||
|
@ -356,13 +326,7 @@ public class ResponseHelper {
|
||||||
|
|
||||||
final List<StreamItem> relatedStreams = new ObjectArrayList<>();
|
final List<StreamItem> relatedStreams = new ObjectArrayList<>();
|
||||||
|
|
||||||
info.getItems().forEach(o -> {
|
info.getItems().forEach(o -> relatedStreams.add(collectRelatedStream(o)));
|
||||||
StreamInfoItem item = o;
|
|
||||||
relatedStreams.add(new StreamItem(substringYouTube(item.getUrl()), item.getName(),
|
|
||||||
rewriteURL(item.getThumbnailUrl()), item.getUploaderName(), substringYouTube(item.getUploaderUrl()),
|
|
||||||
rewriteURL(item.getUploaderAvatarUrl()), item.getTextualUploadDate(), item.getDuration(),
|
|
||||||
item.getViewCount(), item.isUploaderVerified()));
|
|
||||||
});
|
|
||||||
|
|
||||||
String nextpage = null;
|
String nextpage = null;
|
||||||
if (info.hasNextPage()) {
|
if (info.hasNextPage()) {
|
||||||
|
@ -424,12 +388,7 @@ public class ResponseHelper {
|
||||||
info.getRelatedItems().forEach(item -> {
|
info.getRelatedItems().forEach(item -> {
|
||||||
switch (item.getInfoType()) {
|
switch (item.getInfoType()) {
|
||||||
case STREAM:
|
case STREAM:
|
||||||
StreamInfoItem stream = (StreamInfoItem) item;
|
items.add(collectRelatedStream(item));
|
||||||
items.add(new StreamItem(substringYouTube(stream.getUrl()), stream.getName(),
|
|
||||||
rewriteURL(stream.getThumbnailUrl()), stream.getUploaderName(),
|
|
||||||
substringYouTube(stream.getUploaderUrl()), rewriteURL(stream.getUploaderAvatarUrl()),
|
|
||||||
stream.getTextualUploadDate(), stream.getDuration(), stream.getViewCount(),
|
|
||||||
stream.isUploaderVerified()));
|
|
||||||
break;
|
break;
|
||||||
case CHANNEL:
|
case CHANNEL:
|
||||||
ChannelInfoItem channel = (ChannelInfoItem) item;
|
ChannelInfoItem channel = (ChannelInfoItem) item;
|
||||||
|
@ -468,12 +427,7 @@ public class ResponseHelper {
|
||||||
pages.getItems().forEach(item -> {
|
pages.getItems().forEach(item -> {
|
||||||
switch (item.getInfoType()) {
|
switch (item.getInfoType()) {
|
||||||
case STREAM:
|
case STREAM:
|
||||||
StreamInfoItem stream = (StreamInfoItem) item;
|
items.add(collectRelatedStream(item));
|
||||||
items.add(new StreamItem(substringYouTube(stream.getUrl()), stream.getName(),
|
|
||||||
rewriteURL(stream.getThumbnailUrl()), stream.getUploaderName(),
|
|
||||||
substringYouTube(stream.getUploaderUrl()), rewriteURL(stream.getUploaderAvatarUrl()),
|
|
||||||
stream.getTextualUploadDate(), stream.getDuration(), stream.getViewCount(),
|
|
||||||
stream.isUploaderVerified()));
|
|
||||||
break;
|
break;
|
||||||
case CHANNEL:
|
case CHANNEL:
|
||||||
ChannelInfoItem channel = (ChannelInfoItem) item;
|
ChannelInfoItem channel = (ChannelInfoItem) item;
|
||||||
|
@ -1091,6 +1045,16 @@ public class ResponseHelper {
|
||||||
return s == null || s.isEmpty() ? null : StringUtils.substringAfter(s, "youtube.com");
|
return s == null || s.isEmpty() ? null : StringUtils.substringAfter(s, "youtube.com");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static StreamItem collectRelatedStream(Object o) {
|
||||||
|
|
||||||
|
StreamInfoItem item = (StreamInfoItem) o;
|
||||||
|
|
||||||
|
return new StreamItem(substringYouTube(item.getUrl()), item.getName(), rewriteURL(item.getThumbnailUrl()),
|
||||||
|
item.getUploaderName(), substringYouTube(item.getUploaderUrl()),
|
||||||
|
rewriteURL(item.getUploaderAvatarUrl()), item.getTextualUploadDate(), item.getDuration(),
|
||||||
|
item.getViewCount(), item.isUploaderVerified());
|
||||||
|
}
|
||||||
|
|
||||||
private static String rewriteURL(final String old) {
|
private static String rewriteURL(final String old) {
|
||||||
|
|
||||||
if (Constants.debug)
|
if (Constants.debug)
|
||||||
|
|
Loading…
Reference in a new issue