Oct 29, 2023 03:43 PM - edited Oct 29, 2023 03:44 PM
Hi,
I want a URL field to create automaticly with YouTube videos from Field A and Field B.
Field A is song title, and Field B is artist, and I need a URL that automaticly finds the music video of that song.
Let's use Hello - Lionel Ritchie as an example.
I do not need the URL to be YouTube Search (https://www.youtube.com/results?search_query=hello+lionel+richie) But i need the URL to guide me straight to the music video: https://www.youtube.com/watch?v=mHONNcZbwDY
Is this possible?
Oct 29, 2023 06:16 PM - edited Oct 29, 2023 06:17 PM
Unfortunately, there is no quick or easy way to do this.
You would need to write your own custom programming code for this, by tapping into YouTube's REST API that lets you search for videos by using its "Search: List" REST API command.
RapidAPI might make this a little bit easier, by letting you tap into some of their preconfigured YouTube search API's.
In Airtable, there are at least 3 different ways that you can tap into REST APIs:
1. High-code: Writing your own custom Javascript scripts in Airtable.
2. Medium-code: Using DataFetcher.com
3. Low-code: Using Make's HTTP Module. There is a small learning curve with Make, which is why I created this basic navigation video to help.
p.s. If you have a budget for your project and you’d like to hire an expert Airtable consultant to help you with any of this, please feel free to contact me through my website: Airtable consulting — ScottWorld
Oct 29, 2023 11:26 PM
Hi @Andreas_Tystad , I came up with the automation script to try.
Youtube was not able to extract the URL because to Script driven, so I extracted the first Youtube link from the Google search results.
let {keywords} = input.config();
let response = await fetch(`https://www.google.com/search?q=${keywords}&tbm=vid`)
.then(response => {
if (!response.ok) {
throw new Error('Network Error: ' + response.status);
}
return response.text(); // Get the response body as text
})
.then(html => {
const match = /<a[^>]*href="\/url\?q=(https:\/\/www.youtube.com\/watch[^"']+)["'][^>]*>/i.exec(html);
if (match) {
const href = match[1];
output.set("url",decodeURIComponent(href));
} else {
console.error('No matching <a> tag found in the HTML.');
}
})
.catch(error => {
console.error('An error occurred: ', error);
});
If it helps, here you are.
Oct 30, 2023 01:26 AM
Thank you! How do I put this into use? Do I use the Script extension?
Oct 30, 2023 07:33 AM
This is an Automations script.
Be careful when setting up the trigger, as it will consume a lot of counts if it is triggered simply by updating Keywords.
For more information about automation, please refer to here.
Airtable Automations