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();
 | 
			
		||||
 | 
			
		||||
            boolean added = false;
 | 
			
		||||
 | 
			
		||||
            for (String videoId : videoIds) {
 | 
			
		||||
                if (StringUtils.isEmpty(videoId)) continue;
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -240,26 +242,39 @@ public class AuthPlaylistHandlers {
 | 
			
		|||
                        .orElse(null);
 | 
			
		||||
 | 
			
		||||
                if (video == null) {
 | 
			
		||||
                    StreamInfo info = StreamInfo.getInfo("https://www.youtube.com/watch?v=" + videoId);
 | 
			
		||||
                    try {
 | 
			
		||||
                        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/");
 | 
			
		||||
 | 
			
		||||
                    var channel = DatabaseHelper.getChannelFromId(s, channelId);
 | 
			
		||||
                        var channel = DatabaseHelper.getChannelFromId(s, channelId);
 | 
			
		||||
 | 
			
		||||
                    if (channel == null) {
 | 
			
		||||
                        channel = DatabaseHelper.saveChannel(channelId);
 | 
			
		||||
                        if (channel == null) {
 | 
			
		||||
                            channel = DatabaseHelper.saveChannel(channelId);
 | 
			
		||||
                        }
 | 
			
		||||
 | 
			
		||||
                        video = new PlaylistVideo(videoId, info.getName(), info.getThumbnailUrl(), info.getDuration(), channel);
 | 
			
		||||
 | 
			
		||||
                        s.persist(video);
 | 
			
		||||
                    } catch (Exception e) {
 | 
			
		||||
                        ExceptionHandler.handle(e);
 | 
			
		||||
                        continue;
 | 
			
		||||
                    }
 | 
			
		||||
 | 
			
		||||
                    video = new PlaylistVideo(videoId, info.getName(), info.getThumbnailUrl(), info.getDuration(), channel);
 | 
			
		||||
 | 
			
		||||
                    s.persist(video);
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                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();
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue