12 |
- (()=>{var __webpack_exports__={};parseCodecs=e=>{e=e.mimeType;if(!e)return{};e=e.match(/(?<mimetype>[^/]+\/[^;]+)(?:;\s*codecs="?(?<codecs>[^"]+))?/);if(!e)return{};e=e.groups.codecs;if(!e)return{};e=e.trim().replace(/,$/,"").split(",").map(e=>e.trim()).filter(Boolean);let t=null,n=null;for(const i of e){var a=i.split(".")[0];["avc1","avc2","avc3","avc4","vp9","vp8","hev1","hev2","h263","h264","mp4v","hvc1","av01","theora"].includes(a)?t=t||i:["mp4a","opus","vorbis","mp3","aac","ac-3","ec-3","eac3","dtsc","dtse","dtsh","dtsl"].includes(a)&&(n=n||i)}return t||n?{vcodec:t,acodec:n}:2===e.length?{vcodec:e[0],acodec:e[1]}:{}},parseSetCookie=e=>{if(!e)return"";var t=e["Set-Cookie"];if(!t)return"";let n="PREF=hl=en&tz=UTC; SOCS=CAI; GPS=1; ";var a=["YSC","VISITOR_INFO1_LIVE","VISITOR_PRIVACY_METADATA"];for(const o in a){var i=a[o],r=new RegExp(i+"=([^;,]+)"),r=t.match(r);r&&2===r.length&&(r=r[1],o!=a.length-1?n+=i+`=${r}; `:n+=i+"="+r)}return n},request=async(e,t,n=null,r={},a)=>{var i;return"WEB"===a&&(t=t.replace("https://www.youtube.com","http://127.0.0.1")),"WEB"===a?(i=await(a=await fetch(t,{mode:"cors",method:e,headers:r,body:n})).text(),Promise.resolve({data:i,headers:a.headers})):new Promise((a,i)=>{AF.request(t,e,n,r,(e,t,n)=>{n?i(n):a({data:e,headers:JSON.parse(t)})})})},getStringBetween=(e,t,n,a=0,i=0)=>{var r=e.indexOf(t),n=n?e.indexOf(n,r):e.length;return e.substring(r+t.length+i,n+a)},findFunction=(jsCode,regexp)=>{const match=jsCode.match(regexp);if(!match&&match.length<=1)return null;let result="";const dependencyMatches=match[0].match(/([$a-zA-Z0-9]+\.[$a-zA-Z0-9]+)/g),existDependencies=[];if(dependencyMatches&&1<=dependencyMatches.length)for(var currentMatch of dependencyMatches){const varName=currentMatch.split(".")[0];if(!existDependencies.includes(varName)){const varNameMatch=jsCode.match(new RegExp(`var \\${varName}={(.|\\n)*?};`),"ig");varNameMatch&&1<=varNameMatch.length&&(result+=varNameMatch[0]+"\n"),existDependencies.push(varName)}}return result+=`
- `+match[0],eval(result)};const cache={};fetchBaseJSContent=async(e,t)=>{var n,a="jsContent:"+e;return cache[a]||({data:e,_:n}=await request("GET",e,null,{"User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.101 Safari/537.36"},t),cache[a]=e)},extractJSSignatureFunction=async(e,t)=>{e=await fetchBaseJSContent(e,t);return findFunction(e,/([a-zA-Z0-9]+)=function\([a-zA-Z0-9]+\)\{a=a\.split\(""\).*};/)},extractNJSFunction=async(e,t)=>{e=await fetchBaseJSContent(e,t);return findFunction(e,/([a-zA-Z0-9]+)=function\([a-zA-Z0-9]+\)\{var b=a\.split\(""\)[\s\S]*?};/)},signUrl=async(e,t,n)=>{var a={};for(const u of e.split("&")){var[i,r]=u.split("=");a[decodeURIComponent(i)]=decodeURIComponent(r)}var[e,o,s]=[a.url,a.s,a.sp],c=await extractJSSignatureFunction(t,n);if(!c)return null;s=e+`&${s}=`+c(o);for(const h of e.split("&")){var[l,d]=h.split("=");a[decodeURIComponent(l)]=decodeURIComponent(d)}c=await extractNJSFunction(t,n),o=a.n;return o&&c?function replaceUrlParam(e,t,n){var a=new RegExp(`([?&])${t}=.*?(&|$)`,"i");let i=e.replace(a,`$1${t}=${n}$2`);return i===e&&-1===e.indexOf("?")?i+=`?${t}=`+n:i===e&&(i+=`&${t}=`+n),i}(s,"n",c(o)):s},detail=async(t,n)=>{try{var a=(await request("GET",t+"&bpctr=9999999999&has_verified=1",null,{"User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.107 Safari/537.36",Accept:"text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8","Accept-Language":"en-us,en;q=0.5","Sec-Fetch-Mode":"navigate","Accept-Encoding":"gzip, deflate, br",Cookie:"PREF=hl=en&tz=UTC; SOCS=CAI"},n))["data"],i=/var ytInitialPlayerResponse\s*=\s*({.*?});/,r=a.match(i);if(!r||!r.length)throw new Error("JSON not found: ytInitialPlayerResponse");var o=JSON.parse(r[1]),s=o.videoDetails,c=[];for(const C of s.thumbnail.thumbnails)c.push({url:C.url,width:C.width+"",height:C.height+""});let e=[];var l=[];for(const y of o.streamingData.formats.concat(o.streamingData.adaptiveFormats))y&&(y.from="web",l.push(y));e=e.concat(l);var d,u,h,p="https://www.youtube.com"+JSON.parse(a.match(/set\(({.+?})\);/)[1]).PLAYER_JS_URL,m=[],v=[];for(d of e)d&&-1===m.indexOf(d.itag)&&(d.url||(d.url=await signUrl(d.signatureCipher,p,n)),d.url)&&({vcodec:u,acodec:h}=parseCodecs(d),u)&&h&&(v.push({width:d.width+"",height:d.height+"",type:d.mimeType,quality:d.quality,itag:d.itag,fps:d.fps+"",bitrate:d.bitrate+"",url:d.url,ext:"mp4",vcodec:u,acodec:h,vbr:"0",abr:"0",container:"mp4_dash",from:d.from}),m.push(d.itag));var x=a.match(/var ytInitialData\s*=\s*({.*?});/),g=[];if(x&&2===x.length){var f,w=JSON.parse(x[1]);for(const S of w.contents?.twoColumnWatchNextResults?.secondaryResults?.secondaryResults?.results||[])S.compactVideoRenderer&&(f=S.compactVideoRenderer).videoId&&g.push({type:"gridVideoRenderer",videoId:f.videoId,title:f.title?.simpleText,thumbnails:f.thumbnail?.thumbnails,channelName:f.longBylineText?.runs?.[0]?.text,publishedTimeText:f.publishedTimeText?.simpleText,viewCountText:f.viewCountText?.simpleText,shortViewCountText:f.shortViewCountText?.simpleText,lengthText:f.lengthText?.simpleText})}var T={code:200,msg:"",data:{videoDetails:{isLiveContent:s.isLiveContent,title:s.title,thumbnails:c,description:s.shortDescription,lengthSeconds:s.lengthSeconds,viewCount:s.viewCount,keywords:s.keywords,author:s.author,channelID:s.channelId,recommendInfo:g,channelURL:"https://www.youtube.com/channel/"+s.channelId,videoId:s.videoId},streamingData:{formats:v.reverse()}},id:"MusicDetailViewModel_detail_url"};return T}catch(e){t={code:-1,msg:e.toString()};return t}},search=async(e,t,n)=>{try{if(t){var a=JSON.parse(t),i=a.key,r={context:{client:{clientName:"WEB",clientVersion:"2.20240506.01.00"}},continuation:a.continuation},o=(await request("POST","https://www.youtube.com/youtubei/v1/search?key="+i,JSON.stringify(r),{},n))["data"],s=JSON.parse(o),c=[];for(const T of s.onResponseReceivedCommands[0].appendContinuationItemsAction.continuationItems[0].itemSectionRenderer.contents){var l=T.videoRenderer;l&&l.videoId&&c.push({type:"videoWithContextRenderer",data:{videoId:l.videoId,title:l.title?.runs?.[0]?.text,thumbnails:l.thumbnail?.thumbnails,channelName:l.longBylineText?.runs?.[0]?.text,publishedTimeText:l.publishedTimeText?.simpleText,viewCountText:l.viewCountText?.simpleText,shortViewCountText:l.shortViewCountText?.simpleText,lengthText:l.lengthText?.simpleText}})}var d={code:200,msg:"",data:{data:c,next:JSON.stringify({key:a.key,continuation:s.onResponseReceivedCommands?.[0]?.appendContinuationItemsAction?.continuationItems?.[1]?.continuationItemRenderer?.continuationEndpoint?.continuationCommand?.token})},id:"MusicSearchResultViewModel_search_result"};return d}var u=`https://www.youtube.com/results?q=${encodeURIComponent(e)}&sp=EgIQAQ%253D%253D`,h=(await request("GET",u,null,{},n))["data"],p=/var ytInitialData\s*=\s*({.*?});/,m=h.match(p);if(!m||!m.length)throw new Error("JSON not found: ytInitialData");var v,x=JSON.parse(m[1]),g=[];for(const C of x.contents?.twoColumnSearchResultsRenderer?.primaryContents?.sectionListRenderer?.contents?.[0]?.itemSectionRenderer?.contents)C.videoRenderer&&(v=C.videoRenderer)&&v.videoId&&g.push({type:"videoWithContextRenderer",data:{videoId:v.videoId,title:v.title?.runs?.[0]?.text,thumbnails:v.thumbnail?.thumbnails,channelName:v.longBylineText?.runs?.[0]?.text,publishedTimeText:v.publishedTimeText?.simpleText,viewCountText:v.viewCountText?.simpleText,shortViewCountText:v.shortViewCountText?.simpleText,lengthText:v.lengthText?.simpleText}});var f={},w=(0<h.split("innertubeApiKey").length&&(f.key=h.split("innertubeApiKey")[1].trim().split(",")[0].split('"')[2]),f.continuation=x.contents?.twoColumnSearchResultsRenderer?.primaryContents?.sectionListRenderer?.contents?.[1]?.continuationItemRenderer?.continuationEndpoint?.continuationCommand?.token,{code:200,msg:"",data:{data:g,next:JSON.stringify(f)},id:"MusicSearchResultViewModel_search_result"});return w}catch(e){t={code:-1,msg:e.toString()};return t}}})();
|