mirror of
https://github.com/TeamPiped/Piped-Backend.git
synced 2024-08-14 23:51:41 +00:00
Merge pull request #497 from Bnyro/fix-playlist-import
Don't error out when a video of many is private when adding to playlist
This commit is contained in:
commit
09d538d355
1 changed files with 24 additions and 9 deletions
|
@ -232,6 +232,8 @@ public class AuthPlaylistHandlers {
|
||||||
|
|
||||||
var videos = playlist.getVideos();
|
var videos = playlist.getVideos();
|
||||||
|
|
||||||
|
boolean added = false;
|
||||||
|
|
||||||
for (String videoId : videoIds) {
|
for (String videoId : videoIds) {
|
||||||
if (StringUtils.isEmpty(videoId)) continue;
|
if (StringUtils.isEmpty(videoId)) continue;
|
||||||
|
|
||||||
|
@ -240,6 +242,7 @@ public class AuthPlaylistHandlers {
|
||||||
.orElse(null);
|
.orElse(null);
|
||||||
|
|
||||||
if (video == null) {
|
if (video == null) {
|
||||||
|
try {
|
||||||
StreamInfo info = StreamInfo.getInfo("https://www.youtube.com/watch?v=" + videoId);
|
StreamInfo info = StreamInfo.getInfo("https://www.youtube.com/watch?v=" + videoId);
|
||||||
|
|
||||||
String channelId = StringUtils.substringAfter(info.getUploaderUrl(), "/channel/");
|
String channelId = StringUtils.substringAfter(info.getUploaderUrl(), "/channel/");
|
||||||
|
@ -253,13 +256,25 @@ public class AuthPlaylistHandlers {
|
||||||
video = new PlaylistVideo(videoId, info.getName(), info.getThumbnailUrl(), info.getDuration(), channel);
|
video = new PlaylistVideo(videoId, info.getName(), info.getThumbnailUrl(), info.getDuration(), channel);
|
||||||
|
|
||||||
s.persist(video);
|
s.persist(video);
|
||||||
|
} catch (Exception e) {
|
||||||
|
ExceptionHandler.handle(e);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (playlist.getVideos().isEmpty()) playlist.setThumbnail(video.getThumbnail());
|
if (playlist.getVideos().isEmpty()) playlist.setThumbnail(video.getThumbnail());
|
||||||
|
|
||||||
|
added = true;
|
||||||
|
|
||||||
videos.add(video);
|
videos.add(video);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!added) {
|
||||||
|
// only return an error if no videos were added
|
||||||
|
return mapper.writeValueAsBytes(mapper.createObjectNode()
|
||||||
|
.put("error", "Unable to add any videos, since they were unable to be fetched"));
|
||||||
|
}
|
||||||
|
|
||||||
var tr = s.beginTransaction();
|
var tr = s.beginTransaction();
|
||||||
s.merge(playlist);
|
s.merge(playlist);
|
||||||
tr.commit();
|
tr.commit();
|
||||||
|
|
Loading…
Reference in a new issue