├── .gitignore ├── .yarn └── releases │ └── yarn-4.1.0.cjs ├── .yarnrc.yml ├── README.md ├── components.json ├── deno └── route.ts ├── next.config.ts ├── package.json ├── postcss.config.mjs ├── public ├── favicon.png ├── file.svg ├── globe.svg ├── next.svg ├── og.png ├── vercel.svg └── window.svg ├── src ├── app │ ├── APP_URL.tsx │ ├── YouTube_full-color_icon_(2017) (1) 1.ico │ ├── [...url] │ │ ├── route.ts │ │ └── youtube.ts │ ├── favicon.ico │ ├── favicon.png │ ├── fonts │ │ ├── GeistMonoVF.woff │ │ └── GeistVF.woff │ ├── globals.css │ ├── history.tsx │ ├── layout.tsx │ ├── logo.tsx │ ├── logo2.tsx │ └── page.tsx ├── components │ └── ui │ │ ├── accordion.tsx │ │ ├── alert-dialog.tsx │ │ ├── alert.tsx │ │ ├── aspect-ratio.tsx │ │ ├── avatar.tsx │ │ ├── badge.tsx │ │ ├── breadcrumb.tsx │ │ ├── button.tsx │ │ ├── calendar.tsx │ │ ├── card.tsx │ │ ├── carousel.tsx │ │ ├── chart.tsx │ │ ├── checkbox.tsx │ │ ├── collapsible.tsx │ │ ├── command.tsx │ │ ├── context-menu.tsx │ │ ├── dialog.tsx │ │ ├── drawer.tsx │ │ ├── dropdown-menu.tsx │ │ ├── form.tsx │ │ ├── hover-card.tsx │ │ ├── input-otp.tsx │ │ ├── input.tsx │ │ ├── label.tsx │ │ ├── menubar.tsx │ │ ├── navigation-menu.tsx │ │ ├── pagination.tsx │ │ ├── popover.tsx │ │ ├── progress.tsx │ │ ├── radio-group.tsx │ │ ├── resizable.tsx │ │ ├── scroll-area.tsx │ │ ├── select.tsx │ │ ├── separator.tsx │ │ ├── sheet.tsx │ │ ├── sidebar.tsx │ │ ├── skeleton.tsx │ │ ├── slider.tsx │ │ ├── sonner.tsx │ │ ├── switch.tsx │ │ ├── table.tsx │ │ ├── tabs.tsx │ │ ├── textarea.tsx │ │ ├── toast.tsx │ │ ├── toaster.tsx │ │ ├── toggle-group.tsx │ │ ├── toggle.tsx │ │ └── tooltip.tsx ├── hooks │ ├── use-mobile.tsx │ └── use-toast.ts └── lib │ └── utils.ts ├── tailwind.config.ts ├── tsconfig.json ├── turbo.json └── yarn.lock /.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. 2 | 3 | # dependencies 4 | /node_modules 5 | /.pnp 6 | .pnp.* 7 | .yarn/* 8 | !.yarn/patches 9 | !.yarn/plugins 10 | !.yarn/releases 11 | !.yarn/versions 12 | 13 | # testing 14 | /coverage 15 | 16 | # next.js 17 | /.next/ 18 | /out/ 19 | 20 | # production 21 | /build 22 | 23 | # misc 24 | .DS_Store 25 | *.pem 26 | 27 | # debug 28 | npm-debug.log* 29 | yarn-debug.log* 30 | yarn-error.log* 31 | 32 | # env files (can opt-in for committing if needed) 33 | .env* 34 | 35 | # vercel 36 | .vercel 37 | 38 | # typescript 39 | *.tsbuildinfo 40 | next-env.d.ts 41 | .env*.local 42 | 43 | .turbo -------------------------------------------------------------------------------- /.yarnrc.yml: -------------------------------------------------------------------------------- 1 | yarnPath: .yarn/releases/yarn-4.1.0.cjs 2 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # You2Txt 2 | 3 | 4 | 5 | I built You2Txt for the Vercel + Nvidia 2-hour hackathon. It turns any YouTube video into a transcribed `.txt` file. 6 | 7 | [**This project won first place in the hackathon 🏆**](https://x.com/FernandoTheRojo/status/1859848547316924465) 8 | 9 | It's hosted at [you2txt.com](https://you2txt.com). However, YouTube has been rate limiting requests coming from the lambda, so if you want to use it, you'll have more luck running it locally. 10 | 11 | If there's interest, maybe I can set up a self-hosted proxy or raspberry pi for the requests (until that inevitably gets rate limited). 12 | 13 | ## Local development 14 | 15 | This project was made with Next.js, Tailwind (shadcn), v0, and Claude (through Cursor's composer). 16 | 17 | ```sh 18 | yarn 19 | ``` 20 | 21 | ```sh 22 | yarn dev 23 | ``` 24 | 25 | ### Builds 26 | 27 | ```sh 28 | yarn build 29 | ``` 30 | 31 | Then open [http://localhost:3000](http://localhost:3000) 32 | -------------------------------------------------------------------------------- /components.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://ui.shadcn.com/schema.json", 3 | "style": "new-york", 4 | "rsc": true, 5 | "tsx": true, 6 | "tailwind": { 7 | "config": "tailwind.config.ts", 8 | "css": "src/app/globals.css", 9 | "baseColor": "neutral", 10 | "cssVariables": true, 11 | "prefix": "" 12 | }, 13 | "aliases": { 14 | "components": "@/components", 15 | "utils": "@/lib/utils", 16 | "ui": "@/components/ui", 17 | "lib": "@/lib", 18 | "hooks": "@/hooks" 19 | }, 20 | "iconLibrary": "lucide" 21 | } -------------------------------------------------------------------------------- /deno/route.ts: -------------------------------------------------------------------------------- 1 | import { GET } from "../src/app/[...url]/route"; 2 | 3 | // @ts-ignore 4 | Deno.serve(GET); 5 | -------------------------------------------------------------------------------- /next.config.ts: -------------------------------------------------------------------------------- 1 | import type { NextConfig } from "next"; 2 | 3 | const nextConfig: NextConfig = { 4 | /* config options here */ 5 | transpilePackages: ["geist"], 6 | typescript: { 7 | ignoreBuildErrors: true, 8 | }, 9 | }; 10 | 11 | export default nextConfig; 12 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "you2txt", 3 | "version": "0.1.0", 4 | "private": true, 5 | "scripts": { 6 | "dev": "next dev", 7 | "build": "next build", 8 | "start": "next start", 9 | "lint": "next lint" 10 | }, 11 | "dependencies": { 12 | "@hookform/resolvers": "^3.9.1", 13 | "@radix-ui/react-accordion": "^1.2.1", 14 | "@radix-ui/react-alert-dialog": "^1.1.2", 15 | "@radix-ui/react-aspect-ratio": "^1.1.0", 16 | "@radix-ui/react-avatar": "^1.1.1", 17 | "@radix-ui/react-checkbox": "^1.1.2", 18 | "@radix-ui/react-collapsible": "^1.1.1", 19 | "@radix-ui/react-context-menu": "^2.2.2", 20 | "@radix-ui/react-dialog": "^1.1.2", 21 | "@radix-ui/react-dropdown-menu": "^2.1.2", 22 | "@radix-ui/react-hover-card": "^1.1.2", 23 | "@radix-ui/react-label": "^2.1.0", 24 | "@radix-ui/react-menubar": "^1.1.2", 25 | "@radix-ui/react-navigation-menu": "^1.2.1", 26 | "@radix-ui/react-popover": "^1.1.2", 27 | "@radix-ui/react-progress": "^1.1.0", 28 | "@radix-ui/react-radio-group": "^1.2.1", 29 | "@radix-ui/react-scroll-area": "^1.2.1", 30 | "@radix-ui/react-select": "^2.1.2", 31 | "@radix-ui/react-separator": "^1.1.0", 32 | "@radix-ui/react-slider": "^1.2.1", 33 | "@radix-ui/react-slot": "^1.1.0", 34 | "@radix-ui/react-switch": "^1.1.1", 35 | "@radix-ui/react-tabs": "^1.1.1", 36 | "@radix-ui/react-toast": "^1.2.2", 37 | "@radix-ui/react-toggle": "^1.1.0", 38 | "@radix-ui/react-toggle-group": "^1.1.0", 39 | "@radix-ui/react-tooltip": "^1.1.4", 40 | "@upstash/redis": "^1.34.3", 41 | "class-variance-authority": "^0.7.0", 42 | "clsx": "^2.1.1", 43 | "cmdk": "^1.0.0", 44 | "date-fns": "^4.1.0", 45 | "dotenv": "^16.4.5", 46 | "embla-carousel-react": "^8.5.1", 47 | "framer-motion": "^11.11.17", 48 | "geist": "^1.3.1", 49 | "https-proxy-agent": "^7.0.5", 50 | "input-otp": "^1.4.1", 51 | "lucide-react": "^0.460.0", 52 | "next": "15.0.3", 53 | "next-themes": "^0.4.3", 54 | "node-fetch": "^3.3.2", 55 | "react": "19.0.0-rc-66855b96-20241106", 56 | "react-async-hook": "^4.0.0", 57 | "react-day-picker": "^8.10.1", 58 | "react-dom": "19.0.0-rc-66855b96-20241106", 59 | "react-hook-form": "^7.53.2", 60 | "react-resizable-panels": "^2.1.7", 61 | "recharts": "^2.13.3", 62 | "redis": "^4.7.0", 63 | "request-promise": "^4.2.6", 64 | "sonner": "^1.7.0", 65 | "tailwind-merge": "^2.5.4", 66 | "tailwindcss-animate": "^1.0.7", 67 | "vaul": "^1.1.1", 68 | "zod": "^3.23.8", 69 | "zustand": "^5.0.1" 70 | }, 71 | "devDependencies": { 72 | "@types/node": "^20", 73 | "@types/react": "^18", 74 | "@types/react-dom": "^18", 75 | "@types/request-promise": "^4", 76 | "postcss": "^8", 77 | "tailwindcss": "^3.4.1", 78 | "turbo": "^2.3.1", 79 | "typescript": "^5" 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /postcss.config.mjs: -------------------------------------------------------------------------------- 1 | /** @type {import('postcss-load-config').Config} */ 2 | const config = { 3 | plugins: { 4 | tailwindcss: {}, 5 | }, 6 | }; 7 | 8 | export default config; 9 | -------------------------------------------------------------------------------- /public/favicon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nandorojo/you2txt/5762ffd3f3096bd451ab1b14c9f90f9ab706c5c9/public/favicon.png -------------------------------------------------------------------------------- /public/file.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /public/globe.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /public/next.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /public/og.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nandorojo/you2txt/5762ffd3f3096bd451ab1b14c9f90f9ab706c5c9/public/og.png -------------------------------------------------------------------------------- /public/vercel.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /public/window.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/app/APP_URL.tsx: -------------------------------------------------------------------------------- 1 | export const APP_URL = "you2txt.com"; 2 | -------------------------------------------------------------------------------- /src/app/YouTube_full-color_icon_(2017) (1) 1.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nandorojo/you2txt/5762ffd3f3096bd451ab1b14c9f90f9ab706c5c9/src/app/YouTube_full-color_icon_(2017) (1) 1.ico -------------------------------------------------------------------------------- /src/app/[...url]/route.ts: -------------------------------------------------------------------------------- 1 | import { 2 | getYouTubeVideoId, 3 | TranscriptError, 4 | transcriptFromYouTubeId, 5 | transcriptToTextFile, 6 | } from "./youtube"; 7 | 8 | import { Buffer } from "node:buffer"; 9 | 10 | export async function GET(request: Request): Promise { 11 | try { 12 | const url = new URL(request.url); 13 | const { searchParams } = url; 14 | const videoParams = searchParams.getAll("v"); 15 | const includeTimestamps = searchParams.get("timestamps") === "true"; 16 | const filterOutMusic = searchParams.get("filterOutMusic") === "true"; 17 | 18 | // Get unique, valid video IDs 19 | const videoIds = [ 20 | ...new Set( 21 | videoParams 22 | .map((param) => getYouTubeVideoId(param)) 23 | .filter((id) => id !== null) 24 | ), 25 | ]; 26 | 27 | if (!videoIds.length) { 28 | const ending = url.toString().split(url.host)[1]; 29 | console.log("[ending]", ending); 30 | const id = getYouTubeVideoId(ending); 31 | if (id) { 32 | videoIds.push(id); 33 | } else { 34 | return new Response("No valid video IDs provided", { status: 400 }); 35 | } 36 | } 37 | 38 | // Fetch all transcripts in parallel 39 | const transcripts = await Promise.all( 40 | videoIds.map(async (id) => { 41 | const result = await transcriptFromYouTubeId(id); 42 | 43 | return { ...result, id }; 44 | }) 45 | ); 46 | 47 | // Filter out failed transcripts and format them 48 | const formattedTranscripts = transcripts 49 | .filter((t): t is NonNullable => t !== null) 50 | .map((t) => 51 | transcriptToTextFile({ 52 | transcript: t, 53 | includeTimestamps, 54 | filterOutMusic, 55 | }) 56 | ); 57 | 58 | if (!formattedTranscripts.length) { 59 | return new Response("Failed to fetch any transcripts", { status: 404 }); 60 | } 61 | 62 | // Combine all transcripts with separator 63 | const combinedText = formattedTranscripts.join( 64 | "\n\n====video ended====\n\n" 65 | ); 66 | 67 | const headers = new Headers(); 68 | headers.set("Content-Type", "text/plain; charset=utf-8"); 69 | transcripts.forEach(({ transcript, ...t }) => { 70 | if (t) { 71 | headers.set( 72 | "title", 73 | Buffer.from(t.videoTitle.toString()).toString("base64") 74 | ); 75 | if (t.imageUrl) { 76 | headers.set( 77 | "img-url", 78 | Buffer.from(t.imageUrl.toString()).toString("base64") 79 | ); 80 | } 81 | headers.set("id", Buffer.from(t.id.toString()).toString("base64")); 82 | } 83 | }); 84 | 85 | // Return plain text response 86 | return new Response(combinedText, { headers }); 87 | } catch (error) { 88 | if (error instanceof TranscriptError) { 89 | console.error("Transcript processing error:", error.message); 90 | return new Response(error.message, { status: 500 }); 91 | } 92 | console.error("Transcript processing error:", error); 93 | return new Response("Failed to process transcripts", { status: 500 }); 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /src/app/[...url]/youtube.ts: -------------------------------------------------------------------------------- 1 | import { Redis } from "@upstash/redis"; 2 | import { z } from "zod"; 3 | import fetch from "node-fetch"; 4 | 5 | const redis = new Redis({ 6 | url: process.env.KV_REST_API_URL, 7 | token: process.env.KV_REST_API_TOKEN, 8 | }); 9 | 10 | const CACHE_TTL = 60 * 60 * 24; // 24 hours in seconds 11 | 12 | interface TranscriptResponse { 13 | text: string; 14 | start: number; 15 | duration: number; 16 | } 17 | 18 | type TranscriptResult = z.infer; 19 | 20 | const transcriptResultSchema = z.object({ 21 | videoTitle: z.string(), 22 | description: z.string().nullish(), 23 | imageUrl: z.string().nullish(), 24 | transcript: z.array( 25 | z.object({ 26 | text: z.string(), 27 | start: z.number(), 28 | duration: z.number(), 29 | }) 30 | ), 31 | }); 32 | 33 | export class TranscriptError extends Error { 34 | message: string; 35 | constructor(message: string) { 36 | super(message); 37 | this.message = message; 38 | this.name = "TranscriptError"; 39 | } 40 | } 41 | 42 | function getRedisCacheKey(videoId: string) { 43 | return `youtube-transcript-${videoId}`; 44 | } 45 | 46 | // async function getVideoProxied(videoId: string) { 47 | // return new Promise((resolve, reject) => 48 | // request( 49 | // { 50 | // url: `https://www.youtube.com/watch?v=${videoId}`, 51 | // proxy: process.env.PROXY_URL, 52 | // }, 53 | // (err, res) => { 54 | // if (err) { 55 | // reject(err); 56 | // } else { 57 | // resolve(res); 58 | // } 59 | // } 60 | // ) 61 | // ); 62 | // } 63 | 64 | export async function transcriptFromYouTubeId( 65 | videoId: string, 66 | ignoreCache = process.env.KV_REST_API_URL == null, 67 | ): Promise { 68 | // Check cache first 69 | if (!ignoreCache) { 70 | const cacheKey = getRedisCacheKey(videoId); 71 | const cachedData = transcriptResultSchema.safeParse( 72 | await redis.get(cacheKey) 73 | ); 74 | console.log("cached!"); 75 | 76 | if (cachedData.success) { 77 | return cachedData.data; 78 | } 79 | } 80 | 81 | const videoUrl = `https://www.youtube.com/watch?v=${videoId}`; 82 | console.log("[proxy]", process.env.PROXY_URL); 83 | const response = await fetch(videoUrl, { 84 | // ...(process.env.PROXY_URL && { 85 | // agent: new HttpsProxyAgent(process.env.PROXY_URL), 86 | // }), 87 | }); 88 | 89 | if (!response.ok) { 90 | console.error("[oh nooo]", await response.text()); 91 | throw new TranscriptError( 92 | "Failed to fetch video. This might be a YouTube rate limit." 93 | ); 94 | } 95 | 96 | const html = await response.text(); 97 | 98 | // Extract player response data 99 | const playerResponseMatch = html.match( 100 | /ytInitialPlayerResponse\s*=\s*({.+?})\s*;/ 101 | ); 102 | if (!playerResponseMatch) { 103 | throw new TranscriptError("Could not find player response data"); 104 | } 105 | 106 | const playerResponse = JSON.parse(playerResponseMatch[1]); 107 | 108 | // Extract video metadata 109 | const videoTitle = playerResponse?.videoDetails?.title || "Untitled Video"; 110 | const description = playerResponse?.videoDetails?.shortDescription || ""; 111 | const imageUrl = 112 | playerResponse?.microformat?.playerMicroformatRenderer?.thumbnail 113 | ?.thumbnails[0]?.url; 114 | 115 | // Get captions data 116 | const captions = 117 | playerResponse?.captions?.playerCaptionsTracklistRenderer?.captionTracks; 118 | 119 | console.log("[captions]", JSON.stringify(playerResponse.captions)); 120 | console.log("[captions][keys]", Object.keys(playerResponse)); 121 | Object.keys(playerResponse).forEach((key) => { 122 | console.log("[key]", key, Object.keys(playerResponse[key])); 123 | console.log("[key][keys]", playerResponse[key]); 124 | }); 125 | console.log( 126 | "[captions][in HTML?]", 127 | JSON.stringify(playerResponse).toLowerCase().includes("caption") 128 | ); 129 | if (!captions?.length) { 130 | throw new TranscriptError( 131 | "We hit a rate limit. Fernando is probably checking on it. You can run the open source code on your own laptop to get around it. https://github.com/nandorojo/you2txt" 132 | ); 133 | } 134 | 135 | // Fetch transcript data 136 | const captionUrl = `${captions[0].baseUrl}&fmt=json3&lang=en`; 137 | console.log("[captionUrl]", captionUrl); 138 | const transcriptResponse = await fetch(captionUrl); 139 | const transcriptData = await transcriptResponse.json(); 140 | 141 | // Process transcript events 142 | const transcript = transcriptData.events 143 | ?.filter((event: any) => event?.segs?.some((seg: any) => seg?.utf8)) 144 | ?.map((event: any) => { 145 | const text = event.segs 146 | .map((seg: any) => seg.utf8?.trim()) 147 | .filter(Boolean) 148 | .join(" ") 149 | .trim(); 150 | 151 | return { 152 | text, 153 | start: Number((event.tStartMs / 1000).toFixed(3)), 154 | duration: Number((event.dDurationMs / 1000).toFixed(3)), 155 | }; 156 | }) 157 | .filter((item: TranscriptResponse) => item.text); 158 | 159 | if (!transcript?.length) { 160 | throw new TranscriptError("Failed to parse transcript data"); 161 | } 162 | 163 | const result = { 164 | videoTitle, 165 | description, 166 | transcript, 167 | imageUrl, 168 | }; 169 | 170 | // Cache the result 171 | const cacheKey = getRedisCacheKey(videoId); 172 | await redis.set(cacheKey, result, { 173 | ex: CACHE_TTL, 174 | }); 175 | 176 | return result; 177 | } 178 | 179 | export function getYouTubeVideoId(input: string): string | null { 180 | // Handle empty/undefined input 181 | if (!input?.trim()) { 182 | return null; 183 | } 184 | 185 | const trimmedInput = input.trim(); 186 | 187 | // Check for exact 11-character video ID pattern 188 | if (/^[a-zA-Z0-9_-]{11}$/.test(trimmedInput)) { 189 | return trimmedInput; 190 | } 191 | 192 | // Normalize URL format 193 | let normalizedUrl = trimmedInput; 194 | if (!normalizedUrl.startsWith("http")) { 195 | normalizedUrl = normalizedUrl.replace(/^\/\//, ""); 196 | normalizedUrl = `https://${normalizedUrl}`; 197 | } 198 | 199 | // Check against known URL patterns 200 | const patterns = [ 201 | /(?:youtu\.be\/|youtube\.com\/shorts\/|youtube\.com\/embed\/|youtube\.com\/v\/)([a-zA-Z0-9_-]{11})/, 202 | /youtube\.com\/watch.*[?&]v=([a-zA-Z0-9_-]{11})/, 203 | ]; 204 | 205 | for (const pattern of patterns) { 206 | const match = normalizedUrl.match(pattern); 207 | if (match?.[1]) { 208 | return match[1]; 209 | } 210 | } 211 | 212 | // Final attempt: Try parsing as URL 213 | try { 214 | const url = new URL(normalizedUrl); 215 | const videoId = url.searchParams.get("v"); 216 | if (videoId?.length === 11) { 217 | return videoId; 218 | } 219 | } catch { 220 | // URL parsing failed, ignore and return null 221 | } 222 | 223 | return null; 224 | } 225 | 226 | export function transcriptToTextFile({ 227 | transcript, 228 | includeTimestamps = true, 229 | filterOutMusic = false, 230 | }: { 231 | transcript: TranscriptResult; 232 | includeTimestamps?: boolean; 233 | filterOutMusic?: boolean; 234 | }): string { 235 | const { videoTitle, description, transcript: segments } = transcript; 236 | 237 | const lines: string[] = [ 238 | "--", 239 | `Title: ${videoTitle}`, 240 | "", 241 | `Description: ${description}`, 242 | "", 243 | "--", 244 | "", 245 | ]; 246 | 247 | const formatTimestamp = (seconds: number): string => { 248 | const minutes = Math.floor(seconds / 60); 249 | const remainingSeconds = Math.floor(seconds % 60); 250 | return `[${minutes.toString().padStart(2, "0")}:${remainingSeconds 251 | .toString() 252 | .padStart(2, "0")}]`; 253 | }; 254 | 255 | segments.forEach((segment) => { 256 | if (segment.text.trim() === "[Music]" && filterOutMusic) { 257 | return; 258 | } 259 | const line = includeTimestamps 260 | ? `${formatTimestamp(segment.start)} ${segment.text}` 261 | : segment.text; 262 | lines.push(line); 263 | }); 264 | 265 | return lines.join("\n"); 266 | } 267 | -------------------------------------------------------------------------------- /src/app/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nandorojo/you2txt/5762ffd3f3096bd451ab1b14c9f90f9ab706c5c9/src/app/favicon.ico -------------------------------------------------------------------------------- /src/app/favicon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nandorojo/you2txt/5762ffd3f3096bd451ab1b14c9f90f9ab706c5c9/src/app/favicon.png -------------------------------------------------------------------------------- /src/app/fonts/GeistMonoVF.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nandorojo/you2txt/5762ffd3f3096bd451ab1b14c9f90f9ab706c5c9/src/app/fonts/GeistMonoVF.woff -------------------------------------------------------------------------------- /src/app/fonts/GeistVF.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nandorojo/you2txt/5762ffd3f3096bd451ab1b14c9f90f9ab706c5c9/src/app/fonts/GeistVF.woff -------------------------------------------------------------------------------- /src/app/globals.css: -------------------------------------------------------------------------------- 1 | @tailwind base; 2 | @tailwind components; 3 | @tailwind utilities; 4 | 5 | body { 6 | font-family: Arial, Helvetica, sans-serif; 7 | } 8 | 9 | @layer base { 10 | :root { 11 | --background: 0 0% 100%; 12 | --foreground: 0 0% 3.9%; 13 | --card: 0 0% 100%; 14 | --card-foreground: 0 0% 3.9%; 15 | --popover: 0 0% 100%; 16 | --popover-foreground: 0 0% 3.9%; 17 | --primary: 0 0% 9%; 18 | --primary-foreground: 0 0% 98%; 19 | --secondary: 0 0% 96.1%; 20 | --secondary-foreground: 0 0% 9%; 21 | --muted: 0 0% 96.1%; 22 | --muted-foreground: 0 0% 45.1%; 23 | --accent: 0 0% 96.1%; 24 | --accent-foreground: 0 0% 9%; 25 | --destructive: 0 84.2% 60.2%; 26 | --destructive-foreground: 0 0% 98%; 27 | --border: 0 0% 89.8%; 28 | --input: 0 0% 89.8%; 29 | --ring: 0 0% 3.9%; 30 | --chart-1: 12 76% 61%; 31 | --chart-2: 173 58% 39%; 32 | --chart-3: 197 37% 24%; 33 | --chart-4: 43 74% 66%; 34 | --chart-5: 27 87% 67%; 35 | --radius: 0.5rem; 36 | --sidebar-background: 0 0% 98%; 37 | --sidebar-foreground: 240 5.3% 26.1%; 38 | --sidebar-primary: 240 5.9% 10%; 39 | --sidebar-primary-foreground: 0 0% 98%; 40 | --sidebar-accent: 240 4.8% 95.9%; 41 | --sidebar-accent-foreground: 240 5.9% 10%; 42 | --sidebar-border: 220 13% 91%; 43 | --sidebar-ring: 217.2 91.2% 59.8%; 44 | } 45 | .dark { 46 | --background: 0 0% 3.9%; 47 | --foreground: 0 0% 98%; 48 | --card: 0 0% 3.9%; 49 | --card-foreground: 0 0% 98%; 50 | --popover: 0 0% 3.9%; 51 | --popover-foreground: 0 0% 98%; 52 | --primary: 0 0% 98%; 53 | --primary-foreground: 0 0% 9%; 54 | --secondary: 0 0% 14.9%; 55 | --secondary-foreground: 0 0% 98%; 56 | --muted: 0 0% 14.9%; 57 | --muted-foreground: 0 0% 63.9%; 58 | --accent: 0 0% 14.9%; 59 | --accent-foreground: 0 0% 98%; 60 | --destructive: 0 62.8% 30.6%; 61 | --destructive-foreground: 0 0% 98%; 62 | --border: 0 0% 14.9%; 63 | --input: 0 0% 14.9%; 64 | --ring: 0 0% 83.1%; 65 | --chart-1: 220 70% 50%; 66 | --chart-2: 160 60% 45%; 67 | --chart-3: 30 80% 55%; 68 | --chart-4: 280 65% 60%; 69 | --chart-5: 340 75% 55%; 70 | --sidebar-background: 240 5.9% 10%; 71 | --sidebar-foreground: 240 4.8% 95.9%; 72 | --sidebar-primary: 224.3 76.3% 48%; 73 | --sidebar-primary-foreground: 0 0% 100%; 74 | --sidebar-accent: 240 3.7% 15.9%; 75 | --sidebar-accent-foreground: 240 4.8% 95.9%; 76 | --sidebar-border: 240 3.7% 15.9%; 77 | --sidebar-ring: 217.2 91.2% 59.8%; 78 | } 79 | } 80 | 81 | @layer base { 82 | * { 83 | @apply border-border; 84 | } 85 | body { 86 | @apply bg-background text-foreground; 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /src/app/history.tsx: -------------------------------------------------------------------------------- 1 | import { create } from "zustand"; 2 | import { persist } from "zustand/middleware"; 3 | import { createJSONStorage } from "zustand/middleware"; 4 | 5 | export const useTranscriptionHistory = create( 6 | persist<{ 7 | videos: { 8 | id: string; 9 | title: string; 10 | created_at: string; 11 | imgUrl: string; 12 | }[]; 13 | actions: { 14 | addVideo: (video: { id: string; title: string; imgUrl: string }) => void; 15 | removeVideo: (videoId: string) => void; 16 | }; 17 | }>( 18 | (set) => ({ 19 | videos: [], 20 | actions: { 21 | addVideo: (video) => 22 | set((state) => { 23 | if (state.videos.find((v) => v.id === video.id)) { 24 | return state; 25 | } 26 | return { 27 | videos: [ 28 | ...state.videos, 29 | { 30 | id: video.id, 31 | title: video.title, 32 | created_at: new Date().toISOString(), 33 | imgUrl: video.imgUrl, 34 | }, 35 | ], 36 | }; 37 | }), 38 | removeVideo: (videoId) => 39 | set((state) => ({ 40 | videos: state.videos.filter((v) => v.id !== videoId), 41 | })), 42 | }, 43 | }), 44 | { 45 | name: "transcription-history2", 46 | storage: createJSONStorage(() => localStorage), 47 | partialize({ actions, ...rest }) { 48 | return rest as any; 49 | }, 50 | } 51 | ) 52 | ); 53 | -------------------------------------------------------------------------------- /src/app/layout.tsx: -------------------------------------------------------------------------------- 1 | import type { Metadata } from "next"; 2 | import localFont from "next/font/local"; 3 | import "./globals.css"; 4 | import { Toaster } from "@/components/ui/toaster"; 5 | import { ThemeProvider } from "next-themes"; 6 | import { LogoFull } from "@/app/logo2"; 7 | import { APP_URL } from "@/app/APP_URL"; 8 | 9 | const geistSans = localFont({ 10 | src: "./fonts/GeistVF.woff", 11 | variable: "--font-geist-sans", 12 | weight: "100 900", 13 | }); 14 | const geistMono = localFont({ 15 | src: "./fonts/GeistMonoVF.woff", 16 | variable: "--font-geist-mono", 17 | weight: "100 900", 18 | }); 19 | 20 | export const metadata: Metadata = { 21 | title: "You2Txt - by Fernando Rojo", 22 | description: "YouTube Video → txt file", 23 | openGraph: { 24 | images: [ 25 | { 26 | url: `https://${APP_URL}/og.png`, 27 | width: 1200, 28 | height: 630, 29 | }, 30 | ], 31 | }, 32 | }; 33 | 34 | export default function RootLayout({ 35 | children, 36 | }: Readonly<{ 37 | children: React.ReactNode; 38 | }>) { 39 | return ( 40 | 41 | 47 | 53 | {children} 54 |
55 | 56 |
57 |
58 | 59 | 60 | 61 | ); 62 | } 63 | -------------------------------------------------------------------------------- /src/app/logo.tsx: -------------------------------------------------------------------------------- 1 | export const Logo = ({ width = 70 }: { width?: number }) => ( 2 | 9 | 10 | 11 | 15 | 16 | 20 | 24 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | ); 40 | -------------------------------------------------------------------------------- /src/app/logo2.tsx: -------------------------------------------------------------------------------- 1 | export const LogoFull = ({ width = 130 }: { width?: number }) => ( 2 | 9 | 10 | 11 | 15 | 16 | 20 | 24 | 28 | 29 | 30 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | ); 44 | -------------------------------------------------------------------------------- /src/app/page.tsx: -------------------------------------------------------------------------------- 1 | "use client"; 2 | 3 | import { Button } from "@/components/ui/button"; 4 | import { Checkbox } from "@/components/ui/checkbox"; 5 | import { Input } from "@/components/ui/input"; 6 | import { 7 | Dialog, 8 | DialogContent, 9 | DialogHeader, 10 | DialogTitle, 11 | } from "@/components/ui/dialog"; 12 | import { useState } from "react"; 13 | import { useAsyncCallback } from "react-async-hook"; 14 | import { Copy, Menu, Settings, Text } from "lucide-react"; 15 | import { toast, useToast } from "@/hooks/use-toast"; 16 | import { APP_URL } from "./APP_URL"; 17 | import { 18 | Popover, 19 | PopoverContent, 20 | PopoverTrigger, 21 | } from "@/components/ui/popover"; 22 | import { useTranscriptionHistory } from "@/app/history"; 23 | import { useRef } from "react"; 24 | import { useEffect } from "react"; 25 | import Image from "next/image"; 26 | import clsx from "clsx"; 27 | import { AnimatePresence, motion } from "framer-motion"; 28 | import Link from "next/link"; 29 | 30 | function useMutation() { 31 | return useAsyncCallback( 32 | async ( 33 | url: string, 34 | includeTimestamps: boolean, 35 | filterOutMusic: boolean 36 | ) => { 37 | const response = await fetch( 38 | `/${url}×tamps=${includeTimestamps}&filterOutMusic=${filterOutMusic}` 39 | ); 40 | const id = response.headers.get("id"); 41 | const title = response.headers.get("title"); 42 | const imgUrl = response.headers.get("img-url"); 43 | if (id && title && imgUrl) { 44 | const s = useTranscriptionHistory.getState(); 45 | 46 | s.actions.addVideo({ 47 | id: decodeURIComponent(atob(id)), 48 | title: decodeURIComponent(atob(title)), 49 | imgUrl: decodeURIComponent(atob(imgUrl)), 50 | }); 51 | } else if (response.ok) { 52 | toast({ 53 | title: "Transcript created, but...", 54 | description: "We couldn't save it to your history.", 55 | }); 56 | } 57 | return response.text(); 58 | }, 59 | { 60 | onError(e, options) { 61 | toast({ 62 | title: "Error", 63 | description: e.message || "Is that a valid YouTube URL?", 64 | variant: "destructive", 65 | }); 66 | }, 67 | } 68 | ); 69 | } 70 | 71 | export default function Page() { 72 | const [url, setUrl] = useState(""); 73 | const [includeTimestamps, setIncludeTimestamps] = useState(true); 74 | const [filterOutMusic, setFilterOutMusic] = useState(true); 75 | const { toast } = useToast(); 76 | 77 | const mutation = useMutation(); 78 | 79 | return ( 80 |
81 | 89 |
90 | 91 |
92 |
93 |
94 | 95 |
96 | 97 |
{ 99 | e.preventDefault(); 100 | if (!url) return; 101 | 102 | mutation.execute(url, includeTimestamps, filterOutMusic); 103 | }} 104 | className='w-full space-y-4 self-center max-w-[680px]' 105 | > 106 |

107 | YouTube Video → txt file 108 |

109 |

110 | Transcribe any YouTube video into a text file and use it to train 111 | your LLM. 112 |

113 |
114 |
115 | {APP_URL}/ 116 |
117 | setUrl(e.target.value)} 123 | disabled={mutation.loading} 124 | required 125 | autoFocus 126 | style={ 127 | { 128 | // boxShadow: "0 8px 29px -2px", 129 | } 130 | } 131 | /> 132 |
133 | 134 |
135 | 142 | 143 | 144 | 147 | 148 | 149 |
150 | 154 | setIncludeTimestamps(checked as boolean) 155 | } 156 | /> 157 | 163 |
164 | 165 |
166 | 170 | setFilterOutMusic(checked as boolean) 171 | } 172 | /> 173 | 179 |
180 |
181 |
182 |
183 |
184 | 185 | { 188 | mutation.reset(); 189 | }} 190 | /> 191 | 192 | 193 |
194 | By @FernandoTheRojo 195 |
196 |
197 |
198 |
199 | ); 200 | } 201 | 202 | function TranscriptDialog({ 203 | transcript, 204 | onClose, 205 | }: { 206 | transcript: string | undefined; 207 | onClose: () => void; 208 | }) { 209 | const prev = useRef(transcript); 210 | useEffect(() => { 211 | if (transcript) prev.current = transcript; 212 | }); 213 | return ( 214 | !n && onClose()}> 215 | 216 | 217 | Transcript 218 | 219 |
220 | {transcript ?? prev.current} 221 |
222 |
223 | 238 |
239 |
240 |
241 | ); 242 | } 243 | 244 | function HistoryDialog() { 245 | return ( 246 | 247 | 248 | 249 | 250 | 254 | 255 | 256 | 257 | ); 258 | } 259 | 260 | function History() { 261 | const history = useTranscriptionHistory(); 262 | return ( 263 | 264 | {history.videos.length === 0 265 | ? null 266 | : history.videos 267 | .slice() 268 | .reverse() 269 | .map((video) => { 270 | if (!video.imgUrl) return null; 271 | if (!video.title) return null; 272 | if (!video.id) return null; 273 | return ; 274 | })} 275 | 276 | ); 277 | } 278 | 279 | function HistoryItem({ 280 | id, 281 | title, 282 | imgUrl, 283 | }: { 284 | id: string; 285 | title: string; 286 | imgUrl: string; 287 | }) { 288 | const mutation = useMutation(); 289 | return ( 290 | <> 291 | 293 | mutation.execute(`https://www.youtube.com/watch?v=${id}`, true, true) 294 | } 295 | className={clsx( 296 | "p-2 rounded-lg bg-muted flex flex-col gap-3 cursor-pointer border-slate-400 shadow-sm", 297 | mutation.loading && "opacity-50" 298 | )} 299 | layoutId={id} 300 | > 301 | {title} 313 |
314 | {title} 315 |
316 |
317 | 318 | { 321 | mutation.reset(); 322 | }} 323 | /> 324 | 325 | ); 326 | } 327 | -------------------------------------------------------------------------------- /src/components/ui/accordion.tsx: -------------------------------------------------------------------------------- 1 | "use client" 2 | 3 | import * as React from "react" 4 | import * as AccordionPrimitive from "@radix-ui/react-accordion" 5 | import { ChevronDown } from "lucide-react" 6 | 7 | import { cn } from "@/lib/utils" 8 | 9 | const Accordion = AccordionPrimitive.Root 10 | 11 | const AccordionItem = React.forwardRef< 12 | React.ElementRef, 13 | React.ComponentPropsWithoutRef 14 | >(({ className, ...props }, ref) => ( 15 | 20 | )) 21 | AccordionItem.displayName = "AccordionItem" 22 | 23 | const AccordionTrigger = React.forwardRef< 24 | React.ElementRef, 25 | React.ComponentPropsWithoutRef 26 | >(({ className, children, ...props }, ref) => ( 27 | 28 | svg]:rotate-180", 32 | className 33 | )} 34 | {...props} 35 | > 36 | {children} 37 | 38 | 39 | 40 | )) 41 | AccordionTrigger.displayName = AccordionPrimitive.Trigger.displayName 42 | 43 | const AccordionContent = React.forwardRef< 44 | React.ElementRef, 45 | React.ComponentPropsWithoutRef 46 | >(({ className, children, ...props }, ref) => ( 47 | 52 |
{children}
53 |
54 | )) 55 | AccordionContent.displayName = AccordionPrimitive.Content.displayName 56 | 57 | export { Accordion, AccordionItem, AccordionTrigger, AccordionContent } 58 | -------------------------------------------------------------------------------- /src/components/ui/alert-dialog.tsx: -------------------------------------------------------------------------------- 1 | "use client" 2 | 3 | import * as React from "react" 4 | import * as AlertDialogPrimitive from "@radix-ui/react-alert-dialog" 5 | 6 | import { cn } from "@/lib/utils" 7 | import { buttonVariants } from "@/components/ui/button" 8 | 9 | const AlertDialog = AlertDialogPrimitive.Root 10 | 11 | const AlertDialogTrigger = AlertDialogPrimitive.Trigger 12 | 13 | const AlertDialogPortal = AlertDialogPrimitive.Portal 14 | 15 | const AlertDialogOverlay = React.forwardRef< 16 | React.ElementRef, 17 | React.ComponentPropsWithoutRef 18 | >(({ className, ...props }, ref) => ( 19 | 27 | )) 28 | AlertDialogOverlay.displayName = AlertDialogPrimitive.Overlay.displayName 29 | 30 | const AlertDialogContent = React.forwardRef< 31 | React.ElementRef, 32 | React.ComponentPropsWithoutRef 33 | >(({ className, ...props }, ref) => ( 34 | 35 | 36 | 44 | 45 | )) 46 | AlertDialogContent.displayName = AlertDialogPrimitive.Content.displayName 47 | 48 | const AlertDialogHeader = ({ 49 | className, 50 | ...props 51 | }: React.HTMLAttributes) => ( 52 |
59 | ) 60 | AlertDialogHeader.displayName = "AlertDialogHeader" 61 | 62 | const AlertDialogFooter = ({ 63 | className, 64 | ...props 65 | }: React.HTMLAttributes) => ( 66 |
73 | ) 74 | AlertDialogFooter.displayName = "AlertDialogFooter" 75 | 76 | const AlertDialogTitle = React.forwardRef< 77 | React.ElementRef, 78 | React.ComponentPropsWithoutRef 79 | >(({ className, ...props }, ref) => ( 80 | 85 | )) 86 | AlertDialogTitle.displayName = AlertDialogPrimitive.Title.displayName 87 | 88 | const AlertDialogDescription = React.forwardRef< 89 | React.ElementRef, 90 | React.ComponentPropsWithoutRef 91 | >(({ className, ...props }, ref) => ( 92 | 97 | )) 98 | AlertDialogDescription.displayName = 99 | AlertDialogPrimitive.Description.displayName 100 | 101 | const AlertDialogAction = React.forwardRef< 102 | React.ElementRef, 103 | React.ComponentPropsWithoutRef 104 | >(({ className, ...props }, ref) => ( 105 | 110 | )) 111 | AlertDialogAction.displayName = AlertDialogPrimitive.Action.displayName 112 | 113 | const AlertDialogCancel = React.forwardRef< 114 | React.ElementRef, 115 | React.ComponentPropsWithoutRef 116 | >(({ className, ...props }, ref) => ( 117 | 126 | )) 127 | AlertDialogCancel.displayName = AlertDialogPrimitive.Cancel.displayName 128 | 129 | export { 130 | AlertDialog, 131 | AlertDialogPortal, 132 | AlertDialogOverlay, 133 | AlertDialogTrigger, 134 | AlertDialogContent, 135 | AlertDialogHeader, 136 | AlertDialogFooter, 137 | AlertDialogTitle, 138 | AlertDialogDescription, 139 | AlertDialogAction, 140 | AlertDialogCancel, 141 | } 142 | -------------------------------------------------------------------------------- /src/components/ui/alert.tsx: -------------------------------------------------------------------------------- 1 | import * as React from "react" 2 | import { cva, type VariantProps } from "class-variance-authority" 3 | 4 | import { cn } from "@/lib/utils" 5 | 6 | const alertVariants = cva( 7 | "relative w-full rounded-lg border px-4 py-3 text-sm [&>svg+div]:translate-y-[-3px] [&>svg]:absolute [&>svg]:left-4 [&>svg]:top-4 [&>svg]:text-foreground [&>svg~*]:pl-7", 8 | { 9 | variants: { 10 | variant: { 11 | default: "bg-background text-foreground", 12 | destructive: 13 | "border-destructive/50 text-destructive dark:border-destructive [&>svg]:text-destructive", 14 | }, 15 | }, 16 | defaultVariants: { 17 | variant: "default", 18 | }, 19 | } 20 | ) 21 | 22 | const Alert = React.forwardRef< 23 | HTMLDivElement, 24 | React.HTMLAttributes & VariantProps 25 | >(({ className, variant, ...props }, ref) => ( 26 |
32 | )) 33 | Alert.displayName = "Alert" 34 | 35 | const AlertTitle = React.forwardRef< 36 | HTMLParagraphElement, 37 | React.HTMLAttributes 38 | >(({ className, ...props }, ref) => ( 39 |
44 | )) 45 | AlertTitle.displayName = "AlertTitle" 46 | 47 | const AlertDescription = React.forwardRef< 48 | HTMLParagraphElement, 49 | React.HTMLAttributes 50 | >(({ className, ...props }, ref) => ( 51 |
56 | )) 57 | AlertDescription.displayName = "AlertDescription" 58 | 59 | export { Alert, AlertTitle, AlertDescription } 60 | -------------------------------------------------------------------------------- /src/components/ui/aspect-ratio.tsx: -------------------------------------------------------------------------------- 1 | "use client" 2 | 3 | import * as AspectRatioPrimitive from "@radix-ui/react-aspect-ratio" 4 | 5 | const AspectRatio = AspectRatioPrimitive.Root 6 | 7 | export { AspectRatio } 8 | -------------------------------------------------------------------------------- /src/components/ui/avatar.tsx: -------------------------------------------------------------------------------- 1 | "use client" 2 | 3 | import * as React from "react" 4 | import * as AvatarPrimitive from "@radix-ui/react-avatar" 5 | 6 | import { cn } from "@/lib/utils" 7 | 8 | const Avatar = React.forwardRef< 9 | React.ElementRef, 10 | React.ComponentPropsWithoutRef 11 | >(({ className, ...props }, ref) => ( 12 | 20 | )) 21 | Avatar.displayName = AvatarPrimitive.Root.displayName 22 | 23 | const AvatarImage = React.forwardRef< 24 | React.ElementRef, 25 | React.ComponentPropsWithoutRef 26 | >(({ className, ...props }, ref) => ( 27 | 32 | )) 33 | AvatarImage.displayName = AvatarPrimitive.Image.displayName 34 | 35 | const AvatarFallback = React.forwardRef< 36 | React.ElementRef, 37 | React.ComponentPropsWithoutRef 38 | >(({ className, ...props }, ref) => ( 39 | 47 | )) 48 | AvatarFallback.displayName = AvatarPrimitive.Fallback.displayName 49 | 50 | export { Avatar, AvatarImage, AvatarFallback } 51 | -------------------------------------------------------------------------------- /src/components/ui/badge.tsx: -------------------------------------------------------------------------------- 1 | import * as React from "react" 2 | import { cva, type VariantProps } from "class-variance-authority" 3 | 4 | import { cn } from "@/lib/utils" 5 | 6 | const badgeVariants = cva( 7 | "inline-flex items-center rounded-md border px-2.5 py-0.5 text-xs font-semibold transition-colors focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2", 8 | { 9 | variants: { 10 | variant: { 11 | default: 12 | "border-transparent bg-primary text-primary-foreground shadow hover:bg-primary/80", 13 | secondary: 14 | "border-transparent bg-secondary text-secondary-foreground hover:bg-secondary/80", 15 | destructive: 16 | "border-transparent bg-destructive text-destructive-foreground shadow hover:bg-destructive/80", 17 | outline: "text-foreground", 18 | }, 19 | }, 20 | defaultVariants: { 21 | variant: "default", 22 | }, 23 | } 24 | ) 25 | 26 | export interface BadgeProps 27 | extends React.HTMLAttributes, 28 | VariantProps {} 29 | 30 | function Badge({ className, variant, ...props }: BadgeProps) { 31 | return ( 32 |
33 | ) 34 | } 35 | 36 | export { Badge, badgeVariants } 37 | -------------------------------------------------------------------------------- /src/components/ui/breadcrumb.tsx: -------------------------------------------------------------------------------- 1 | import * as React from "react" 2 | import { Slot } from "@radix-ui/react-slot" 3 | import { ChevronRight, MoreHorizontal } from "lucide-react" 4 | 5 | import { cn } from "@/lib/utils" 6 | 7 | const Breadcrumb = React.forwardRef< 8 | HTMLElement, 9 | React.ComponentPropsWithoutRef<"nav"> & { 10 | separator?: React.ReactNode 11 | } 12 | >(({ ...props }, ref) =>