PageSourceSearch

https://clipchat.ai/dist/assets/index-BuOQZUEr.js

js clipchat.ai collected 2026-10-05 11:56:25 UTC 45,815 bytes, 1 lines download raw bytes

1var e=Object.defineProperty,t=Object.defineProperties,r=Object.getOwnPropertyDescriptors,n=Object.getOwnPropertySymbols,o=Object.prototype.hasOwnProperty,s=Object.prototype.propertyIsEnumerable,i=(t,r,n)=>r in t?e(t,r,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[r]=n,a=(e,t)=>{for(var r in t||(t={}))o.call(t,r)&&i(e,r,t[r]);if(n)for(var r of n(t))s.call(t,r)&&i(e,r,t[r]);return e},l=(e,n)=>t(e,r(n)),c=(e,t,r)=>new Promise((n,o)=>{var s=e=>{try{a(r.next(e))}catch(t){o(t)}},i=e=>{try{a(r.throw(e))}catch(t){o(t)}},a=e=>e.done?n(e.value):Promise.resolve(e.value).then(s,i);a((r=r.apply(e,t)).next())});import{j as d,T as u,at as p,aE as m,a6 as h,a4 as x,ak as g,gw as w,al as b,B as y,aA as f,c5 as j,D as T,cI as v,aQ as C,bj as k,a5 as _,aL as S,aa as I,cm as L,m as D,I as M,aK as z,cX as A,c_ as R,br as P,fW as E,cA as $,Y as U,p as W,cU as V,C as O,a1 as H,a3 as Y,b9 as F,bg as B,cv as N,gx as G,gy as q,gz as X,r as K,ff as Q,gA as J,R as Z,gp as ee,U as te,c as re,dG as ne,L as oe}from"./vendor-mui-CBxi4-UE.js";import{a as se,f as ie,u as ae}from"./vendor-react-DJCar8wk.js";import{a as le,b as ce,D as de,s as ue,p as pe,bs as me,u as he,o as xe}from"./main-fFbGxLEq.js";import{Y as ge,G as we,a as be,b as ye,A as fe,C as je}from"./queries-CO0uZbZK.js";import"./index-Cc7IhL_s.js";import"./vendor-utils-hGafao2v.js";const Te=e=>{if(!e)return"0:00";return`${Math.floor(e/60)}:${Math.floor(e%60).toString().padStart(2,"0")}`},ve=e=>navigator.clipboard.writeText(e).then(()=>{alert("Copied to clipboard!")}).catch(e=>{}),Ce=({onTaskCreated:e,onTaskCompleted:t})=>{const[r,n]=se.useState(""),[o,s]=se.useState(""),[i,a]=se.useState(null),[l,{loading:c,error:k}]=le(ge,{onCompleted:t=>{"queued"===t.youtubeMp3Download.status&&t.youtubeMp3Download.taskId&&e(t.youtubeMp3Download.taskId),a({status:t.youtubeMp3Download.status,msg:t.youtubeMp3Download.msg})}}),_=e=>{ve(e)};return d.jsxs(d.Fragment,{children:[d.jsxs(u,{variant:"subtitle1",color:"primary.dark",fontWeight:600,gutterBottom:!0,sx:{display:"flex",alignItems:"center"},children:[d.jsx(p,{color:"error",sx:{mr:1,fontSize:20}}),"Download Audio from YouTube"]}),d.jsx(u,{variant:"body2",color:"text.secondary",paragraph:!0,sx:{mb:3},children:"Enter a YouTube URL or video ID to download audio. You can then transcribe and enhance with AI."}),d.jsx("form",{onSubmit:e=>{e.preventDefault();const t=(e=>{if(!e)return"";const t=[/(?:youtube\.com\/watch\?v=|youtu\.be\/)([^&]+)/,/youtube\.com\/embed\/([^?]+)/,/youtube\.com\/v\/([^?]+)/,/youtube\.com\/user\/[^/]+\/\?v=([^&]+)/,/youtube\.com\/user\/[^/]+\/([^?]+)/,/youtube\.com\/y\/([^?]+)/,/youtube\.com\/shorts\/([^?]+)/];for(const r of t){const t=e.match(r);if(t&&t[1])return t[1]}return/^[a-zA-Z0-9_-]{11}$/.test(e)?e:""})(r);t?(a(null),l({variables:{input:{youtubeId:t,filename:o||null}}})):alert("Invalid YouTube URL or ID")},children:d.jsxs(m,{container:!0,spacing:2,children:[d.jsx(m,{item:!0,xs:12,children:d.jsx(h,{label:"YouTube URL or Video ID",variant:"outlined",fullWidth:!0,required:!0,value:r,onChange:e=>n(e.target.value),placeholder:"https://www.youtube.com/watch?v=dQw4w9WgXcQ or dQw4w9WgXcQ",InputProps:{startAdornment:d.jsx(p,{color:"error",sx:{mr:1}})},sx:{"& .MuiOutlinedInput-root":{borderRadius:"8px"}}})}),d.jsx(m,{item:!0,xs:12,children:d.jsx(h,{label:"Custom Filename (optional)",variant:"outlined",fullWidth:!0,value:o,onChange:e=>s(e.target.value),placeholder:"my_awesome_music",helperText:"Leave empty to use the video title",sx:{"& .MuiOutlinedInput-root":{borderRadius:"8px"}}})}),d.jsx(m,{item:!0,xs:12,sx:{mt:1},children:d.jsx(x,{type:"submit",variant:"contained",color:"primary",size:"large",disabled:c||!r,startIcon:c?d.jsx(g,{size:24,color:"inherit"}):d.jsx(w,{}),fullWidth:!0,sx:{py:1.5,borderRadius:"8px",textTransform:"none",fontWeight:600},children:c?"Processing...":"Download MP3"})})]})}),k&&d.jsxs(b,{severity:"error",sx:{mt:3},children:["Error: ",k.message]}),i&&d.jsxs(y,{mt:4,children:[i.msg&&d.jsx(b,{severity:"ok"===i.status||"queued"===i.status?"success":"error",sx:{mb:3},children:i.msg}),"ok"===i.status&&d.jsx(f,{variant:"outlined",sx:{mb:3},children:d.jsxs(j,{children:[d.jsx(u,{variant:"h6",gutterBottom:!0,children:i.youtubeTitle}),d.jsxs(u,{variant:"body2",color:"text.secondary",gutterBottom:!0,children:["Duration: ",Te(i.youtubeDuration)]}),d.jsx(T,{sx:{my:2}}),d.jsxs(y,{sx:{my:2},children:[d.jsx(u,{variant:"subtitle2",gutterBottom:!0,children:"Local URL:"}),d.jsxs(y,{sx:{display:"flex",alignItems:"center",bgcolor:e=>"dark"===e.palette.mode?"action.hover":"grey.100",p:1,borderRadius:1},children:[d.jsx(v,{href:i.localUrl,target:"_blank",rel:"noopener",sx:{flex:1,mr:1},children:i.localUrl}),d.jsx(x,{size:"small",startIcon:d.jsx(C,{}),onClick:()=>_(window.location.origin+i.localUrl),children:"Copy"})]})]}),d.jsxs(y,{sx:{my:2},children:[d.jsx(u,{variant:"subtitle2",gutterBottom:!0,children:"S3/CloudFront URL:"}),d.jsxs(y,{sx:{display:"flex",alignItems:"center",bgcolor:e=>"dark"===e.palette.mode?"action.hover":"grey.100",p:1,borderRadius:1},children:[d.jsx(v,{href:i.s3Url,target:"_blank",rel:"noopener",sx:{flex:1,mr:1},children:i.s3Url}),d.jsx(x,{size:"small",startIcon:d.jsx(C,{}),onClick:()=>_(i.s3Url),children:"Copy"})]})]}),d.jsx(y,{sx:{mt:3,textAlign:"center"},children:d.jsx(x,{variant:"contained",color:"primary",startIcon:d.jsx(w,{}),component:"a",href:`${i.s3Url}?dl=true&filename=${encodeURIComponent(i.youtubeTitle||"youtube_mp3")}.mp3`,download:!0,children:"Download MP3"})})]})})]})]})},ke=({task:e,isPlaying:t,onPlay:r,onStop:n,onCopy:o,onTranscribe:s,onViewTranscription:i,isTranscribing:a,inLongVideoFlow:l=!1,onSelectForLongVideo:c})=>d.jsxs(f,{elevation:0,sx:{mb:2,border:"1px solid",borderColor:"divider",borderRadius:2,bgcolor:"background.paper",transition:"all 0.3s ease",overflow:"visible","&:hover":{transform:"translateY(-4px)",boxShadow:"0 8px 16px rgba(0,0,0,0.1)"}},children:[d.jsxs(j,{sx:{pt:2,pb:1},children:[d.jsx(m,{container:!0,spacing:2,children:d.jsx(m,{item:!0,xs:12,children:d.jsxs(y,{sx:{display:"flex",alignItems:"flex-start",justifyContent:"space-between"},children:[d.jsxs(y,{sx:{display:"flex",alignItems:"flex-start",maxWidth:"70%"},children:[d.jsx(k,{color:"primary",sx:{mt:.5,mr:1.5,fontSize:20}}),d.jsxs(y,{children:[d.jsx(u,{variant:"subtitle1",sx:{fontWeight:t?700:600,color:t?"primary.main":"text.primary",lineHeight:1.3,mb:.5},children:e.youtubeTitle||`YouTube MP3 ${e.id}`}),d.jsxs(_,{direction:"row",spacing:1,alignItems:"center",sx:{mb:1},children:[d.jsxs(u,{variant:"body2",color:"text.secondary",sx:{dis
1play:"flex",alignItems:"center"},children:[d.jsx(S,{fontSize:"small",sx:{mr:.5,fontSize:16,opacity:.7}}),Te(e.duration)]}),d.jsx(u,{variant:"body2",color:"text.secondary",children:"•"}),d.jsxs(u,{variant:"body2",color:"text.secondary",sx:{display:"flex",alignItems:"center"},children:[d.jsx(p,{fontSize:"small",sx:{mr:.5,fontSize:16,opacity:.7}}),e.youtubeId]})]})]})]}),d.jsxs(y,{children:[t&&d.jsx(I,{size:"small",label:"Now Playing",color:"primary",sx:{borderRadius:"16px",fontWeight:500}}),e.hasTranscription&&d.jsx(I,{size:"small",label:"Transcribed",color:"success",variant:"outlined",sx:{borderRadius:"16px",ml:t?1:0}})]})]})})}),d.jsxs(u,{variant:"caption",color:"text.secondary",sx:{display:"block",mt:1,mb:.5},children:["Downloaded: ",new Date(e.createdAt).toLocaleString()]})]}),d.jsx(T,{}),d.jsxs(L,{sx:{p:1,justifyContent:"space-between",flexWrap:"wrap"},children:[d.jsxs(y,{children:[d.jsx(D,{title:t?"Stop Audio":"Play Audio",children:d.jsx(M,{size:"small",color:t?"secondary":"primary",onClick:()=>t?n():r(e.s3Url),children:t?d.jsx(k,{}):d.jsx(z,{})})}),d.jsx(D,{title:"Download MP3",children:d.jsx(M,{size:"small",color:"secondary",component:"a",href:`${e.s3Url}?dl=true&filename=${encodeURIComponent(e.youtubeTitle||`youtube_mp3_${e.youtubeId}`)}.mp3`,download:!0,children:d.jsx(w,{})})}),d.jsx(D,{title:"Open on YouTube",children:d.jsx(M,{size:"small",color:"error",component:"a",href:`https://www.youtube.com/watch?v=${e.youtubeId}`,target:"_blank",children:d.jsx(A,{})})})]}),d.jsx(y,{sx:{mt:{xs:1,sm:0},display:"flex",gap:1},children:a?d.jsx(x,{variant:"outlined",color:"secondary",disabled:!0,startIcon:d.jsx(g,{size:16}),sx:{borderRadius:"8px",textTransform:"none"},children:"Transcribing..."}):e.hasTranscription?d.jsx(d.Fragment,{children:d.jsx(x,{variant:"contained",color:"info",startIcon:d.jsx(R,{}),onClick:()=>{i(e.id)},sx:{borderRadius:"8px",textTransform:"none",fontWeight:500},children:"View Text"})}):d.jsx(x,{variant:"contained",color:"success",startIcon:d.jsx(P,{}),onClick:()=>s(e.id),sx:{borderRadius:"8px",textTransform:"none",fontWeight:500},children:"Transcribe"})})]})]}),_e=F(y)(({theme:e})=>({display:"flex",flexDirection:"column",height:"100%",width:"100%",margin:"0 auto"})),Se=F(y)(({theme:e})=>({flexGrow:1,overflowY:"auto",padding:e.spacing(2),marginBottom:e.spacing(2),border:`1px solid ${e.palette.divider}`,borderRadius:e.spacing(1),background:e.palette.background.default,minHeight:"300px",maxHeight:"60vh",width:"100%"})),Ie=F(U)(({theme:e,isuser:t})=>({padding:e.spacing(1.5,2),marginBottom:e.spacing(1.5),maxWidth:"true"===t?"85%":"95%",minWidth:"true"===t?"auto":"70%",wordBreak:"break-word",backgroundColor:"true"===t?e.palette.primary.light:e.palette.grey[100],color:"true"===t?e.palette.primary.contrastText:e.palette.text.primary,alignSelf:"true"===t?"flex-end":"flex-start",borderRadius:"true"===t?"18px 18px 0 18px":"18px 18px 18px 0",boxShadow:"0 1px 2px rgba(0,0,0,0.1)",width:"true"===t?"auto":"calc(100% - 40px)","& pre":{backgroundColor:"true"===t?"rgba(0, 0, 0, 0.1)":"rgba(0, 0, 0, 0.05)",padding:e.spacing(1),borderRadius:e.spacing(.5),overflowX:"auto",margin:e.spacing(1,0),fontSize:"0.9em",border:"1px solid",borderColor:"true"===t?"rgba(255, 255, 255, 0.2)":"rgba(0, 0, 0, 0.1)"},"& ul, & ol":{paddingLeft:e.spacing(2.5),marginTop:e.spacing(.5),marginBottom:e.spacing(.5)},"& a":{color:"true"===t?"rgba(255, 255, 255, 0.9)":e.palette.primary.main,textDecoration:"underline","&:hover":{textDecoration:"none"}}})),Le=F(y)(({theme:e})=>({display:"flex",gap:e.spacing(1),marginTop:e.spacing(2)})),De=F(u)(({theme:e})=>({padding:e.spacing(1),fontSize:"0.8rem",color:e.palette.text.secondary,fontStyle:"italic",display:"flex",alignItems:"center",gap:e.spacing(1)})),Me=F(y)(({theme:e})=>({display:"flex",flexWrap:"wrap",gap:e.spacing(1),padding:e.spacing(1),borderRadius:e.shape.borderRadius,width:"100%",margin:"4px 0"})),ze=F(x)(({theme:e,actiontype:t})=>a(a(a(a({margin:e.spacing(.5),transition:"all 0.2s ease-in-out",borderRadius:"8px",fontWeight:600,textTransform:"none",padding:e.spacing(1,2.5),fontSize:"0.9rem",boxShadow:e.shadows[1],minWidth:"140px","&:hover":{transform:"translateY(-2px)",boxShadow:e.shadows[3]}},"primary"===t&&{backgroundColor:e.palette.secondary.main,color:e.palette.secondary.c
1ontrastText,"&:hover":{backgroundColor:e.palette.secondary.dark,transform:"translateY(-2px)",boxShadow:e.shadows[3]}}),"secondary"===t&&{backgroundColor:e.palette.primary.main,color:e.palette.primary.contrastText,"&:hover":{backgroundColor:e.palette.primary.dark,transform:"translateY(-2px)",boxShadow:e.shadows[3]}}),"text"===t&&{backgroundColor:e.palette.background.paper,color:e.palette.text.primary,border:`1px solid ${e.palette.divider}`,"&:hover":{backgroundColor:e.palette.action.hover,transform:"translateY(-2px)",boxShadow:e.shadows[1]}}),"use_text"===t&&{backgroundColor:e.palette.success.main,color:e.palette.common.white,fontWeight:"bold","&:hover":{backgroundColor:e.palette.success.dark,transform:"translateY(-2px)",boxShadow:e.shadows[3]}})),Ae={video_call:d.jsx(ee,{}),image:d.jsx(Z,{}),info:d.jsx(V,{}),summarize:d.jsx(J,{}),edit:d.jsx(H,{}),format:d.jsx(Q,{}),style:d.jsx(K,{}),polish:d.jsx(X,{}),extract:d.jsx(q,{}),paraphrase:d.jsx(G,{}),translate:d.jsx(N,{}),share:d.jsx(B,{}),more:d.jsx(E,{}),use_text:d.jsx(Y,{})},Re=({open:e,onClose:t,transcriptionText:r,onUseText:n,task:o})=>{const{t:s,i18n:i}=ce(["youtubeMp3","transcriptionViewer","common"]),[c,p]=se.useState(""),[m,w]=se.useState([]),[f,j]=se.useState(""),[T,v]=se.useState(!1),[C]=se.useState(`gemini-transcription-${Date.now()}-${Math.random().toString(36).substring(2,10)}`),[k,_]=se.useState(!1),[S,I]=se.useState(!1),[L,D]=se.useState("initializing"),[z,A]=se.useState({}),[R,P]=se.useState(!0),F=se.useRef({}),B=se.useRef(null),N=se.useRef(null),G=se.useRef(null),q=se.useRef(null);se.useEffect(()=>{e&&r&&P(!0)},[e,r]),se.useEffect(()=>{if(R&&r)return;const t=()=>{try{D("connecting");const e=pe();G.current=me(e),window._streamingTranscriptionStatus="connecting",q.current=G.current.subscriptions.create({channel:"GeminiChatChannel",session_token:C},{connected(){window._streamingTranscriptionStatus="connected",window._connectionTime=(new Date).toISOString(),_(!0),D("connected"),window._webSocketDebug={status:"connected",connectionTime:(new Date).toISOString(),channel:"GeminiChatChannel",sessionToken:C,consumer:G.current},r&&w(e=>[...e,{role:"system",content:"Transcription loaded. Preparing to analyze...",id:`transcription-loaded-${Date.now()}`}]),setTimeout(()=>{if(q.current)try{q.current.perform("fetch_history")}catch(e){}},500)},disconnected(){window._streamingTranscriptionStatus="disconnected",_(!1),D("disconnected"),window._webSocketDebug=l(a({},window._webSocketDebug||{}),{status:"disconnected",disconnectTime:(new Date).toISOString()}),T&&(v(!1),f&&(w(e=>[...e,{role:"assistant",content:f+"\n\n[Message incomplete - connection lost]",id:`disconnected-${Date.now()}`}]),j(""))),setTimeout(()=>{q.current&&t()},3e3)},rejected(){window._streamingTranscriptionStatus="rejected",_(!1),D("rejected"),window._webSocketDebug=l(a({},window._webSocketDebug||{}),{status:"rejected",rejectionTime:(new Date).toISOString(),rejectionReason:"Unknown rejection reason"})},received(e){var t,r,n;if(window._lastTranscriptionReceivedData=e,window._transcriptionReceivedDataTime=(new Date).toISOString(),"history"===e.system){if(window._lastHistoryTimestamp&&Date.now()-window._lastHistoryTimestamp<500)return;if(window._lastHistoryTimestamp=Date.now(),e.history&&e.history.length>0){const t=new Set,r=e.history.filter(e=>{if("assistant"===e.role){const r=e.content.replace(/\s+/g," ").trim();if(t.has(r))return!1;t.add(r)}return!0});w(r)}}else if(e.streaming_started)window._streamingStartTime=(new Date).toISOString(),v(!0),j(""),window._lastStreamingMessage="",window._streamingChunks=[],window._streamingChunkSizes=[],window._chunkCounter=0;else if(e.message_chunk){const o=Date.now();window._lastTranscriptionMessageTime=o,window._streamingChunks||(window._streamingChunks=[]),window._streamingChunkSizes||(window._streamingChunkSizes=[]),window._streamingChunks.push({number:e.chunk_number||window._streamingChunks.length+1,size:(null==(t=e.message_chunk)?void 0:t.length)||0,time:(new Date).toISOString(),preview:e.message_chunk?e.message_chunk.substring(0,30)+"...":"empty"}),window._streamingChunkSizes.push((null==(r=e.message_chunk)?void 0:r.length)||0),v(!0),window._streamingError&&(window._streamingError=!1),window._lastStreamingMessage=(window._lastStreamingMessage||"")+e.message_chunk,window._totalChunksSize=(window._totalChunksSize||0)+((null==(n=e.message_chunk)?void 0:n.length)||0),window._chunkCounter=(window._chunkCounter||0)+1,j(t=>{let r=t+e.message_chunk;const n=/<button>(.*?)<\/button>
1/g;return n.test(r)&&(r=r.replace(n,"")),(window._chunkCounter%5==0||e.message_chunk.includes("\n"))&&setTimeout(()=>{try{if(B.current&&B.current.parentElement){const e=B.current.parentElement.closest(".MuiBox-root");if(e){const t=e.clientHeight,r=e.scrollTop+t;e.scrollHeight-r<200&&(e.scrollTop+=40)}}}catch(e){}},10),r})}else if(e.streaming_completed){if(window._processingStreamingCompleted)return;window._processingStreamingCompleted=!0,window._lastCompletedMessageHashes||(window._lastCompletedMessageHashes=new Set),setTimeout(()=>{window._processingStreamingCompleted=!1},2e3);let t=window._lastStreamingMessage||f||"",r=t;const n=[...r.matchAll(/<button>(.*?)<\/button>/gi)];let o=[];if(n.length>0&&(n.forEach((e,t)=>{}),o=n.map((e,t)=>({id:`action_${t}`,label:e[1].trim(),type:"primary",icon:e[1].toLowerCase().includes("summar")?"summarize":e[1].toLowerCase().includes("edit")||e[1].toLowerCase().includes("improve")?"edit":e[1].toLowerCase().includes("translat")?"translate":e[1].toLowerCase().includes("image")||e[1].toLowerCase().includes("visual")?"image":e[1].toLowerCase().includes("video")?"video_call":e[1].toLowerCase().includes("share")?"share":"more"})),r=r.replace(/<button>.*?<\/button>/gi,"").trim(),t=r),t&&t.length>0){const r=e.message_id||`assistant-${Date.now()}`;let n=t;const c=o.length>0?o:[];let d=o.length>0;if(!d){const e=/<button>(.*?)<\/button>/g;let r;for(;null!==(r=e.exec(t));){d=!0;const e=r[1].trim();e&&c.push({id:`action_${c.length}`,label:e,type:"primary",icon:e.toLowerCase().includes("summarize")?"summarize":e.toLowerCase().includes("polish")||e.toLowerCase().includes("refine")?"polish":e.toLowerCase().includes("extract")?"extract":e.toLowerCase().includes("format")||e.toLowerCase().includes("readability")?"format":e.toLowerCase().includes("highlight")?"edit":e.toLowerCase().includes("style")||e.toLowerCase().includes("engage")||e.toLowerCase().includes("boost")?"style":e.toLowerCase().includes("paraphrase")?"paraphrase":"more"})}d&&(n=t.replace(e,""),n=n.replace(/\n+$/g,""))}const u=new RegExp("\\d+\\.\\s+(.*?)(?=\\n\\d+\\.|$)","gs");let p=[...n.matchAll(u)];const h=new RegExp("[•\\-\\*]\\s+(.*?)(?=\\n[•\\-\\*]|$)","gs");let x=[...n.matchAll(h)];const g=/\d+\.\s+\n/g,b=g.test(n),y=/[\[\(]([^\]\)]{3,30})[\]\)]/g;let f=[...n.matchAll(y)];if(p.length>=2&&p.length<=8)d=!0,p.forEach((e,t)=>{var r;const n=null==(r=e[1])?void 0:r.trim();if(n&&n.length>3&&n.length<40){const e=n.toLowerCase().includes("summar")?"summarize":n.toLowerCase().includes("polish")||n.toLowerCase().includes("correct")||n.toLowerCase().includes("grammar")?"polish":n.toLowerCase().includes("extract")||n.toLowerCase().includes("key")||n.toLowerCase().includes("list")?"extract":n.toLowerCase().includes("format")||n.toLowerCase().includes("readab")?"format":n.toLowerCase().includes("style")||n.toLowerCase().includes("engag")?"style":n.toLowerCase().includes("translat")?"translate":"more";c.push({id:`action_${t}`,label:n,type:"primary",icon:e})}}),n=n.replace(/(\d+\..*?\n)/g,""),n=n.replace(/\n{3,}/g,"\n\n");else if(x.length>=2&&x.length<=8)d=!0,x.forEach((e,t)=>{var r;const n=null==(r=e[1])?void 0:r.trim();if(n&&n.length>3&&n.length<40){const e=n.toLowerCase().includes("summar")?"summarize":n.toLowerCase().includes("polish")||n.toLowerCase().includes("correct")||n.toLowerCase().includes("grammar")?"polish":n.toLowerCase().includes("extract")||n.toLowerCase().includes("key")||n.toLowerCase().includes("list")?"extract":n.toLowerCase().includes("format")||n.toLowerCase().includes("readab")?"format":n.toLowerCase().includes("style")||n.toLowerCase().includes("engag")?"style":n.toLowerCase().includes("translat")?"translate":"more";c.push({id:`action_${t}`,label:n,type:"primary",icon:e})}}),n=n.replace(/([•\-\*].*?\n)/g,""),n=n.replace(/\n{3,}/g,"\n\n");else if(f.length>=2&&f.length<=8)d=!0,f.forEach((e,t)=>{var r;const n=null==(r=e[1])?void 0:r.trim();if(n&&n.length>3&&n.length<40){const e=n.toLowerCase().includes("summar")?"summarize":n.toLowerCase().includes("polish")||n.toLowerCase().includes("correct")||n.toLowerCase().includes("grammar")?"polish":n.toLowerCase().includes("extract")||n.toLowerCase().includes("key")||n.toLowerCase().includes("list")?"extract":n.toLowerCase().includes("format")||n.toLowerCase().includes("readab")?"format":n.toLowerCase().includes("style")||n.toLowerCase().includes("engag")?"style":n.toLowerCase().includes("translat")?"translate":"more";c.push({id:`action_${t}`,label:n,type:"primary",icon:e})}});else if(b){d=!0,n=n.replace(g,""),n=n.replace(/\n{3,}/g,"\n\n");const e=i.language||"en";"ru"===e?c.push({id:"action_summarize",label:"Сделать краткое изложение",type:"primary",icon:"summarize"},{id:"action_polish",label:"Исправить текст",type:"primary",icon:"polish"},{id:"action_extract",label:"Выделить ключевые моменты",type:"primary",icon:"extract"},{id:"action_format",label:"Улучшить читаемость",type:"primary",icon:"format"}):"es"===e?c.push({id:"action_summarize",label:"Resumir contenido",type:"primary",icon:"summarize"},{id:"action_polish",label:"Pulir y corregir",type:"primary",icon:"polish"},{id:"action_extract",label:"Extraer puntos clave",type:"primary",icon:"extract"},{id:"action_format",label:"Mejorar legibilidad",type:"primary",icon:"format"}):c.push({id:"action_summarize",label:"Summarize Content",type:"primary",icon:"summarize"},{id:"action_polish",label:"Polish & Correct Text",type:"primary",icon:"polish"},{id:"action_extract",label:"Extract Key Points",type:"primary",icon:"extract"},{id:"action_format",label:"Format for Readability",type:"primary",icon:"format"})}const C=d?c:e.suggested_actions||[];window._lastSuggestedTranscriptionActions=C;const k=[{id:"use_text",label:s("youtubeMp3:useThisText","Use this text"),type:"primary",icon:"use_text"},...C];d&&(t=n,window._lastStreamingMessage=n);const _={role:"assistant",content:n||t,id:r,hasActions:!0};window._lastActionsWithText=k,A(e=>l(a({},e),{[r]:k})),F.current={messageId:r,actions:k},w(e=>{e.filter(e=>
1"assistant"===e.role).forEach(e=>{});const r=t.replace(/\s+/g," ").trim().substring(0,100);if(window._lastCompletedMessageHashes&&window._lastCompletedMessageHashes.has(r))return e;if(e.some(e=>"assistant"===e.role&&e.content&&t&&(e.content.trim()===t.trim()||e.content.replace(/\s+/g," ").trim()===t.replace(/\s+/g," ").trim())))return e;if(window._lastCompletedMessageHashes.add(r),window._lastCompletedMessageHashes.size>10){const e=window._lastCompletedMessageHashes.values();window._lastCompletedMessageHashes.delete(e.next().value)}return[...e,_]}),setTimeout(()=>{const e=z[r]&&z[r].length>0;k.length>0&&(!e||0===Object.keys(z).length)&&A(e=>l(a({},e),{[r]:k})),v(!1),I(!1),X.current||(X.current=!0);m.some(e=>e.id===r);window._messageProcessed=!0,window._actionCount=k.length,window._streamingError=!1,T&&v(!1),S&&I(!1),setTimeout(()=>{try{m.some(e=>e.id===r)?(j(""),window._lastStreamingMessage="",window._streamingChunks=[],window._chunkCounter=0,window._processingStreamingCompleted=!1,S&&I(!1)):window._processingStreamingCompleted=!1}catch(e){window._processingStreamingCompleted=!1}},500)},200)}else v(!1),I(!1),setSuggestedActions([]),setLastMessageWithActions(null),j("")}else if(e.error)if(v(!1),I(!1),window._streamingError=!0,e.recoverable&&e.recovered_text){w(t=>[...t,{role:"assistant",content:e.recovered_text,id:`recovered-${Date.now()}`}]);const t=[{id:"use_text",label:s("youtubeMp3:useThisText","Use this text"),type:"primary",icon:"use_text"},{id:"action_retry",label:"Try again",type:"secondary",icon:"more"}];setTimeout(()=>{setSuggestedActions(t)},100)}else w(t=>[...t,{role:"system",content:`Error: ${e.error}`,id:`error-${Date.now()}`}]),setSuggestedActions([]),setLastMessageWithActions(null);else if(T){const e=window._lastTranscriptionMessageTime||0,t=Date.now();t-e>1e4?(v(!1),I(!1),window._streamingError=!0,f?(w(e=>[...e,{role:"assistant",content:f+"\n\n[Message may be incomplete - streaming stopped unexpectedly]",id:`recovered-hang-${Date.now()}`}]),j(""),setTimeout(()=>{const e=[{id:"use_text",label:s("youtubeMp3:useThisText","Use this text"),type:"primary",icon:"use_text"},{id:"action_summarize",label:s("transcriptionViewer:actionSummarize","Summarize Content"),type:"primary",icon:"summarize"},{id:"action_retry",label:s("common:tryAgain","Try again"),type:"secondary",icon:"more"}];setSuggestedActions(e)},100)):w(e=>[...e,{role:"system",content:`${s("common:error","Error")}: ${s("transcriptionViewer:streamingUnexpectedlyTerminated","Streaming unexpectedly terminated")}`,id:`error-hang-${Date.now()}`}])):window._lastTranscriptionMessageTime=t}}}),window.streamingTranscriptionChatChannel=q.current,window.streamingTranscriptionConsumer=G.current}catch(e){D("error"),w(t=>[...t,{role:"system",content:`Connection error: ${e.message}. Please refresh the page.`,id:`error-${Date.now()}`}])}};return e&&t(),()=>{try{q.current&&q.current.unsubscribe(),G.current&&G.current.disconnect()}catch(e){}}},[e,s,R,r]);const X=se.useRef(!1);se.useEffect(()=>{const e=m.filter(e=>"assistant"===e.role&&e.hasActions);if(e.length>0){const t=e[e.length-1];!(z[t.id]&&z[t.id].length>0)&&F.current.messageId===t.id&&F.current.actions&&F.current.actions.length>0&&A(e=>l(a({},e),{[t.id]:F.current.actions}))}},[m,z]),se.useEffect(()=>{if(k&&r&&r.trim().length>10&&e&&!X.current){const e=setTimeout(()=>{X.current=!0;const e={en:"English",ru:"Russian",es:"Spanish",fr:"French",de:"German",it:"Italian",zh:"Chinese",ja:"Japanese",ko:"Korean",pt:"Portuguese",ar:"Arabic",hi:"Hindi",bn:"Bengali",uk:"Ukrainian",pl:"Polish",tr:"Turkish"}[i.language||"en"]||"English",t=`I have a transcription from audio that I will provide to you.\nPlease analyze this transcription text and tell me what you can do with it.\nIMPORTANT: Respond ENTIRELY in ${e} language.\n\nThis is the beginning of our conversation, and I will maintain context throughout our dialog.\n\nHere is the transcription that needs to be analyzed:\n===TRANSCRIPTION===\n${r}\n===END TRANSCRIPTION===\n\nIMPORTANT: I need you to suggest 3-5 specific actions you could help with based on what you see in the transcription.\nFor example:\n1. Summarize the main points\n2. Correct grammar issues\n3. Make the text more engaging\n4. Extract key information or data\n5. Format the text for readability\n\nFocus your response on understanding and enhancing this specific transcription.\nBe concise but thorough in your initial analysis and suggestions.\n\nYour suggestions MUST be presented as HTML button elements that I can click to perform specific tasks.\nUse EXACTLY this format for each action: <button>Action Name</button>\n\nFor example:\n<button>Summarize Content</button>\n<button>Fix Grammar Issues</button>\n<button>Improve Style</button>\n\nName each action with a clear, concise label (2-4 words) describing what it will do.\nDon't use a numbered list - only use the HTML button tags as shown above.\n\nRemember, ALL your response must be in ${e} language - both your analysis and the button labels.`,n={role:"system",content:"Analyzing transcription...",id:`system-initial-${Date.now()}`},o={role:"user",content:r,id:`transcription-${Date.now()}`};m.length<=1&&w(e=>[...e,n,o]),I(!0),q.current&&q.current.perform("send_message",{content:t,session_token:C,is_initial_prompt:!0})},500);return()=>clearTimeout(e)}e||(X.current=!1)},[k,r,e,m.length]),se.useEffect(()=>{m.length>0&&(()=>{if(B.current&&B.current.parentElement)try{const e=B.current.parentElement.closest(".MuiBox-root");
1if(e){const t=e.clientHeight,r=e.scrollTop+t,n=e.scrollHeight;n-r<200||n<2*t?e.scrollTop=n:e.scrollTop+=100}}catch(e){}})()},[m]),se.useEffect(()=>{var e;T||""!==f||null==(e=B.current)||e.scrollIntoView({behavior:"smooth"})},[T,f]);const K=()=>{if(!c.trim()||S||!k)return;const e=`user-${Date.now()}`,t={role:"user",content:c,id:e};if(window._lastUserTranscriptionMessage={content:c,time:(new Date).toISOString(),id:e},w(e=>[...e,t]),I(!0),setLastMessageWithActions(null),q.current)try{window._lastTranscriptionSendAttempt={messageId:e,time:(new Date).toISOString(),message:c.substring(0,100)+(c.length>100?"...":"")},q.current.perform("send_message",{content:c,transcription_text:r,session_token:C,client_timestamp:Date.now(),message_id:e,is_followup_message:m.length>2}),window._lastTranscriptionSendAttempt.status="sent",p(""),N.current&&N.current.focus()}catch(n){window._lastTranscriptionSendAttempt.status="error",window._lastTranscriptionSendAttempt.error=n.message,w(e=>[...e,{role:"system",content:`Error sending message: ${n.message}`,id:`send-error-${Date.now()}`}]),I(!1)}else window._transcriptionConnectionError={time:(new Date).toISOString(),error:"Channel not available",connectionStatus:L,consumerAvailable:!!G.current},I(!1),w(e=>[...e,{role:"system",content:"Error: Not connected to chat server. Please refresh the page and try again.",id:`connection-error-${Date.now()}`}])},Q=e=>{if("use_text"===e.id&&"function"==typeof n){const e=[...m].reverse().find(e=>"assistant"===e.role);return e&&(n(e.content),w(e=>[...e,{role:"system",content:"Text has been selected.",id:`use-text-${Date.now()}`}]),setTimeout(()=>{t()},1e3)),void setLastMessageWithActions(null)}let o="";switch(e.id){case"create_video":o="Can you help me create a video about this topic?";break;case"generate_image":o="Can you suggest visual ideas or scenes for this video?";break;case"explain_more":o="Please provide more details about this topic.";break;case"summarize":o="Can you give me a shorter version of this?";break;default:if(e.label){const t=e.label.toLowerCase();o="translate"===t||t.includes("translat")?"Translate this to English":t.length<15?`Please ${e.label} the transcription text`:e.label}}o&&(p(o),setTimeout(()=>{if(q.current){const e=`user-${Date.now()}`;w(t=>[...t,{role:"user",content:o,id:e}]),I(!0),q.current.perform("send_message",{content:o,transcription_text:r,session_token:C,client_timestamp:Date.now(),message_id:e,is_followup_message:!0,is_action_button:!0})}},50)),setLastMessageWithActions(null)},J=!r||r.trim().length<=10,Z=!0===e&&!t,ee=d.jsxs(d.Fragment,{children:[(()=>{let e="error.main",t="Disconnected";switch(L){case"connected":e="success.main",t="Connected";break;case"connecting":e="warning.main",t="Connecting...";break;case"disconnected":e="error.main",t="Disconnected - Attempting to reconnect...";break;case"rejected":e="error.main",t="Connection rejected";break;case"error":e="error.main",t="Connection error";break;default:e="info.main",t="Initializing..."}return d.jsxs(u,{variant:"body2",color:e,sx:{display:"flex",alignItems:"center",gap:1,mb:1},children:[d.jsx("span",{style:{display:"inline-block",width:"10px",height:"10px",borderRadius:"50%",backgroundColor:e}}),t]})})(),J&&d.jsx(b,{severity:"warning",sx:{mb:2},action:d.jsx(x,{color:"inherit",size:"small",onClick:t,children:s("common:close","Close")}),children:s("transcriptionViewer:invalidTranscription","The transcription text is empty or too short. Please make sure the audio has been properly transcribed.")}),d.jsxs(_e,{children:[d.jsxs(Se,{children:[m.filter(e=>!("system"===e.role&&(e.content.includes("Connected to chat server")||e.content.includes("Disconnected from chat server")||e.content.includes("Connection rejected")))).filter((e,t,r)=>t===r.findIndex(t=>t.role===e.role&&t.content.trim()===e.content.trim()&&("system"!==t.role||t.id===e.id))).map(e=>{var t,r,n;return d.jsxs(y,{sx:a({display:"flex",justifyContent:"user"===e.role?"flex-end":"flex-start",mb:2},"system"===e.role&&"Analyzing transcription..."===e.content&&{display:"none"}),children:[d.jsx(Ie,{isuser:"user"===e.role?"true":"false",sx:a(a(a({},e.id&&e.id.includes("transcription-")&&{bgcolor:"grey.100",border:"1px dashed",borderColor:"grey.400",width:"calc(100% - 40px)",maxWidth:"100%",my:2,p:2,maxHeight:"250px",overflowY:"auto"}),"system"===e.role&&!(null==(t=e.id)?void 0:t.includes("transcription-"))&&{bgcolor:"info.light",border:"1px solid",borderColor:"info.main",width:"calc(100% - 20px)",maxWidth:"100%",marginX:"auto",textAlign:"center",py:1}),"assistant"===e.role&&{bgcolor:"secondary.light",borderColor:"secondary.main",color:e=>e.palette.getContrastText(e.palette.secondary.light)}),children:e.id&&e.id.includes("transcription-")?d.jsxs(d.Fragment,{children:[d.jsxs(u,{variant:"subtitle2",sx:{mb:1,fontWeight:"bold",color:"text.secondary",borderBottom:"1px solid",borderColor:"divider",pb:.5},children:[s("transcriptionViewer:transcriptionText","Transcription Text"),":"]}),d.jsxs(y,{sx:{maxHeight:"200px",overflowY:"auto",border:"1px solid",borderColor:"divider",borderRadius:1,p:1,backgroundColor:"rgba(0,0,0,0.01)"},children:[d.jsx(u,{variant:"body2",sx:{whiteSpace:"pre-wrap",fontSize:"0.9rem",lineHeight:1.6,color:"text.secondary","& b, & strong":{color:"text.primary",fontWeight:"medium"},"& p":{marginTop:.5,marginBottom:.5}},children:e.content}
1),d.jsx(u,{variant:"caption",sx:{display:"block",textAlign:"right",mt:.5,fontStyle:"italic",color:"text.disabled",fontSize:"0.7rem"},children:s("transcriptionViewer:aiWillAnalyzeText","AI will analyze this text")})]})]}):d.jsx(u,{variant:"body1",sx:a({whiteSpace:"pre-wrap"},"system"===e.role&&{fontStyle:"italic",fontSize:"0.9rem"}),children:e.content})}),"assistant"===e.role&&e.hasActions&&((null==(r=z[e.id])?void 0:r.length)>0?d.jsxs(y,{sx:{display:"flex",flexDirection:"column",width:"100%",mt:1,mb:1,borderRadius:2,backgroundColor:"rgba(2, 136, 209, 0.04)",p:2,border:"1px solid rgba(2, 136, 209, 0.1)"},children:[d.jsx(u,{variant:"caption",sx:{mb:1,color:"text.secondary",fontWeight:500},children:s("transcriptionViewer:quickActions","What would you like to do with this text?")}),d.jsx(Me,{children:z[e.id].map(e=>d.jsx(ze,{actiontype:"use_text"===e.id?"use_text":e.type||"primary",onClick:()=>Q(e),startIcon:Ae[e.icon]||d.jsx(E,{}),sx:{my:.5},children:e.label},e.id))})]}):F.current.messageId===e.id&&(null==(n=F.current.actions)?void 0:n.length)>0?d.jsxs(y,{sx:{display:"flex",flexDirection:"column",width:"100%",mt:1,mb:1,borderRadius:2,backgroundColor:"rgba(2, 136, 209, 0.04)",p:2,border:"1px solid rgba(2, 136, 209, 0.1)"},children:[d.jsx(u,{variant:"caption",sx:{mb:1,color:"text.secondary",fontWeight:500},children:s("transcriptionViewer:quickActions","What would you like to do with this text?")}),d.jsx(Me,{children:F.current.actions.map(e=>d.jsx(ze,{actiontype:"use_text"===e.id?"use_text":e.type||"primary",onClick:()=>Q(e),startIcon:Ae[e.icon]||d.jsx(E,{}),sx:{my:.5},children:e.label},e.id))})]}):null)]},e.id)}),f&&d.jsx(y,{sx:{display:"flex",justifyContent:"flex-start",opacity:T?1:.95},children:d.jsxs(Ie,{isuser:"false",sx:{bgcolor:"secondary.light",color:e=>e.palette.getContrastText(e.palette.secondary.light),borderLeft:"3px solid",borderColor:"secondary.main",width:"calc(100% - 40px)",minWidth:"70%"},children:[d.jsx(u,{variant:"body1",sx:{whiteSpace:"pre-wrap"},children:f}),!T&&d.jsx(u,{variant:"caption",sx:{display:"block",fontStyle:"italic",mt:1,color:"rgba(255,255,255,0.7)"},children:"Adding message to history..."})]})}),T&&!window._streamingError&&d.jsxs(De,{children:[d.jsx(g,{size:16,thickness:6}),f?f.length<100?s("transcriptionViewer:geminiAiIsWriting","AI is writing..."):f.length<500?s("transcriptionViewer:geminiAiIsGenerating","AI is generating content..."):s("transcriptionViewer:geminiAiIsCompleting","AI is completing the response..."):s("transcriptionViewer:geminiAiIsThinking","AI is thinking...")]}),S&&!T&&d.jsx(y,{sx:{display:"flex",justifyContent:"center",my:2},children:d.jsx(g,{size:24})}),d.jsx(y,{ref:B,sx:{height:T&&f&&f.length>300?"40px":"1px",my:T&&f&&f.length>300?1:0,display:"flex",alignItems:"center",justifyContent:"center",opacity:.7,transition:"opacity 0.3s ease","&:hover":{opacity:1}},children:T&&f&&f.length>300&&d.jsxs(u,{variant:"caption",sx:{display:"flex",alignItems:"center",gap:1,fontStyle:"italic",color:"text.secondary",fontSize:"0.75rem"},children:[d.jsx(g,{size:14,thickness:6}),"Scroll to see more..."]})})]}),d.jsxs(Le,{children:[d.jsx(h,{fullWidth:!0,variant:"outlined",placeholder:s("transcriptionViewer:typeInstructionsForEnhancing","Ask about this transcription..."),value:c,onChange:e=>p(e.target.value),onKeyDown:e=>{"Enter"!==e.key||e.shiftKey||(e.preventDefault(),K())},multiline:!0,maxRows:4,disabled:!k||S,inputRef:N}),d.jsx(x,{variant:"contained",onClick:K,disabled:!c.trim()||!k||S,sx:{minWidth:"100px"},endIcon:S?d.jsx(g,{size:16}):d.jsx($,{}),children:s("common:send","Send")})]})]})]});return Z?d.jsx(U,{elevation:1,sx:{p:2,borderRadius:2,height:"500px",display:"flex",flexDirection:"column"},children:ee}):d.jsxs(W,{anchor:"right",open:e,onClose:t,hideBackdrop:!1,SlideProps:{direction:"left"},sx:{zIndex:1300,"& .MuiDrawer-paper":{width:{xs:"100%",sm:"80%",md:"60%",lg:"50%"},maxWidth:"800px",display:"flex",flexDirection:"column",height:"100%",bgcolor:"grey.50",position:"fixed",right:0,left:"auto",boxShadow:"-4px 0 20px rgba(0,0,0,0.1)"}},children:[R&&d.jsxs(y,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",p:2,borderBottom:"1px solid",borderColor:"divider",bgcolor:"primary.main",color:"white"},children:[d.jsxs(y,{sx:{display:"flex",alignItems:"center"},children:[d.jsx(V,{sx:{mr:1}}),d.jsx(u,{variant:"h6",children:s("transcriptionViewer:transcriptionTitle","Transcription")})]}),d.jsx(M,{color:"inherit",onClick:t,edge:"end","aria-label":"close",children:d.jsx(O,{})})]}),d.jsxs(y,{sx:{p:R?2:0,flexGrow:1,overflow:"auto",display:"flex",flexDirection:"column",height:R?"calc(100% - 64px)":"100%"},children:[R&&r?d.jsxs(y,{sx:{height:"100%",display:"flex",flexDirection:"column"},children:[d.jsx(U,{elevation:0,sx:{p:3,mb:2,flexGrow:1,overflow:"auto",bgcolor:"background.paper",border:"1px solid",borderColor:"divider",borderRadius:2},children:d.jsx(u,{variant:"body1",sx:{whiteSpace:"pre-wrap",lineHeight:1.6},children:r})}),d.jsxs(y,{sx:{display:"flex",gap:2,justifyContent:"center",mt:"auto"},children:[d.jsx(x,{variant:"contained",color:"primary",startIcon:d.jsx(H,{}),onClick:()=>{P(!1),D("initializing")},sx:{borderRadius:"8px",textTransform:"none",fontWeight:600,px:3},children:s("transcriptionViewer:editWithAi","Edit with AI")}),"function"==typeof n&&d.jsx(x,{variant:"contained",color:"success",startIcon:d.jsx(Y,{}),onClick:()=>{n(r),t()},sx:{borderRadius:"8px",textTransform:"none",fontWeight:600,px:3},children:s("transcriptionViewer:useThisText","Use this text")})]})]}):d.jsx(y,{sx:{height:"100%",overflow:"hidden",bgcolor:"white",display:"flex",flexDirection:"column",p:2},children:d.jsx(y,{sx:{flexGrow:1,overflow:"hidden",display:"flex",flexDirection:"column",bgcolor:"background.paper",border:"1px solid",borderColor:"divider",borderRadius:2,position:"relative"},children:d.jsx(de,{task:o,initialUserMessage:r?`Here is the transcription I want to work with:\n\n${r}\n\nPlease help me improve or modify this transcription.`:"",onSelectForLongVideo:e=>{if(ue.info("StreamingTranscriptionViewer onSelectForLongVideo called","StreamingTranscriptionViewer",{textOrTaskType:typeof e,isObject:"object"==typeof e,objectKeys:"object"==typeof e?Object.keys(e||{}):null,hasTranscriptionText:"object"==typeof e&&void 0!==(null==e?void 0:e.transcriptionText)}),"function"==typeof n){let r;r="object"==typeof e&&(null==e?void 0:e.transcriptionText)?e.transcriptionText:"string"==typeof e?e:String(e||""),ue.info("StreamingTranscriptionViewer calling onUseText","StreamingTranscriptionViewer",{finalTextType:typeof r,finalTextPreview:r.substring(0,100)+"...",finalTextLength:r.length}),n(r),t()}},onClose:()=>P(!0),headerTitle:"Edit Transcription with AI",inLongVideoFlow:!0})})}),!1]})]})},Pe=({inLongVideoFlow:e=!1,onAudioSelected:t})=>{var r;const{t:n,i18n:o}=ce(["youtubeMp3"]),s=ie(),i=ae(),{data:h,loading:x,error:w,refetch:f}=he(we,{variables:{limit:20,status:"completed"},fetchPolicy:"network-only",pollInterval:5e3});se.useEffect(()=>{o.hasResourceBundle(o.language,"youtubeMp3")||o.loadNamespaces("youtubeMp3")},[o]),se.useEffect(()=>{if(e){const e=new URLSearchParams(i.search),t=e.get("view"),r=e.get("taskId");"transcription"===t&&r&&(E(r),R(!0),!(null==h?void 0:h.youtubeMp3Tasks)&&f&&f())}},[e,i.search,h,f]);const[j,v]=se.useState(null),[C,_]=se.useState(null),[S,I]=se.useState(null),[L,D]=se.useState(null),[M,z]=se.useState(null),[A,R]=se.useState(!1),[P,E]=se.useState(null),{data:$,error:W,stopPolling:V}=he(be,{variables:{id:j},skip:!j,pollInterval:3e3,fetchPolicy:"network-only",onCompleted:e=>{(null==e?void 0:e.youtubeMp3Task)&&("completed"===e.youtubeMp3Task.status?(_({status:"ok",youtubeTitle:e.youtubeMp3Task.youtubeTitle,youtubeDuration:e.
1youtubeMp3Task.duration,localUrl:e.youtubeMp3Task.localUrl,s3Url:e.youtubeMp3Task.s3Url,msg:"Download completed successfully!"}),V(),f()):"failed"===e.youtubeMp3Task.status&&(_({status:"error",msg:e.youtubeMp3Task.errorMessage||"Download failed"}),V()))}}),{data:O,error:H,stopPolling:Y}=he(ye,{variables:{id:L},skip:!L,pollInterval:3e3,fetchPolicy:"network-only",onCompleted:e=>{(null==e?void 0:e.audioTranscriptionTask)&&("completed"===e.audioTranscriptionTask.status&&e.audioTranscriptionTask.text?(Y(),D(null),z(null),f(),setTimeout(()=>{f()},1e3)):"failed"===e.audioTranscriptionTask.status&&(alert("Transcription failed: "+(e.audioTranscriptionTask.errorMessage||"Unknown error")),Y(),D(null),z(null)))}}),[F,{error:B}]=le(fe,{onCompleted:e=>{"queued"!==e.audioToText.status&&"pending"!==e.audioToText.status&&"processing"!==e.audioToText.status||!e.audioToText.taskId?alert("Error starting transcription: "+(e.audioToText.error||"Unknown error")):D(e.audioToText.taskId)},onError:e=>{z(null),alert("Failed to start transcription: "+e.message)}}),N=e=>c(null,null,function*(){const t=yield(e=>c(null,null,function*(){try{const{data:t}=yield xe.query({query:je,variables:{sourceId:e},fetchPolicy:"no-cache"});return!!((null==t?void 0:t.audioTranscriptionTasks)&&t.audioTranscriptionTasks.length>0&&t.audioTranscriptionTasks[0].text)&&(f(),!0)}catch(t){return!1}}))(e);t?alert("Transcription already exists! Click the 'View Text' button."):(z(e),F({variables:{input:{youtubeMP3TaskId:e}}}))}),G=null==(r=null==h?void 0:h.youtubeMp3Tasks)?void 0:r.find(e=>e.id===P),q=null==$?void 0:$.youtubeMp3Task,X=null==O?void 0:O.audioTranscriptionTask,K=(null==h?void 0:h.youtubeMp3Tasks)||[],Q=W||w||B||H,J=e=>{I(e)},Z=()=>{I(null)},ee=t=>{E(t),(t=>{if(e){const e=new URLSearchParams(i.search);e.set("view","transcription"),e.set("taskId",t),s(`${i.pathname}?${e.toString()}`,{replace:!0})}})(t),R(!0)},de=r=>{e&&t&&"function"==typeof t&&t({id:r.id,youtubeId:r.youtubeId,youtubeTitle:r.youtubeTitle,s3Url:r.s3Url,duration:r.duration,transcriptionText:r.transcriptionText})};return d.jsx(y,{sx:{minHeight:e?"auto":"100vh",backgroundColor:e=>"dark"===e.palette.mode?"background.default":"grey.50",pt:e?0:4,pb:8,px:e?0:2},children:d.jsxs(te,{maxWidth:e?"xl":"lg",disableGutters:e,children:[!e&&d.jsxs(y,{sx:{mb:4},children:[d.jsxs(u,{variant:"h4",component:"h1",sx:{display:"flex",alignItems:"center",color:"primary.main",fontWeight:600},children:[d.jsx(p,{color:"error",sx:{mr:2}}),"YouTube MP3 Downloader",d.jsx(k,{color:"primary",sx:{ml:2}})]}),d.jsx(u,{variant:"body1",color:"text.secondary",sx:{mt:1},children:"Download audio from YouTube videos, transcribe and enhance with AI"})]}),d.jsxs(m,{container:!0,spacing:e?2:3,children:[d.jsx(m,{item:!0,xs:12,md:5,lg:4,children:d.jsxs(U,{elevation:0,sx:{p:e?2:3,borderRadius:2,border:"1px solid",borderColor:"divider",height:"100%"},children:[d.jsx(Ce,{onTaskCreated:e=>{v(e)},onTaskCompleted:f}),Q&&d.jsxs(b,{severity:"error",sx:{mt:3},children:["Error: ",Q.message]}),!Q&&L&&(!X||"processing"===X.status||"queued"===X.status||"pending"===X.status)&&d.jsx(b,{severity:"info",sx:{mt:3},children:n("transcriptionTaskStartedMessage")||"Transcription task started. Please wait while we process your audio..."}),(C||q)&&"ok"!==(null==C?void 0:C.status)&&d.jsxs(y,{mt:4,children:[C&&d.jsx(b,{severity:"ok"===C.status||"queued"===C.status?"success":"error",sx:{mb:3},children:C.msg}),q&&q.inProgress&&d.jsxs(y,{sx:{my:3,textAlign:"center"},children:[d.jsx(g,{size:40}),d.jsxs(u,{variant:"subtitle1",color:"primary",mt:2,children:["downloading"===q.status?"Downloading audio from YouTube...":"","uploading"===q.status?"Uploading audio to cloud storage...":""]})]}),q&&"failed"===q.status&&d.jsxs(y,{sx:{my:2,p:2,bgcolor:"error.light",color:"error.contrastText",borderRadius:1},children:[d.jsx(u,{variant:"subtitle1",fontWeight:"bold",children:"Error Details:"}),d.jsx(u,{variant:"body2",children:q.errorMessage||"Unknown error occurred during processing"})]})]}),S&&d.jsxs(y,{mt:3,p:2,sx:{bgcolor:e=>"dark"===e.palette.mode?re(e.palette.primary.main,.1):"primary.light",borderRadius:2,border:"1px solid",borderColor:"primary.main"},children:[d.jsx(u,{variant:"subtitle1",color:"primary.contrastText",gutterBottom:!0,children:n("nowPlaying")}),d.jsx("audio",{src:S,controls:!0,autoPlay:!0,style:{width:"100%"},onEnded:Z})]})]})}),d.jsx(m,{item:!0,xs:12,md:7,lg:8,children:d.jsx(U,{elevation:0,sx:{p:e?2:3,borderRadius:2,border:"1px solid",borderColor:"divider"},children:d.jsxs(y,{children:[d.jsxs(u,{variant:"h6",gutterBottom:!0,sx:{display:"flex",alignItems:"center",fontWeight:600,color:"primary.dark"},children:[d.jsx(ne,{sx:{mr:1.5,color:"primary.main"}}),"Audio Library"]}),d.jsx(T,{sx:{mb:3}}),x?d.jsx(y,{sx:{textAlign:"center",py:4},children:d.jsx(g,{size:40})}):K.length>0?d.jsx(oe,{children:K.map(t=>d.jsx(ke,{task:t,isPlaying:S===t.s3Url,onPlay:J,onStop:Z,onCopy:ve,onTranscribe:N,onViewTranscription:ee,isTranscribing:M===t.id&&!t.hasTranscription,inLongVideoFlow:e,onSelectForLongVideo:de},t.id))}):d.jsxs(y,{sx:{textAlign:"center",py:6,px:2,borderRadius:2,border:"1px dashed",borderColor:"divider",bgcolor:e=>"dark"===e.palette.mode?"action.hover":"grey.50"},children:[d.jsx(k,{sx:{fontSize:48,color:"text.secondary",mb:2}}),d.jsx(u,{variant:"h6",color:"text.secondary",gutterBottom:!0,children:"No MP3 Files Yet"}),d.jsx(u,{variant:"body2",color:"text.secondary",children:"Use the form to download your first MP3 from YouTube"})]})]})})})]}),d.jsx(Re,{open:A,onClose:()=>{R(!1),E(null),(()=>{if(e){const e=new URLSearchParams(i.search);e.delete("view"),e.delete("taskId"),s(`${i.pathname}?${e.toString()}`,{replace:!0})}})()},task:G,transcriptionText:(null==G?void 0:G.transcriptionText)||"",onUseText:t=>{if(e){const e="string"==typeof t?t:String(t||""),r=l(a({},G),{transcriptionText:e});de(r)}}},P)]})})};export{Pe as default};

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.