Youtube embed link made easy with Appscript

My need

Well, It turned out that I needed one app where I could add youtube links and watch them inside the App. I was able to do that but I always needed to get the embed link, which was a pain in the neck. Then I thought:
"What if I could just paste the link of the video and run a scrip that extracts its embed link?"

Setting the Appsheet columns

  1. In your database you must have one column for the Youtube link and anotther one for the Embed link. 
  2. Set them as a TEXT column and not a URL column (it is important)
  3. Create an empty Virtual Column with the following formula "" type show and set the content to the embed link column, as Video Category. As below:
    peterson_0-1696509471011.png

    *** It is important to have in mind the SHOW columns will only appear in detail views if you set it in the Column order.

Appscript and automation

1. Go to your google drive and create a Appscript

peterson_1-1696509964788.png

2. Copy the following link:

function converterLinkParaEmbed(link) {
  // Check if the link is working on YouTube
  var regExp = /(?:https?:\/\/)?(?:www\.)?(?:youtube\.com|youtu\.be)\/(?:watch\?v=)?(.+)/;
  var match = link.match(regExp);
 
  if (match) {
    var videoId = match[1];
    var embedLink = "https://www.youtube.com/embed/" + videoId;
    return embedLink;
  } else {
    return "Link do YouTube invรกlido";
  }
}

Name your file the way you want and save it.

3. Create a BOT automation. The event you choose. I set it as follow:

peterson_2-1696510164351.png

4. In the process Follow the steps:
choose call a script >> Table name >> Searc and select the Script you created >> Give permissions >> Function Paramenter = The Youtube link column >> Return Value = String >> Specific type = URL

5. Create a new step and set just like that:

peterson_3-1696510585248.png

In Set these column(s) choose the embed link column and and use the formula

peterson_4-1696510717961.png

In my case it is [new step].[Output] because this is my process name, it may vary depending on its name. 

Result

No need to check for embed links anymore and I can add any video from youtube for every particular entry.

peterson_5-1696511055703.png

peterson_6-1696511172596.pngpeterson_7-1696511191291.png

PS: Do not show the embed link for people might "break" it in your app.

 

 

0 REPLIES 0
Top Labels in this Space