JavaScript Mapping Library
Probably around twenty years ago, I was walking around the house when a commercial on TV stopped me in my tracks. It was some dumb commercial for Coors and very much a typical beer commercial, but halfway through the ad the song morphed into another, and both songs played together. I didn’t know it at the time, but it was an example of the mashup genre. As a genre, mashups have been around since the late 60s so it definitely wasn’t even new back then, but I’ve been fascinated by them for quite some time. (If you’re curious, this track is probably my favorite.)
While I love the genre, I don’t really have a great way of keeping up with the latest releases. That’s 100% my laziness of course, but I thought it might be a good way to use automation to bring me new tracks when I’m in the mood. SearchApi is an API provider that wraps multiple different search engines and sites and provides a programmatic way to get data. While they highlight wrapping Google search most prominently, their APIs cover a wealth of different services, including Amazon, Reddit, YouTube, TikTok and more.
I thought I’d build a simple web app that would do the following:
If you don’t care about how it was built, you can check out the dashboard here: Fresh Cuts.
As I mentioned above, my dashboard is created from two sources, TikTok and YouTube. Let’s start with TikTok. The TikTok Search API is relatively simple. Make a GET to https://www.searchapi.io/api/v1/search?engine=tiktok_search and add additional parameters, at minimum your search (q). Two important parameters, at least for my use, are:
https://www.searchapi.io/api/v1/search?engine=tiktok_search
q
videos
last_day
As an example, this would search for recent Bigfoot videos: https://www.searchapi.io/api/v1/search?engine=tiktok_search&q=bigfoot&filter_by=videos&time_period=last_day
https://www.searchapi.io/api/v1/search?engine=tiktok_search&q=bigfoot&filter_by=videos&time_period=last_day
You can pass your key in an Authorization header or via querystring. Once set, you get results like the example below. I removed results 3-12 to slim it down a bit.
Authorization
{ "search_metadata": { "id": "search_z9qLVyexP1TWKjBpyeMEoPrY", "status": "Success", "created_at": "2026-11-18T20:20:08Z", "request_time_taken": 38.04, "parsing_time_taken": 0.03, "total_time_taken": 38.07, "request_url": "https://www.tiktok.com/search/video?q=bigfoot", "html_url": "https://www.searchapi.io/api/v1/searches/search_z9qLVyexP1TWKjBpyeMEoPrY.html", "json_url": "https://www.searchapi.io/api/v1/searches/search_z9qLVyexP1TWKjBpyeMEoPrY" }, "search_parameters": { "engine": "tiktok_search", "q": "bigfoot", "filter_by": "videos", "time_period": "last_day" }, "videos": [ { "position": 1, "id": "7709506056388349206", "link": "https://www.tiktok.com/@furics/video/7709506056388349206", "type": "video", "caption": "Unc found bigfoot in gta6.. š #gta6 ", "language": "en", "hashtags": [ "gta6" ], "iso_date": "2026-11-18T13:41:04Z", "duration": 30, "width": 576, "height": 1024, "is_duet_enabled": true, "is_stitch_enabled": true, "views": 190200, "likes": 7981, "comments": 46, "shares": 1926, "saves": 684, "thumbnail": "https://p16-common-sign.tiktokcdn.com/tos-no1a-p-0037-no/okwuLEvidqB0Iz3nxaDqBj3bqvA9iIZ2l8YvB~tplv-tiktokx-origin.image?dr=14575&x-expires=1795204800&x-signature=g1I8MikfYr781BDojUuvsBcV5Ew%3D&t=4d5b0474&ps=13740610&shp=81f88b70&shcp=43f4a2f9&idc=my2", "dynamic_thumbnail": "https://p16-common-sign.tiktokcdn.com/tos-no1a-p-0037-no/oocvzI0BxIY9DCZ73ISq8AziBvb2aBqviL3E9~tplv-tiktokx-origin.image?dr=14575&x-expires=1795204800&x-signature=GYUSkHuJRp%2BxcUvQ2MkD9jX0L9k%3D&t=4d5b0474&ps=13740610&shp=81f88b70&shcp=43f4a2f9&idc=my2", "video_meta": { "definition": "540p", "ratio": "540p", "format": "mp4", "codec_type": "h264", "size": 6334049, "bitrate": 1685315, "bitrates": [ { "gear_name": "normal_540_0", "bitrate": 1685315, "codec_type": "h264" }, { "gear_name": "adapt_lowest_1080_1", "bitrate": 1562462, "codec_type": "h265_hvc1" }, { "gear_name": "adapt_lower_720_1", "bitrate": 637456, "codec_type": "h265_hvc1" }, { "gear_name": "adapt_540_1", "bitrate": 512467, "codec_type": "h265_hvc1" } ] }, "music": { "id": "7709506075434781463", "title": "original sound", "author": "FURIOUSSS", "cover": "https://p16-common-sign.tiktokcdn.com/tos-maliva-avt-0068/1d10cda0763f03545d41e14502f28661~tplv-tiktokx-cropcenter:1080:1080.jpeg?dr=14579&refresh_token=4526c606&x-expires=1795204800&x-signature=Qh%2Fdx4Dkgjs%2BN6fuIuuaarqlBuM%3D&t=4d5b0474&ps=13740610&shp=a5d48078&shcp=81f88b70&idc=my2", "duration": 30, "play_url": "https://v16-webapp-prime.tiktok.com/video/tos/no1a/tos-no1a-v-2370-no/oYQ2QAWAmq3eJaMraWPV8vfTMXfQnQAAQN1eGX/?a=1988&bti=ODszNWYuMDE6&&bt=125&ft=GNDpcInz7ThxouxGXq8Zmo&mime_type=audio_mpeg&rc=anVxPHE5cnZ0ZTMzbzU8NUBpanVxPHE5cnZ0ZTMzbzU8NUBtMzRvMmRzaXJhLS1kMTFzYSNtMzRvMmRzaXJhLS1kMTFzcw%3D%3D&expire=1795036872&l=20261119042041DDB625B4325ADF36EF2A&ply_type=3&policy=3&signature=a3bd87900189c963b95a91303d9370be&tk=0&btag=e00048000", "is_original": true, "link": "https://www.tiktok.com/music/original-sound-7709506075434781463" }, "subtitles": [ { "language": "eng-US", "format": "webvtt", "source": "ASR", "url": "https://v16-webapp.tiktok.com/056669a1f3faee129d9a0b2f67a0a510/6b00abb8/video/tos/no1a/tos-no1a-v-0037-no/c28aced1ae0f489481e09847e50af4c7/?a=1988&bti=ODszNWYuMDE6&&bt=10397&ft=-ElcomI_PD12NiuGin-UxG~2NY6e3wv25dcAp&mime_type=video_mp4&rc=M2VpdnE5cm50ZTMzbzczNUBpM2VpdnE5cm50ZTMzbzczNUByYm9sMmRraXJhLS1kMTFzYSNyYm9sMmRraXJhLS1kMTFzcw%3D%3D&l=20261119042041DDB625B4325ADF36EF2A&btag=e00048000", "url_expires_at": "2026-11-20T20:21:12Z" } ], "author": { "id": "6699468133923570693", "sec_uid": "MS4wLjABAAAA6-w2JqfO-A8tODiEZbm_PwbvuT35ceNG18RUpcwd-uvCzg3dYXNnN7g4NWXyBbQb", "username": "furics", "link": "https://www.tiktok.com/@furics", "name": "FURIOUSSS", "bio": "I love kebab and counter-strike", "avatar": "https://p16-common-sign.tiktokcdn.com/tos-maliva-avt-0068/1d10cda0763f03545d41e14502f28661~tplv-tiktokx-cropcenter:720:720.jpeg?dr=14579&refresh_token=ccbb0edb&x-expires=1795204800&x-signature=H5Z6iiEiTWCLw%2BFMFJMfIBfiUeQ%3D&t=4d5b0474&ps=13740610&shp=a5d48078&shcp=81f88b70&idc=my2", "avatar_hd": "https://p16-common-sign.tiktokcdn.com/tos-maliva-avt-0068/1d10cda0763f03545d41e14502f28661~tplv-tiktokx-cropcenter:1080:1080.jpeg?dr=14579&refresh_token=4526c606&x-expires=1795204800&x-signature=Qh%2Fdx4Dkgjs%2BN6fuIuuaarqlBuM%3D&t=4d5b0474&ps=13740610&shp=a5d48078&shcp=81f88b70&idc=my2", "followers": 77500, "following": 9, "hearts": 4500000, "posts": 589, "liked_videos": 34600 } }, { "position": 2, "id": "7709594790626708766", "link": "https://www.tiktok.com/@bigfootandjeff/video/7709594790626708766", "type": "video", "caption": "BREAKING: The elusive sasquatch spotted in Hokum national park š« #bigfoot #bigfootsighting #nationalparks ", "language": "en", "hashtags": [ "bigfoot", "bigfootsighting", "nationalparks" ], "iso_date": "2026-11-18T19:25:42Z", "duration": 18, "width": 720, "height": 1280, "is_duet_enabled": true, "is_stitch_enabled": true, "views": 488, "likes": 79, "comments": 3, "shares": 1, "saves": 2, "thumbnail": "https://p16-common-sign.tiktokcdn.com/tos-useast8-p-0068-tx2/oUrfg70RAGIpAAJ4Me8FeL7dbQUYTgjwGf95ka~tplv-tiktokx-origin.image?dr=14575&x-expires=1795204800&x-signature=i1Bd2JBctOSVln2Wt4qE%2Bypzat4%3D&t=4d5b0474&ps=13740610&shp=81f88b70&shcp=43f4a2f9&idc=my2", "dynamic_thumbnail": "https://p16-common-sign.tiktokcdn.com/tos-useast8-p-0068-tx2/oMQARa9pA4tRfuUrGsGFQg8I3EQeQJF7CHwefD~tplv-tiktokx-origin.image?dr=14575&x-expires=1795204800&x-signature=pxvsCFOqDLqU3YiVk23JlV0eVsA%3D&t=4d5b0474&ps=13740610&shp=81f88b70&shcp=43f4a2f9&idc=my2", "video_meta": { "definition": "720p", "ratio": "720p", "format": "mp4", "codec_type": "h264", "size": 6560478, "bitrate": 2822014, "bitrates": [ { "gear_name": "normal_720_0", "bitrate": 2822014, "codec_type": "h264" }, { "gear_name": "adapt_lowest_1080_1", "bitrate": 1277960, "codec_type": "h265_hvc1" }, { "gear_name": "adapt_lower_720_1", "bitrate": 772052, "codec_type": "h265_hvc1" }, { "gear_name": "adapt_540_1", "bitrate": 589784, "codec_type": "h265_hvc1" } ] }, "music": { "id": "118053679", "title": "Pink Panther Intro", "album": "Pink Panther", "author": "Henry Mancini", "cover": "https://p16-sg.tiktokcdn.com/aweme/720x720/tos-alisg-v-2774/7760834633aa440f8cb3689b7e0d3c0d.jpeg", "duration": 30, "play_url": "https://sf16-ies-music-sg.tiktokcdn.com/obj/tos-alisg-ve-2774/d82c2f079d334932ab7492eb7192c7a3", "is_copyrighted": true, "link": "https://www.tiktok.com/music/pink-panther-intro-118053679" }, "author": { "id": "7129773694663820334", "sec_uid": "MS4wLjABAAAAA43z9stowUYdN9hEteOw0Ju0conhegD32sO8Xh2ZLMnSPVSd9sIUEuwp1C4IUJhZ", "username": "bigfootandjeff", "link": "https://www.tiktok.com/@bigfootandjeff", "name": "Bigfoot & Jeff", "bio": "A national park ranger and his best friend... š£ \nStarring: @JJ Carroll & @kevinismedlin \nDirector: @Matt Tory Producer: @getthehawk DP: Sam Halleen", "avatar": "https://p19-common-sign.tiktokcdn.com/tos-maliva-avt-0068/1803486b65e37d71cceddac9061127f1~tplv-tiktokx-cropcenter:720:720.jpeg?dr=14579&refresh_token=1cf51b3f&x-expires=1795204800&x-signature=zIAgJhY3i2iUyugtyx4ROP8C5Lo%3D&t=4d5b0474&ps=13740610&shp=a5d48078&shcp=81f88b70&idc=my2", "avatar_hd": "https://p16-common-sign.tiktokcdn.com/tos-maliva-avt-0068/1803486b65e37d71cceddac9061127f1~tplv-tiktokx-cropcenter:1080:1080.jpeg?dr=14579&refresh_token=296ccbce&x-expires=1795204800&x-signature=q8EJmtuaZc%2Fy7MrjV9T3sbHI82Q%3D&t=4d5b0474&ps=13740610&shp=a5d48078&shcp=81f88b70&idc=my2", "followers": 86300, "following": 16, "hearts": 1600000, "posts": 322, "liked_videos": 261 } } ], "pagination": { "has_more": true, "next_page_token": "<trimmed>" } }
On the YouTube side it’s pretty similar. You send your request to https://www.searchapi.io/api/v1/search?engine=youtube and use q for a search term. The API supports date filtering, but I ran into some issues testing that (I believe on the YouTube side), so instead used a function to handle filtering it after the results were returned.
https://www.searchapi.io/api/v1/search?engine=youtube
sp
Here’s an example of how those results look, once again for our furry friend in the forest (again, I trimmed out some results):
{ "search_metadata": { "id": "search_mOgBEZe50gHYJazd3kzwL3jW", "status": "Success", "created_at": "2026-11-18T20:38:31Z", "request_time_taken": 2.0, "parsing_time_taken": 0.05, "total_time_taken": 2.05, "request_url": "https://www.youtube.com/results?search_query=bigfoot&gl=US&hl=en", "html_url": "https://www.searchapi.io/api/v1/searches/search_mOgBEZe50gHYJazd3kzwL3jW.html", "json_url": "https://www.searchapi.io/api/v1/searches/search_mOgBEZe50gHYJazd3kzwL3jW" }, "search_parameters": { "engine": "youtube", "q": "bigfoot", "hl": "en", "gl": "US" }, "search_information": { "total_results": 6284946 }, "videos": [ { "position": 1, "id": "51-3_BZ-8mM", "title": "BIGFOOT: BEAST OF THE NORTH | Full Length BIGFOOT DOCUMENTARY | 4k Remaster", "link": "https://www.youtube.com/watch?v=51-3_BZ-8mM", "description": "BIGFOOT: BEAST OF THE NORTH | Full Length BIGFOOT DOCUMENTARY | 4k Remaster Mountain Beast Mysteries is a channelĀ ...", "views": 5867, "channel": { "id": "UCx0dPu6FzvajlmKmd4EdblA", "title": "MountainBeastMysteries", "link": "https://www.youtube.com/@MountainBeastMysteries", "thumbnail": "https://yt3.ggpht.com/ytc/AIdro_nkYRGD47VTcofpctHiSwY2rHswSNFE4kJI9kMjm1f_Cq8=s68-c-k-c0x00ffffff-no-rj" }, "length": "1:07:02", "published_time": "4h ago", "badges": [ "New", "4K" ], "thumbnail": { "static": "https://i.ytimg.com/vi/51-3_BZ-8mM/hq720.jpg?sqp=-oaymwEnCOgCEMoBSFryq4qpAxkIARUAAIhCGAHYAQHiAQoIGBACGAY4AUAB&rs=AOn4CLBrO7-_rMhtoLarjybb2NWVaN96uA", "rich": "https://i.ytimg.com/vi/51-3_BZ-8mM/hq720.jpg?sqp=-oaymwEnCNAFEJQDSFryq4qpAxkIARUAAIhCGAHYAQHiAQoIGBACGAY4AUAB&rs=AOn4CLDq7BdTvYorQmBNYas2MkJVFpA-Zw" } }, { "position": 2, "id": "jECoB4wX3zk", "title": "NEW Bigfoot Footage Just Dropped⦠And Itās TERRIFYING!", "link": "https://www.youtube.com/watch?v=jECoB4wX3zk", "description": "A pale figure appears to aim a red beam at a man in his cane field. A man reportedly calls dispatch to say 11 Bigfoots are standingĀ ...", "views": 14594, "channel": { "id": "UCPybHG1RFHwNr2zA6MRCh5Q", "title": "Wild Assault", "link": "https://www.youtube.com/@Wild_Assault", "thumbnail": "https://yt3.ggpht.com/aMUmqfmvO4nF2I5fu8T96Fq_dZ65MSO834dk7jRTGP9qHKKlQjMx1uBy-pKmjabylGlKG0CmoA=s68-c-k-c0x00ffffff-no-rj" }, "length": "34:20", "published_time": "2d ago", "badges": [ "New", "4 products" ], "thumbnail": { "static": "https://i.ytimg.com/vi/jECoB4wX3zk/hq720.jpg?sqp=-oaymwEnCOgCEMoBSFryq4qpAxkIARUAAIhCGAHYAQHiAQoIGBACGAY4AUAB&rs=AOn4CLDBHLpSkPE40Xho6zadh14c3bsziQ", "rich": "https://i.ytimg.com/vi/jECoB4wX3zk/hq720.jpg?sqp=-oaymwEnCNAFEJQDSFryq4qpAxkIARUAAIhCGAHYAQHiAQoIGBACGAY4AUAB&rs=AOn4CLAPR_kuBQyU7BGUOTSGloRqhRbW-g" }, "key_moments": [ { "title": "Something at the Cabin Garbage Can", "start_seconds": 0, "thumbnail": "https://i.ytimg.com/vi/jECoB4wX3zk/hqdefault_14933.jpg?sqp=-oaymwEnCNACELwBSFryq4qpAxkIARUAAIhCGAHYAQHiAQoIGBACGAY4AUAB&rs=AOn4CLC3Nly_w9taEd9Y6zv5afNf_NElag" }, { "title": "The Figure Pressed Against a Tree", "start_seconds": 141, "thumbnail": "https://i.ytimg.com/vi/jECoB4wX3zk/hqdefault_141333.jpg?sqp=-oaymwEnCNACELwBSFryq4qpAxkIARUAAIhCGAHYAQHiAQoIGBACGAY4AUAB&rs=AOn4CLCLBETu5cPeRYAsftimzfFZkJg00w" }, { "title": "The Tunga Canyon Scream", "start_seconds": 236, "thumbnail": "https://i.ytimg.com/vi/jECoB4wX3zk/hqdefault_265833.jpg?sqp=-oaymwEnCNACELwBSFryq4qpAxkIARUAAIhCGAHYAQHiAQoIGBACGAY4AUAB&rs=AOn4CLAV-LTuZjaXSPHJCSI0m9-050dZsg" }, { "title": "The Cane Field and the Red Beam", "start_seconds": 290, "thumbnail": "https://i.ytimg.com/vi/jECoB4wX3zk/hqdefault_290300.jpg?sqp=-oaymwEnCNACELwBSFryq4qpAxkIARUAAIhCGAHYAQHiAQoIGBACGAY4AUAB&rs=AOn4CLDWAgmyR1Jmabmekx0NpqysCZH6Ug" }, { "title": "Bigfoot Walking Through Sunlight", "start_seconds": 471, "thumbnail": "https://i.ytimg.com/vi/jECoB4wX3zk/hqdefault_478266.jpg?sqp=-oaymwEnCNACELwBSFryq4qpAxkIARUAAIhCGAHYAQHiAQoIGBACGAY4AUAB&rs=AOn4CLC2jD1i_3StBWIqR-o8TzOpjJkHvg" }, { "title": "The Skunk Ape in the Florida Clearing", "start_seconds": 591, "thumbnail": "https://i.ytimg.com/vi/jECoB4wX3zk/hqdefault_596800.jpg?sqp=-oaymwEnCNACELwBSFryq4qpAxkIARUAAIhCGAHYAQHiAQoIGBACGAY4AUAB&rs=AOn4CLDHp7FbOfzRS4qhvnquwcD8uiX4UA" }, { "title": "The Trail Cam Wild Man", "start_seconds": 682, "thumbnail": "https://i.ytimg.com/vi/jECoB4wX3zk/hqdefault_700966.jpg?sqp=-oaymwEnCNACELwBSFryq4qpAxkIARUAAIhCGAHYAQHiAQoIGBACGAY4AUAB&rs=AOn4CLBg14lGrxjux-fm05PcD3v_eHOOsQ" }, { "title": "The Growl Heard While Cutting Wood", "start_seconds": 784, "thumbnail": "https://i.ytimg.com/vi/jECoB4wX3zk/hqdefault_788266.jpg?sqp=-oaymwEnCNACELwBSFryq4qpAxkIARUAAIhCGAHYAQHiAQoIGBACGAY4AUAB&rs=AOn4CLCcgHxoe4yBkQoTdej3mXu6EB2UBA" }, { "title": "The Ghost on the Bristol Trail Cam", "start_seconds": 935, "thumbnail": "https://i.ytimg.com/vi/jECoB4wX3zk/hqdefault_938100.jpg?sqp=-oaymwEnCNACELwBSFryq4qpAxkIARUAAIhCGAHYAQHiAQoIGBACGAY4AUAB&rs=AOn4CLCEEbzNDoph-1cKOF4_x3f3SBSgDQ" }, { "title": "The Dark Mass on the Alberta Deer Trail", "start_seconds": 1041, "thumbnail": "https://i.ytimg.com/vi/jECoB4wX3zk/hqdefault_1052066.jpg?sqp=-oaymwEnCNACELwBSFryq4qpAxkIARUAAIhCGAHYAQHiAQoIGBACGAY4AUAB&rs=AOn4CLC5OpkpJQgal3fNjIdeSYfJCD4Nkg" }, { "title": "The Baby Bigfoot Photos and the Dispatch Call", "start_seconds": 1180, "thumbnail": "https://i.ytimg.com/vi/jECoB4wX3zk/hqdefault_1208866.jpg?sqp=-oaymwEnCNACELwBSFryq4qpAxkIARUAAIhCGAHYAQHiAQoIGBACGAY4AUAB&rs=AOn4CLCr9JrO6PWqm1vzGEgyuxW-wsns6g" }, { "title": "The Silhouette in the Alaska Woods", "start_seconds": 1321, "thumbnail": "https://i.ytimg.com/vi/jECoB4wX3zk/hqdefault_1323000.jpg?sqp=-oaymwEnCNACELwBSFryq4qpAxkIARUAAIhCGAHYAQHiAQoIGBACGAY4AUAB&rs=AOn4CLAHMy3WTFAnNz3V5QDuaNi46vnl_Q" }, { "title": "Howls, Whoops and a Coyote Pack", "start_seconds": 1420, "thumbnail": "https://i.ytimg.com/vi/jECoB4wX3zk/hqdefault_1422100.jpg?sqp=-oaymwEnCNACELwBSFryq4qpAxkIARUAAIhCGAHYAQHiAQoIGBACGAY4AUAB&rs=AOn4CLAAUl7URBICGt5FkldLf7dXJcMOoA" }, { "title": "The Woven Trees on Bigfoot Trail", "start_seconds": 1558, "thumbnail": "https://i.ytimg.com/vi/jECoB4wX3zk/hqdefault_1559400.jpg?sqp=-oaymwEnCNACELwBSFryq4qpAxkIARUAAIhCGAHYAQHiAQoIGBACGAY4AUAB&rs=AOn4CLBXWRxvqZ3Gw1kLj03N_x7DLYY7XA" }, { "title": "The Driveway Creature Under Two Feet Tall", "start_seconds": 1722, "thumbnail": "https://i.ytimg.com/vi/jECoB4wX3zk/hqdefault_1732000.jpg?sqp=-oaymwEnCNACELwBSFryq4qpAxkIARUAAIhCGAHYAQHiAQoIGBACGAY4AUAB&rs=AOn4CLBBsa9ym_z6CU-GqRKc17J31nwGgQ" }, { "title": "The Church Picnic Scream", "start_seconds": 1812, "thumbnail": "https://i.ytimg.com/vi/jECoB4wX3zk/hqdefault_1824866.jpg?sqp=-oaymwEnCNACELwBSFryq4qpAxkIARUAAIhCGAHYAQHiAQoIGBACGAY4AUAB&rs=AOn4CLBTE3EpySxlut480IR-iN_dERORpQ" } ] }, ], "shorts": [ { "position": 3, "items": [ { "position": 1, "id": "SSDXIz2m1Do", "title": "Bigfoot Was Running From Something Beneath the Mountains⦠šØ", "link": "https://www.youtube.com/shorts/SSDXIz2m1Do", "views": 1300, "thumbnail": "https://i.ytimg.com/vi/SSDXIz2m1Do/oar2.jpg?sqp=-oaymwEoCJUDENAFSFqQAgHyq4qpAxcIARUAAIhC2AEB4gEKCBgQAhgGOAFAAQ==&rs=AOn4CLCumP49eaabFZXbbhIdHcbpLfeBnw" }, { "position": 2, "id": "4uIdvGGCzJ0", "title": "Are Bigfoot Skeptics Ignoring the Evidence | Les Stroud's Conversations On Bigfoot | Encounters", "link": "https://www.youtube.com/shorts/4uIdvGGCzJ0", "views": 679, "thumbnail": "https://i.ytimg.com/vi/4uIdvGGCzJ0/oar2.jpg?sqp=-oaymwEoCJUDENAFSFqQAgHyq4qpAxcIARUAAIhC2AEB4gEKCBgQAhgGOAFAAQ==&rs=AOn4CLC_MUdY7sTn9wCeuuGWFNgN0mxdRA" } ] }, { "position": 7, "items": [ { "position": 1, "id": "WUNJ9XXrlCo", "title": "The Bigfoot Photos That Disturbed Russ Acord", "link": "https://www.youtube.com/shorts/WUNJ9XXrlCo", "views": 186000, "thumbnail": "https://i.ytimg.com/vi/WUNJ9XXrlCo/oar2.jpg?sqp=-oaymwEoCJUDENAFSFqQAgHyq4qpAxcIARUAAIhC2AEB4gEKCBgQAhgGOAFAAQ==&rs=AOn4CLD3y6wr2v7p65GxXJK6s6pYfMOmQg" }, { "position": 2, "id": "_hBvd88iQcI", "title": "Tuckerās Thoughts on Bigfoot", "link": "https://www.youtube.com/shorts/_hBvd88iQcI", "views": 104000, "thumbnail": "https://i.ytimg.com/vi/_hBvd88iQcI/sardefault.jpg?sqp=-oaymwEoCJUDENAFSFqQAgHyq4qpAxcIARUAAIhC2AEB4gEKCBgQAhgGOAFAAQ==&rs=AOn4CLAcsJ2PjWTzegBlh3MZMPJJyvIjxA" } ] } ], "pagination": { "next_page_token": "<trimmed>" } }
Everything above is wrapped up in a simple Netlify serverless function:
import { getStore } from '@netlify/blobs'; const SEARCH_TERM = 'mashup'; const API_URL = 'https://www.searchapi.io/api/v1/search'; const CACHE_TTL_MS = 2 * 60 * 60 * 1000; // 2 hours in milliseconds /** * Converts a YouTube relative time string (e.g., "3h ago", "45 minutes ago", "1d ago") * into a JavaScript Date object if it falls within the last 24 hours. * Returns null if the video is older than 24 hours or cannot be parsed. */ function parseRelativeTime(timeStr) { if (!timeStr) return null; const lower = timeStr.toLowerCase(); const match = lower.match(/(\d+)\s*(s|sec|second|m|min|minute|h|hr|hour|d|day)s?\b/); if (!match) return null; const amount = parseInt(match[1], 10); const unit = match[2][0]; // 's', 'm', 'h', or 'd' const now = Date.now(); if (unit === 's') { return new Date(now - amount * 1000); } if (unit === 'm') { return new Date(now - amount * 60 * 1000); } if (unit === 'h' && amount <= 24) { return new Date(now - amount * 60 * 60 * 1000); } if (unit === 'd' && amount === 1) { return new Date(now - 24 * 60 * 60 * 1000); } return null; } async function getYouTubeMashups(apiKey) { const params = new URLSearchParams({ engine: 'youtube', q: SEARCH_TERM, api_key: apiKey }); const res = await fetch(`$ {API_URL}?$ {params}`); if (!res.ok) { throw new Error(`YouTube search failed: $ {res.statusText}`); } const data = await res.json(); const videos = data.videos || []; const results = []; for (const video of videos) { const publishedDate = parseRelativeTime(video.published_time); if (publishedDate && video.id) { results.push({ id: video.id, source: 'youtube', title: video.title, author: video.channel?.title || 'Unknown Creator', authorUrl: video.channel?.link || '#', date: publishedDate.toISOString(), publishedText: video.published_time, embedUrl: `https://www.youtube.com/embed/$ {video.id}`, link: video.link }); } } return results; } async function getTikTokMashups(apiKey) { const params = new URLSearchParams({ engine: 'tiktok_search', q: SEARCH_TERM, time_period: 'last_day', filter_by: 'videos', api_key: apiKey }); const res = await fetch(`$ {API_URL}?$ {params}`); if (!res.ok) { throw new Error(`TikTok search failed: $ {res.statusText}`); } const data = await res.json(); const videos = data.videos || []; return videos .filter(video => video.id && video.iso_date) .map(video => { const publishedDate = new Date(video.iso_date); return { id: video.id, source: 'tiktok', title: video.caption || 'Untitled Mashup', author: video.author?.name || video.author?.username || 'Unknown Creator', authorUrl: `https://www.tiktok.com/@$ {video.author?.username || ''}`, date: publishedDate.toISOString(), publishedText: publishedDate.toLocaleTimeString([], { hour: 'numeric', minute: '2-digit' }), thumbnail: video.dynamic_thumbnail || video.thumbnail || video.music?.cover || '', link: video.link }; }); } export default async (req, context) => { const apiKey = Netlify.env.get('SEARCHAPI_KEY'); if (!apiKey) { return Response.json( { error: 'Missing SEARCHAPI_KEY environment variable.' }, { status: 500 } ); } try { const store = getStore('mashup-cache'); const cached = await store.get('latest-results', { type: 'json' }); if (cached && Date.now() - cached.timestamp < CACHE_TTL_MS) { console.log('Returning cached mashups from Netlify Blobs'); return Response.json(cached.results); } console.log('Cache miss or expired ā fetching fresh mashups from SearchApi'); const [youtubeResults, tiktokResults] = await Promise.all([ getYouTubeMashups(apiKey), getTikTokMashups(apiKey) ]); const combined = [...youtubeResults, ...tiktokResults]; // Sort newest first combined.sort((a, b) => new Date(b.date) - new Date(a.date)); await store.setJSON('latest-results', { timestamp: Date.now(), results: combined }); return Response.json(combined); } catch (error) { console.error('Error fetching mashups:', error); return Response.json( { error: 'Failed to load mashup videos.' }, { status: 500 } ); } }; export const config = { path: '/api/mashups' };
You can see the two SearchApi wrappers which get combined into one sorted array when done. I’m also using Netlify Blobs for lightweight caching.
And that’s pretty much it. I will share one final little oddity I ran into, completely separate from SearchApi. TikTok’s embed code was very buggy for me. I had wanted all the results to play on the dashboard, but I ran into constant issues with TikTok’s embed code. I decided to punt and simply link out to a new tab for those results. If you would like to see the complete code for the application, you may find it here: https://github.com/cfjedimaster/mashupviewer
Enjoy – and dance your heart out!
Photo by Eric Krull on Unsplash
Raymond Camden
You must be logged in to post a comment.
This site uses Akismet to reduce spam. Learn how your comment data is processed.