Hey guys, welcome back. In this video, we're going to continue building our own self-hosted alternative to Loom. Let's get into it.
So we made plenty of progress in the last video, in part one. This is part two. We got stuck in one of the steps, which is, in order to serve videos through Cloudflare or an R2 bucket, we had to set up Cloudflare CDN. And in order to do that, we had to transfer our domain and DNS records and everything to Cloudflare, which is something that I didn't want to do because I'm using Vercel.
So I found a workaround, and I'm going to show you that workaround in this video. What you can do is you can go over to Compute, and then Workers and Pages, and you can create a Cloudflare Worker over here. I've already done that, but I'm just going to show you the steps so you can do this yourself too.
You're just going to click Create Application. I'm going to start with a Hello World template, and it'll give you all this basic code. You can just set the name of the worker over here. And once you've done that, just create the worker. All right. And then you'll have a Cloudflare Worker that looks something like this.
The next thing you're going to have to do is go into Bindings, then Add Binding, go down here to R2 Bucket, Add Binding, and then you put a variable over here, like my bucket or something, and you connect your bucket to this.
And then, as for the actual code, let me just show you the code over here. This is the code that we're using. It's just like 70 lines of really basic code, and all it does is that it just forwards our requests to the R2 bucket, so that if I try to fetch a file from this worker, it's going to fetch that same file from the R2 bucket and just return that to me.
I just use Gemini to generate this worker, and all you really have to do is just go over to any chatbot, ask it to write you a basic Cloudflare Worker that can fetch files from an R2 bucket. Just do that, add the binding, and attach your R2 bucket to that binding, and you'll be done.
And then you can just use your worker's URL. Like, for instance, I have one over here, and I can say resume.pdf, and it should open it up. There we go. So this worker is now fetching files from our R2 bucket, and we don't need to use the r2.dev domain, which is not intended for production anyway.
Once you've set this up, go over to your editor, and let's actually integrate this. So what I'm going to do is I'm going to copy this domain, this entire URL, paste it over here, and then just ask my agent to use that from now on instead of using the R2 domain, which is obviously not intended for production use and is rate limited anyway. Use this worker domain that I set up in Cloudflare. All requests to the R2 bucket files should now go through this worker.
Okay, let's fix this prompt real quick. And there we go. Now, while it does that, let's also start the development server so we can start fixing the design of this app as well, which, if you remember, is very horrible.
We're gonna change this homepage as well a little bit. I don't need it to be anything fancy, just something minimal, because, like, the homepage isn't gonna get used all that much, right? We're just going to, you know, upload outreach videos and then just send the link to that exact video to the client. So we don't really need a homepage for this, but we're just gonna have a minimal template that is just different from this default Next.js crap, right?
Anyway, there we go. Now we're using the actual worker. Now let me go over to a video URL. Let's pick this one and start fixing the design, because the design of this entire app is very horrible.
So to do this, let's just take some screenshots. I want to remove that Wistack player thing. Remove the Wistack player text from the menu bar, or actually that's called the navbar. There we go.
What else? I want to remove all of this stuff. Let's see. Let's take a full screenshot of the entire section over here. Remove the source file. There's no need to show the entire file name. Remove the fingerprint thing you have over here. Also remove the R2 bucket text and the Full HD 1080p text over here. No need to show an embed button or an R2 button or a download button or a share video button at all. Remove the entire storage and delivery section as well, and remove the brand color spectrum as well. There's no need to show any of these things.
You will still keep the player keyboard shortcut section because I think that can be useful, but remove everything else. And from the footer, remove the powered by text that tells the user our tech stack. No need to show that. And remove the theme and the custom HSL shade you've written over there as well.
Let's transcribe all of that. And let's also fix the issues with our theme, right? So if I go over here, if I turn on light theme, the text just disappears, right? So let's fix that as well. Also, the design is not configured for light theme and dark theme properly. It looks fine in dark theme, but if I turn on light theme, some of the text disappears and turns completely white, or other elements just start looking weird.
Make sure that the design is configured for both light and dark themes. Both themes need to look really good, no matter which one I'm using. Make sure all elements can dynamically switch between light and dark themes.
Okay, now let's send that prompt. Let's turn on dark mode again so we don't get blinded by this white screen, and let's wait for that to finish. In the meantime, I think we can mark this task complete.
Also, I want to add a CTA just below the video. So let's ask it to do that as well. Add a CTA button called "Book a Free Call" at the bottom of the video player. I'll give you the link to that button over here as well. And then just paste my Calendly link over there. And the agent will take care of that as well once it's done fixing the design and everything.
By the way, we're also going to need some sort of a database to add this tracking information, so we can track how many times a video was played, whether a video was played to completion or it was just, you know, the client played it like halfway through and then just stopped. We want to add tracking for these things, and we want some sort of a database to do this, right?
Now, I don't want to have a Postgres database for this because then I have to, you know, go open up my computer, run psql or the Docker container for this, and just run some psql queries, and that's just extra steps, right? What I much prefer to do nowadays is to just set up a Google Sheet where I store all of this data instead. Not something a programmer does usually, but I just prefer this approach so much more.
So, yeah, we're gonna set up a database over here. I'll just call this Loom Outreach Database, and we want to store a few things over here. We'll store the URL, we'll store the page views, video plays, and video completions. There we go. It's gonna make this look a little bit better as well, because why not?
Okay, in the meantime, the agent has finished updating our design, so let's see what it looks like now. Let's refresh the page. Okay, not as good as I wanted it to be. A light theme looks amazing. There's the book a call CTA. Okay, I actually like this a lot more, but the dark theme still needs work. Most changes look amazing, but the nav bar and the footer in the dark theme does not actually look dark. I'm in my dark theme in my OS right now, and the nav bar and footer are still using light colors and light backgrounds, whereas the rest of the page has correctly updated to the dark mode. Fix that. However, in the light theme, everything looks perfect, so don't change anything over there.
Also, I'm gonna create a new file over here in this lib folder called `crack in sheet`. This is where we're going to, I'm going to add all the Google Sheets API stuff so we can save all our data. And there we go. The design has completely fixed itself as well. I actually like this design. I'm gonna go with it now.
Since all the design stuff has been fixed, let's create. And let me make sure these errors are actually fixed as well before we do anything else. Let's refresh the page. Okay, yeah, no errors. Perfect. If I switch the theme, no errors. Perfect.
Now start a new chat and ask the agent to create all the Google Sheet database stuff that we need. I'm taking a screenshot of the Google Sheet as well so we can show the agent what the column names are and how to use them, right? So paste that in over here as well.
I want you to add a bunch of minimal tracking mechanisms to our video pages. I want to track how many times a video page has been opened. I want to track how many times the video was actually played, and I also want to track how many times a video was played to completion, meaning the user didn't stop watching halfway or in the middle of the video. He actually watched the entire video all the way to the end. I want to track these three things, and I want to track all of them in my Google Sheet. Set up all of the tracking mechanisms and the Google Sheet API stuff that you need in order to make this work. Tell me the environment variables that you need from me in order to accomplish this task, and I will add them in the .env file myself.
Okay, so my transcription service is a bit finicky. Let's fix this typo over here. It called, instead of writing Google, it said Ogle. Funny. Okay, let's send this.
Now, to actually make this work, you are going to have to go over to your Google Cloud Console. And you're going to have to create a project over here. You're going to have to enable the Google Sheets API, and then, and then grab your OAuth tokens, client IDs, and client secrets. I'm not going to go into how to do all of that stuff. I've already done that for previous apps of my own. But it is a pretty straightforward process, and you can ask any chatbot to help you guide, to help you enable all of these things. Just go over to ChatGPT or Gemini or something, and tell them you want to create a Google Cloud project and enable the Google Sheets API, and they'll tell you everything you need to know. Or you could just ask your agent over here to do it for you.
Once you're done with all of those things, you're probably gonna have, uh, where is it? Where's my whiteboard? A client secret and a token file. Both of these are JSON files, and you're gonna have to store them in your codebase. Just make sure they're in your `.gitignore` file as well, so you don't commit them to source control.
Now, I already have my client secrets and tokens over here in my video editor project, in YouTube API, `ls tokens`. Yeah, there we go. So what I can do is I can just copy these things over to, let's go over here. Let's say `cp` to copy the file. Okay, there we go. So I've added both of them over here.
What I'm going to do is I'm going to create a tokens folder just to organize both of these, and I'll move both of them in there, and I'll add it to the `.gitignore` file as well. Let's say credentials, tokens, and just ignore that entire folder.
Now, instead of environment variables, we can just use these client secret and token fields, and instead of using a service account, we can just use my OAuth credentials. So let me tell the agent to do that. I've created a tokens folder in this directory where I have a `token.json` and a `client_secret.json` file. You can use these two files to interact with the Google Sheets API on my behalf using my OAuth tokens. No need to set up service accounts and use that.
And once again, I need to change Ogle to Google before YouTube bans me or something. And then submit that, and the agent will modify the implementation plan over here, and then we'll, you know, have a good plan, and we can proceed with it.
Now, while it does that, let's go back over here to my whiteboard and see what we need to do next. So we've created a beautiful minimal design for the app. Okay, done. We've also added a CTA at the bottom of the video player. We're gonna skip this step because we don't need the Cloudflare CDN anymore because we're using a Cloudflare Worker, which already gives us Cloudflare CDN, but without using or without transferring our domain to Cloudflare, which is something I wanted to avoid as much as possible. So I'm just gonna consider this one done as well.
And it looks like my agent has written most of the code. Let's let it do its thing. Let's refresh the page over here. Okay, so that should count as a page view. Okay, so that didn't work because I forgot to configure the Google Sheet ID, so let's do that. The Google Sheet ID is just this long string of jumbled-up characters in your URL. Copy that and put that in your `.env` file. Okay, I've done that.
Now I'm gonna go back over to right here. Actually, no, we need to. The request had insufficient authentication scopes. I think we need to reconnect our OAuth to actually enable this. I guess it doesn't have the correct permissions right now. Let's copy this error and paste it in the agent and ask it how to resolve this. I'm pretty sure we just need to, you know, reconnect our OAuth stuff and whatever.
Okay, so it created a new script for us called `authsheets`. We just need to run this command, and we should be able to, you know, reconnect to our Google Sheets. So let's go and run that. I'll just say `bun run art sheets`. Okay, I'm in the wrong folder. Let's run that again.
And I'm going to go ahead and connect my Google account to this and then come back. Okay, I finished connecting the account. Now it gave me this code that I can just copy and write till there, then just paste it over in my terminal, and that should work. Okay, there we go. We have a success now. If I refresh this page again, okay, so that still doesn't work. We need to fix that somehow.
Okay, so it turns out I just had to refresh my or restart my development server. Once I did that, this is working now, and you can see over here. There we go. The styling needs to be improved a bit, but yeah, the tracking at least works fine. If I play the video, it does track that the video has been played. What happens if I complete the video? It sends another track request. Okay, and the video has been completed. Perfect. So the tracking works flawlessly now. The tracking works flawlessly now.
Let's config, let's set this task to complete it as well, and then we need to add time-stamped chapters to each video. To do this, I'm just going to use Gemma 4 from OpenRouter. It's free, and we can just use this model to generate the timestamps. It also supports structured JSON output, which is extremely useful for us. We're going to generate a VTT file. This is a captions file. We're going to upload it to R2 alongside the video file, and yeah, then we're just going to set our player to use that VTT file for chapters.
So let's start configuring all of this. In order to do all of these things, you're going to have to go over to openrouter.ai, sign up for your account, then create a personal API key over here. And once you've done that, you'll have your API key, and you can use it to at the very least use all the free models over here. And of course, if you add a bunch of credits, you can use the paid models as well, but we don't need that for this purpose. We're going to use Gemma 4 26B, the free version over here.
So go over to this page, copy the model name, and then start a new chat in your agent, and then let's give it a prompt. I want you to use OpenRouter and the Gemma 4 26B model to generate a .vtt file, which will contain the captions and the chapters for this video. Not captions, I just want to generate the chapters for the video. So let's fix this prompt up as well. For some reason, I just can't type G when I'm using my transcription service over here. Use the following model. Fix that as well. Paste in the model name over here. Use the following environment variable for my API key: OPENROUTER_API_KEY.
And then we also want to, you know, give it some docs on how this thing actually works. So go over to Docs over here. The way I configure these kinds of, like, external APIs and everything using agents is to just go over to their docs, find what I'm looking for, which is structured outputs over here, copy the entire page. Most documentation has this button nowadays, especially ones related to AI and LLMs. Copy the entire thing, paste it over here, and just say something like, "Below I have the docs for the OpenRouter API and how to use structured outputs in it. Use those docs to write your script."
There we go. And then let think a bit about the architecture of how we going to actually do this. So what we want to do is we want to have a file over here in the scripts folder saying something like generate chapters. And then we can just pass that file in over here in the context and say something like the generate chapters TypeScript file is where you will write all of this OpenRouter code to actually configure all of this.
And then how do we want to host this or add this into the, let's say, the video player and the R2 bucket? What I'm planning is to run the upload to R2 script, which should automatically generate the chapters and the .VTT file and then upload that alongside the video file with the exact same file name so that we can easily fetch it.
So let's add that to the prompt. Once you're done writing the TypeScript script, you should update the upload to R2 shell script to automatically run this script to generate the VTT file and the chapters for each video. And then you should upload that VTT file to the R2 bucket using the exact same file name as the video file. Then you can fetch that VTT file in the video player and add that to the Vidstack video player when we go to the video page.
Now one thing I forgot to add over here is we are also going to need some sort of a transcription service to generate the captions for this whole thing before we can, you know, um, generate the chapters, right? So this is going to be a pretty massive prompt, so I'm just going to set the thinking level to high.
And in order to generate captions, I'm going to use Grok. Not the Twitter Grok, the other Grok with the Q. These guys offer us OpenAI's Whisper large V3 model, which can basically transcribe all of our audio and generate captions for it. So we're going to use that as well. Or at least that's what you should do. But I already have a transcription service, which is what I use for my video editing, which is in my Phantom editor over here.
Let me clear all of this. I can just say something like, "Phantom Edit Transcribe Cloud --help." And I can use this command to transcribe any video file. So I'm just going to copy this entire help text and say something like, "You're going to need the captions for the video file if you can generate the chapters accurately. In order to get the captions, you can use the Phantom Edit Transcribe Cloud command. Below is the help text to use this command." And there we go. Paste that in. Maybe format that as a code block as well, because why not? And just let the agent figure it out after this.
This is a pretty massive prompt, but that's why we set the thinking level to high, right? Okay, so for some reason, the Grok website is just not loading. So I'm just going to walk you through what you would have done if you didn't have a transcription service like this already set up, right?
Basically, Grok is just an AI LLM provider, and one of the models that they offer is Whisper 3, and Whisper 3 is a speech-to-text model built by OpenAI, right? So you can give it some sort of an audio file, and it can just transcribe all of it and give you timestamps and captions for the entire thing. Super useful, and Grok actually offers this for free, which is why I wanted to use them.
So since you probably don't have a transcription service like this already set up, what you can do is sign up to Grok, grab the API key, right? And then follow the same process we followed for OpenRouter, which is to go over to the Grok docs, go over to speech to text. And I don't know why this is not loading.
Grok's website is just really slow right now, for some reason, while I'm recording things, right? If I wasn't recording a video, this would work flawlessly. But when I need it to work, this is what I have to deal with.
But yeah, let me just explain the entire thing. You would go over to speech-to-text over here. You would copy the entire docs, paste that into your agent, and just ask it to write a transcription service for you that can transcribe a video file or audio file. And then you can use that to generate the timestamps, right? Then you pass that in over here to OpenRouter, which will then generate the captions or the chapters for you. And that's pretty much it.
Okay, so it came up with an implementation plan. Let's try reading this whole thing. API key. Yup. That's the model we want to use. Naming convention. Yup. Everything looks fine.
Okay. Use structured outputs. Yes, we want to have structured outputs with chapters. Normalize and format them to WebVTT syntax. Save the file. Okay, everything is perfect.
The upload script is now going to compress the video. We already did that. Then it's going to transcribe the video, then generate the chapters, upload the compressed MP4 and the VTT chapters, all of them. And yeah, looks fine. Let's proceed with this.
By the way, I know I've been recording for a very long time, but I'm just trying to finish this project in this video because we're literally almost done. The only thing we need to do after this step is to just deploy this to Vercel and add a CNAME record so we can easily watch our videos on our own domain. So I'm trying to just finish this whole thing in this video.
This might get a bit longer. Just bear with me over here. We're almost done. Just one or two steps left.
Okay, skip the building process. You don't really need to run this if your development server is working fine.
Okay, and to test this out, we should probably upload the freelancer intro all the way again, right? So let's do that. I'm going to exit the development server, and I'm going to upload a video file again by going to `scripts/upload-to-r2.sh`, and then I'll pass in a video file path, and then just pass in my freelancer intro again, and this time name it to something like `freelancer-intro-with-chapters.mp4`.
Let's do that. It's obviously going to compress the whole thing again, and then it'll generate the captions and everything. We're just going to wait for this to finish.
And while we do that, let's also deploy this to Vercel so that we can start to finish this whole thing. I say create a new project. The name will just be Watch Us in Dev. No need to customize anything. This is just a standard Next project, and then just let Vercel handle all of the rest.
Then we can just go over to Vercel, open up the project settings, and add the environment variables we're going to need over here, because we are going to need most of them.
Okay, so I just added all of my variables to the Vercel project. Let's go over to deployments. And let's redeploy this. We can use the existing build cache. I just want to have the variables that I just added in the actual app.
Okay, I forgot to set my OpenRouter API key. So that sucks.
Okay, so I just added the API key. Now let's try to upload all over again. This is kind of annoying because it's going to run every single step all over again. But yeah, you're just going to have to deal with that, I guess. So let's let this whole thing run and see how it works.
Okay, so the Google servers returned a rate limit error. This happens way too often. Google just can't keep up with the demand, so we're just gonna switch to a different provider and a different model. Let's use NVIDIA's Nemotron 3 Ultra. This is a free model. Let's switch to this one. Pass in the generate chapter script over here and say, "Use this model from now on."
Honestly, I don't know why I chose to use Gamma 4 and Google servers. They just, they have such horrible rate limits. No matter how many times you send a request, no matter when you send a request, it's just going to return a rate limit like nine times out of 10. Because, like, these guys just can't keep up with the, you know, the demand for this stuff.
Okay, let's run this whole thing all over again for the third time now and see how it works.
And it turns out the Grok website is finally loading as well. So yeah, what you were supposed to do to generate the captions was to just go over to the speech-to-text documentation page, copy the page, paste it into your LLM along with your API key, which you would put in the env file, not in the LLM chat, and just let it write you a transcription service, right?
Okay, I think this time it actually worked. So if you look at the output over here, it generated the captions, it compressed the video, it generated the chapters file, and it uploaded everything.
So let's go and see if it works. Fingers crossed. I really hope this works now.
And let's actually test this on my Vercel app. So this is the URL of the file, or actually, no, this is the old file that we were using. So let's go over to my R2 bucket, or actually, instead of that, here's the file that we can just view. Let's copy this whole URL.
Well, let's paste that over here and let's go and see what happens.
Okay, so the file name is correct, freelancer intro with chapters. There's the chapters that I wanted to have: Introduction and Key Achievements, Technical Consulting, Business Value, End-to-End Ownership. There we go. So that all works now, thank goodness.
The theme works as well. And there we go. Yeah, and with that, we have accomplished this entire project. I'm going to mark all of those tasks complete, and yeah, before this video gets even longer, because I've been recording for like an hour already, I'm gonna end it over here.
That right there, ladies and gentlemen, is how I build projects with AI. As you can see, the whole thing took me like two or three hours to build in total. Obviously, you know, the so you can build apps really, really quickly with AI. You just have to do it the right way, right?
Things like, you know, having a proper tech stack, saving your secrets in your environment variables properly, having a good idea of what tools and frameworks and apps to use. Like, I use the Cloudflare R2 bucket over here because they offer me 10 GB of storage for free. I, you know, use OpenRouter for generating chapters because they offer free models. I use Grok for transcription because they give me Whisper Flow for free. Not Whisper Flow, the OpenAI Whisper model.
And so, yeah, as long as you have a good idea of what you're doing, you can build pretty much anything. And with that, I'm I'm going to end the video over there before it gets even longer. Thank you so much for watching if you stuck to the end. And I hope you built this alongside me and learned a thing or two. Peace.