SmartBlocks
SmartBlocks copied to clipboard
Retrieve the list of YouTube videos for a given Playlist ID
✂️ Copy of your #42SmartBlock from Roam
-
#42SmartBlock yt_PlaylistItems
-
<%NOBLOCKOUTPUT%><%JAVASCRIPTASYNC: ```javascript // Enter YouTube Playlist ID. // In the link below, ID is what comes after "?list=", which is // "PLRpUYjB1LkA9QcI5uhH-ldV0rTqhi54sv" // https://www.youtube.com/playlist?list=PLRpUYjB1LkA9QcI5uhH-ldV0rTqhi54sv var playlistLookUp = encodeURIComponent(prompt('Enter YouTube Playlist ID.')); // Get your API from Google API Console var apiKey = 'Your API' var url = "https://youtube.googleapis.com/youtube/v3/playlistItems?part=snippet%2CcontentDetails&maxResults=3&playlistId=" + playlistLookUp + "&key="+apiKey; var responseText = $.ajax({url:url, type:"GET", async:false,}).responseText; var data = JSON.parse(responseText); var playlistItems = data.items var videoSnippet = playlistItems[0].snippet // Insert the link to the YouTube playlist await roam42.smartBlocks.activeWorkflow.outputAdditionalBlock( "**Link to Playlist:** " + "https://www.youtube.com/playlist?list=" + playlistLookUp ); // Print the description of the playlist await roam42.smartBlocks.activeWorkflow.outputAdditionalBlock( "**Playlist Description:** " + videoSnippet.description ); for(idx in playlistItems) { videoSnippet = playlistItems[idx].snippet var videoContentDetails = playlistItems[idx].contentDetails // Print the title of the video await roam42.smartBlocks.activeWorkflow.outputAdditionalBlock( videoSnippet.title ); // Date the video published in YouTube await roam42.smartBlocks.activeWorkflow.outputAdditionalBlock( "Published: " + (videoContentDetails.videoPublishedAt).substring(0,10) ); // Placeholder for transcript of the video await roam42.smartBlocks.activeWorkflow.outputAdditionalBlock( "[[Transcript: " + videoSnippet.title + "]]" ); // Insert a link for the YouTube video await roam42.smartBlocks.activeWorkflow.outputAdditionalBlock( "{{[[youtube]]:" + "https://www.youtube.com/watch?v=" + videoContentDetails.videoId + "}}" ); } return '';``` %>
-
📋 Describe the SmartBlock
It inserts the list of YouTube videos for a given Playlist ID.
✅ Describe any prerequisites or dependencies that are required for this SmartBlock
YouTube API Key is required and it can be obtained from Google's API Console.
📷 Screenshot of your #42SmartBlock workflow/template from Roam
💡 Additional Info
Up to 50 videos can be retrieved. YouTube link is intentionally commented to reduce the loading time. Remove `` from the link when you watch videos.
Hi, `thank you for your thoughtful contribution, I have a problem using it though, it seems that each block is replacing the previous block and I get the last video of the playlist and not the fully populated style like yours. could you please guide me in troubleshooting this? Here's a video:
https://user-images.githubusercontent.com/64003499/103233863-d9782480-4946-11eb-9d59-c2583e68aedb.mov
Hi, `thank you for your thoughtful contribution, I have a problem using it though, it seems that each block is replacing the previous block and I get the last video of the playlist and not the fully populated style like yours. could you please guide me in troubleshooting this? Here's a video:
youtube.playlist.mov
Updated the code to accommodate the recent changes in SmartBlock.
Thanks it is working but is limited to 3 videos.