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:
Kavin 2023-01-02 21:00:32 +00:00 committed by GitHub
commit 09d538d355
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -232,6 +232,8 @@ public class AuthPlaylistHandlers {
var videos = playlist.getVideos();
boolean added = false;
for (String videoId : videoIds) {
if (StringUtils.isEmpty(videoId)) continue;
@ -240,6 +242,7 @@ public class AuthPlaylistHandlers {
.orElse(null);
if (video == null) {
try {
StreamInfo info = StreamInfo.getInfo("https://www.youtube.com/watch?v=" + videoId);
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);
s.persist(video);
} catch (Exception e) {
ExceptionHandler.handle(e);
continue;
}
}
if (playlist.getVideos().isEmpty()) playlist.setThumbnail(video.getThumbnail());
added = true;
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();
s.merge(playlist);
tr.commit();