Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

189
Views
How to scrape between two (2) dates in time // How to convert Channel and Video ID into URL in script

FYI I have not written this code myself, I've sourced it online via forums like this since it does the job in needs to up to a certain point.

I'm looking to scrape YouTube search results data based on keywords between two dates in time, for example; September 19th - October 4th.

What code and where can I add this to the script?

Here is the script I'm currently using:

function YoutubeScraper() {
  var spreadSheet = SpreadsheetApp.getActiveSpreadsheet()
  var activeSheet = spreadSheet.getActiveSheet();

  // Retrieve YouTube.Search.list.
  var search = YouTube.Search.list("snippet", { q: "Gang Beasts", maxResults: 10 });
  var results = search.items.map((item) => [item.snippet.channelId, item.id.videoId, item.snippet.title, item.snippet.publishedAt]);
  
  // Retrieve channel IDs and video IDs.
  var {channelIds, videoIds} = results.reduce((o, [channelId, videoId]) => {
    o.channelIds.push(channelId);
    o.videoIds.push(videoId);
    return o;
  }, {channelIds: [], videoIds: []});

  // Retrieve YouTube.Videos.list.
  var videoList = YouTube.Videos.list("statistics", {id: videoIds.join(",")});
  var videoStats = videoList.items.map((item) => [item.id, item.statistics.viewCount, item.statistics.likeCount, item.statistics.dislikeCount]).reduce((o, [id, ...v]) => Object.assign(o, {[id]: v}), {});

  // Retrieve YouTube.Channels.list
  var channelList = YouTube.Channels.list("statistics", { id: channelIds.join(",") });
  var channelStats = channelList.items.map((item) => [item.id, item.statistics.subscriberCount]).reduce((o, [id, ...v]) => Object.assign(o, {[id]: v}), {});

  // Create an array for putting values and put the values to Spreadsheet.
  results = results.map(e => channelStats[e[0]] ? e.concat(channelStats[e[0]]) : e.concat(Array(2).fill("")));
  results = results.map(e => videoStats[e[1]] ? e.concat(videoStats[e[1]]) : e.concat(Array(3).fill("")));
  activeSheet.getRange(2, 1, results.length, results[0].length).setValues(results);
}
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!