UNPKG

crunchyroll-js-api

Version:
1 lines 36.3 kB
var e={d:(t,a)=>{for(var o in a)e.o(a,o)&&!e.o(t,o)&&Object.defineProperty(t,o,{enumerable:!0,get:a[o]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},t={};e.d(t,{II:()=>n,Or:()=>a,FH:()=>x,$W:()=>l,Ay:()=>E,xM:()=>T,vF:()=>d,Wp:()=>f});var a={};e.r(a),e.d(a,{default:()=>O});class o extends Error{constructor(e,t=null,a=null,n=null,c=null){super(e),this.code=t,this.context=a,this.httpStatus=n,this.httpStatusText=c,Object.setPrototypeOf(this,o.prototype)}}const n=o;let c="info",r=!0;process&&process.env&&process.env.LOG_LEVEL&&(c=process.env.LOG_LEVEL);const s={info:()=>{},error:()=>{},debug:()=>{},setLevel:()=>{},activeColor:e=>{r=e}};console.debug||(console.debug=console.log),console.info||(console.info=console.log),console.error||(console.error=console.log);const i={debug:"",info:"",error:"",reset:""},u=(e,t)=>{"string"==typeof e||e instanceof String||(e=(e=>{let t="";const a=Object.keys(e);if(a.length)if(2===a.length&&a.includes("message")&&a.includes("stack")){const a=e;t=`\n message:${a.name}\n stack:${a.stack}`}else t="\n"+JSON.stringify(e,null," ");else e instanceof Error?t=`\n message:${e.name}\n stack:${e.stack}`:e instanceof Set&&(t="["+Array.from(e).toString()+"]");return t})(e));const a=(new Error).stack.split("\n")[3];let o=i[t],n=i.reset;r||(o=n="");return`${(new Date).toISOString()} ${o}${t.toUpperCase()} ${e} ${(a||"").trim()} ${n}`};s.setLevel=function(e){switch(e||(e=c),s.debug=()=>{},s.info=()=>{},s.error=()=>{},e){case"silent":break;case"debug":s.debug=e=>{console.debug(u(e,"debug"))};case"info":s.info=e=>{console.info(u(e,"info"))};case"error":s.error=e=>{console.error(u(e,"error"))}}return s},s.setLevel();const d=s,l={production:"cr-production",vilo:"https://static.crunchyroll.com/vilos",clientId:"xunihvedbt3mbisuhevt",clientSecret:"1kIS5dyTvjE0_rqaA3YeAh0bUXUmxW11",clientIdSso:"ltccxd10yl6cqcn1acx1",url:"https://www.crunchyroll.com",urlBeta:"https://beta-api.crunchyroll.com",urlSso:"https://sso.crunchyroll.com",urlStatic:"https://static.crunchyroll.com",urlDrm:"https://cr-play-service.prd.crunchyrollsvc.com",urlPl:"https://pl.crunchyroll.com",urlLicense:"https://cr-license-proxy.prd.crunchyrollsvc.com",accountingId:"crunchyroll",castId:"4D84B31C",urlEec:"https://eec.crunchyroll.com",appConfig:"app-config-default-production.json",versionName:"3.70.4",appId:"cr-android",osReleaseVersion:"13",contentTypes:["series","movie_listing","episode"],sortByValues:["popularity","newly_added","alphabetical"],ratingContentTypes:["1s","2s","3s","4s","5s"],ratingEpisodeTypes:["up","down"]};let g=null;function h(){return`Crunchyroll/${l.versionName} Android/${l.osReleaseVersion}`}async function m(e,t){if(!(200<=t.status&&t.status<300)){d.error(`Status Code: ${t.status} - ${e}`);let a=null;try{a=await t.json(),d.error(a)}catch(e){}throw a?new n(a.error,a.code,a.context,t.status,t.statusText):(d.error(t.statusText),new Error(t.statusText))}d.debug(`Status Code: ${t.status} - ${e}`)}async function p(e,t){let a=null;if(t.baseUrlIncluded?(e=decodeURIComponent(`${e}`),delete t.baseUrlIncluded):e=decodeURIComponent(`${l.urlBeta}${e}`),d.debug(`${t.method} - ${e}`),t.headers||(t.headers={}),t.headers["User-Agent"]=h(),g)a=g;else try{a=window.fetch}catch(e){}return a(e,t)}const f={camelCase:e=>e.replace(/_([a-z])/g,((e,t)=>t.toUpperCase())),logRes:m,makeRawRequest:p,makeRequest:async function(e,t,a){const o=await p(t,a);await m(e,o);let n=null;try{n=await o.json()}catch(e){}return n},addParam:function(e,t,a,o){if(void 0!==a){if(o&&!o(a))throw new Error(`Value ${a} for key ${t} is not valid.`);e[t]=encodeURIComponent(a)}},toCamel:function(e){return e.replace(/([-_][a-z])/gi,(e=>e.toUpperCase().replace("_","")))},toSnake:function(e){return e.replace(/[A-Z]/g,(e=>`_${e.toLowerCase()}`))},toURLSearchParams:async function(e){let t=null;try{t=window.URLSearchParams}catch(e){}return new t(e)},setFetchFunction:function(e){g=e},getUserAgent:h};function y(){const e=`${l.clientId}:${l.clientSecret}`;return Buffer.from(e).toString("base64")}async function k({device:e,credentials:t,grantType:a,scope:o}){const n="_makeLogin";d.debug(n);const c=y(),r={grant_type:a,scope:o||"offline_access",device_id:e.id,device_name:e.name,device_type:e.type,...t},s={method:"post",body:await f.toURLSearchParams(r),headers:{Authorization:`Basic ${c}`,"Content-Type":"application/x-www-form-urlencoded","ETP-Anonymous-ID":null}},i=await f.makeRequest(n,"/auth/v1/token",s);return i&&(i.created_date=(new Date).toISOString()),i}const v={getDeviceCode:async function(){const e="getDeviceCode";d.debug(e);const t=y(),a={method:"post",body:await f.toURLSearchParams({grant_type:"client_id"}),headers:{Authorization:`Basic ${t}`,"Content-Type":"application/x-www-form-urlencoded","etp-anonymous-id":null}},o=await f.makeRequest(e,"/auth/v1/device/code",a);return o&&(o.created_date=(new Date).toISOString()),o},getDeviceAuth:async function({device:e,deviceCode:t}){const a="getDeviceAuth";d.debug(a);const o=y(),n={device_id:e.id,device_name:e.name,device_type:e.type,device_code:t},c={method:"post",body:JSON.stringify(n),headers:{Authorization:`Basic ${o}`,"Content-Type":"application/json"}};return f.makeRequest(a,"/auth/v1/device/token",c)},getToken:async function({device:e,scope:t,username:a,password:o}){return d.debug("getToken"),k({device:e,scope:t,grantType:"password",credentials:{username:a,password:o}})},getTokenWithPhone:async function({device:e,scope:t,phone:a,verification_code:o}){return d.debug("getTokenWithPhone"),k({device:e,scope:t,grantType:"phone",credentials:{phone_number:a,verification_code:o}})},getTokenWithCode:async function({device:e,scope:t,code:a,code_verifier:o}){return d.debug("getTokenWithCode"),k({device:e,scope:t,grantType:"authorization_code",credentials:{code:a,code_verifier:o}})},getRefreshToken:async function({device:e,scope:t,refreshToken:a}){return d.debug("getRefreshToken"),k({device:e,scope:t,grantType:"refresh_token",credentials:{refresh_token:a}})},revokeRefreshToken:async function({refreshToken:e}){const t="revokeRefreshToken";d.debug(t);const a=y(),o={token:e},n={method:"post",body:await f.toURLSearchParams(o),headers:{Authorization:`Basic ${a}`,"Content-Type":"application/x-www-form-urlencoded","ETP-Anonymous-ID":null}};return f.makeRequest(t,"/auth/v1/revoke",n)},switchProfile:async function({device:e,scope:t,refreshToken:a,profileId:o}){return d.debug("switchProfile"),k({device:e,scope:t,grantType:"refresh_token_profile_id",credentials:{refresh_token:a,profile_id:o}})}};const w={getIndexConfig:async function({token:e}){const t="getIndexConfig";d.debug(t);const a={method:"get",headers:{Authorization:e}};return f.makeRequest(t,"/index/v2",a)}};const $={createMultiProfile:async function({token:e,data:t}){const a="createMultiProfile";d.debug(a);const o={method:"post",headers:{Authorization:e,"Content-Type":"application/json"},body:JSON.stringify(t)};await f.makeRequest(a,"/accounts/v1/me/multiprofile",o)},deleteMultiProfile:async function({token:e,profileId:t}){const a="deleteMultiProfile";d.debug(a);const o=`/accounts/v1/me/multiprofile/${t}`,n={method:"delete",headers:{Authorization:e,"Content-Type":"application/json"}};await f.makeRequest(a,o,n)},getAccountId:async function({token:e}){const t="getAccountId";d.debug(t);const a={method:"get",headers:{Authorization:e}};return f.makeRequest(t,"/accounts/v1/me",a)},getProfile:async function({token:e}){const t="getProfile";d.debug(t);const a={method:"get",headers:{Authorization:e}};return f.makeRequest(t,"/accounts/v1/me/profile",a)},getMultiProfile:async function({token:e,profileId:t}){const a="getMultiProfiles";d.debug(a);const o=`/accounts/v1/me/multiprofile/${t}`,n={method:"get",headers:{Authorization:e}};return f.makeRequest(a,o,n)},getMultiProfiles:async function({token:e}){const t="getMultiProfiles";d.debug(t);const a={method:"get",headers:{Authorization:e}};return f.makeRequest(t,"/accounts/v1/me/multiprofile",a)},getUsernames:async function({token:e}){const t="getAccountId";d.debug(t);const a={method:"get",headers:{Authorization:e}};return f.makeRequest(t,"/accounts/v1/usernames",a)},updateProfile:async function({token:e,data:t}){const a="updateProfile";d.debug(a);const o={method:"patch",headers:{Authorization:e,"Content-Type":"application/json"},body:JSON.stringify(t)};await f.makeRequest(a,"/accounts/v1/me/profile",o)},updateMultiProfile:async function({token:e,data:t,profileId:a}){const o="updateMultiProfile";d.debug(o);const n=`/accounts/v1/me/multiprofile/${a}`,c={method:"patch",headers:{Authorization:e,"Content-Type":"application/json"},body:JSON.stringify(t)};await f.makeRequest(o,n,c)}},_={credential:null,device:null,token:null,cms:null,account:null};let b=null,R=null;function L(e){return q(e,f.toCamel)}async function P(e){e?(_.token=L(e),_.token.token=`${_.token.tokenType} ${_.token.accessToken}`):_.token=null,await A()}async function I(){let e=null;if(_.token&&_.token.accessToken){((new Date).getTime()-new Date(_.token.createdDate).getTime())/1e3<_.token.expiresIn-5&&(e=_.token)}if(!e){let t=null;_.token&&_.token.refreshToken?t=await v.getRefreshToken({..._.token,device:_.device}):_.credential&&(t=await v.getToken({..._.credential,device:_.device})),await P(t),e=_.token}if(!e)throw new n("No auth token found.");return e.token}async function S(){return await I(),_.token}async function A(){const e=await U(),t=JSON.stringify(q(_,f.toSnake),null,"\t");try{b?await b(t):window.localStorage.setItem(e,btoa(t))}catch(e){}}function q(e,t){let a;if(e)if(Array.isArray(e)){a=[];for(const o of e)a.push(q(o,t))}else if("object"==typeof e||Object.prototype.isPrototypeOf.call(e,Object)){a={};for(const o of Object.keys(e))a[t(o)]=q(e[o],t)}else a=e;else a=e;return a}async function U(){return"crunchyData"}const T={storage:_,getAuthToken:I,getToken:S,getLocale:async function(){return"es-419"},getCms:async function(){let e=null;if(_.cms&&_.cms.bucket){const t=new Date;new Date(_.cms.expires)>t&&(e=_.cms)}return e||(e=await w.getIndexConfig({token:await I()}),_.cms=L(e.cms),e=_.cms,await A()),e},getContentParam:async function(e){return{...await S(),locale:e.preferred_communication_language,audioLanguage:e.preferred_content_audio_language}},loadFromLocal:async function(){let e=null;const t=await U();try{if(R)e=await R();else{const a=window.localStorage.getItem(t);a&&(e=atob(a))}}catch(e){}if(e){const t=JSON.parse(e);Object.assign(_,L(t))}},saveToLocal:A,authDataFile:U,getAccount:async function(){if(!_.account||!_.account.accountId){const e=await $.getAccountId({token:await I()});_.account=L(e),await A()}return _.account},saveToken:P,setExternalStorage:function({save:e,load:t}){void 0!==t&&(R=t),void 0!==e&&(b=e)},setNewData:async function(e){Object.assign(_,e),await A()},switchProfile:async function(e){const t=await v.switchProfile({..._.token,device:_.device,profileId:e});return await P(t),_.token},revokeToken:async function(){_.token&&await v.revokeRefreshToken(_.token),_.token=null,await A()}};const z={getWatchlist:async function({account:e,quantity:t,start:a,ratings:o,order:c}){const r="getWatchlist";d.debug(r);const s={locale:e.locale,preferred_audio_language:e.audioLanguage};if(f.addParam(s,"n",t,(e=>e>0)),f.addParam(s,"start",a,(e=>e>=0)),f.addParam(s,"ratings",o),c&&!["desc","asc"].includes(c))throw new n("Wrong order value");f.addParam(s,"order",c);const i=await f.toURLSearchParams(s),u=`/content/v2/discover/${e.accountId}/watchlist?${i}`,l={method:"get",headers:{Authorization:e.token}};return f.makeRequest(r,u,l)},getBrowseAll:async function({account:e,quantity:t,start:a,category:o,query:c,seasonTag:r,sort:s,type:i,ratings:u}){const g="getBrowseAll";d.debug(g);const h={locale:e.locale,preferred_audio_language:e.audioLanguage};if(f.addParam(h,"n",t,(e=>e>0)),f.addParam(h,"start",a,(e=>e>=0)),o&&o.length&&f.addParam(h,"categories",o.join(",")),f.addParam(h,"q",c),f.addParam(h,"seasonal_tag",r),s&&!l.sortByValues.includes(s))throw new n("Wrong sort value");f.addParam(h,"sort_by",s),f.addParam(h,"type",i),f.addParam(h,"ratings",u);const m=`/content/v2/discover/browse?${await f.toURLSearchParams(h)}`,p={method:"get",headers:{Authorization:e.token,add_watchlist_status:!0}};return f.makeRequest(g,m,p)},getBrowseIndex:async function({account:e,category:t,sort:a,ratings:o}){const c="getBrowseIndex";d.debug(c);const r={locale:e.locale,preferred_audio_language:e.audioLanguage};if(t&&t.length&&f.addParam(r,"categories",t.join(",")),a&&!l.sortByValues.includes(a))throw new n("Wrong sort value");f.addParam(r,"sort_by",a),f.addParam(r,"ratings",o);const s=`/content/v2/discover/browse/index?${await f.toURLSearchParams(r)}`,i={method:"get",headers:{Authorization:e.token,add_watchlist_status:!0}};return f.makeRequest(c,s,i)},getCategories:async function({account:e,contentId:t}){const a="getCategories";d.debug(a);const o={locale:e.locale,preferred_audio_language:e.audioLanguage};f.addParam(o,"guid",t);const n=`/content/v2/discover/categories?${await f.toURLSearchParams(o)}`,c={method:"get",headers:{Authorization:e.token,add_watchlist_status:!0}};return f.makeRequest(a,n,c)},getSubcategories:async function({account:e,parentCategory:t}){const a="getSubcategories";d.debug(a);const o={locale:e.locale,preferred_audio_language:e.audioLanguage};f.addParam(o,"parent_category",t);const n=`/content/v2/discover/categories/${t}/sub_categories?${await f.toURLSearchParams(o)}`,c={method:"get",headers:{Authorization:e.token}};return f.makeRequest(a,n,c)},getHome:async function({account:e}){const t="getHome";d.debug(t);const a={locale:e.locale},o=await f.toURLSearchParams(a),n=`${l.url}/f/v1/home?${o}`,c={method:"get",headers:{Authorization:e.token},baseUrlIncluded:!0};return f.makeRequest(t,n,c)},getHomeFeed:async function({account:e,quantity:t,start:a}){const o="getHomeFeed";d.debug(o);const n={locale:e.locale,preferred_audio_language:e.audioLanguage};f.addParam(n,"n",t,(e=>e>0)),f.addParam(n,"start",a,(e=>e>=0));const c=await f.toURLSearchParams(n),r=`/content/v2/discover/${e.accountId}/home_feed?${c}`,s={method:"get",headers:{Authorization:e.token}};return f.makeRequest(o,r,s)},getHistory:async function({account:e,quantity:t,ratings:a}){const o="getHistory";d.debug(o);const n={locale:e.locale};f.addParam(n,"n",t,(e=>e>0)),f.addParam(n,"ratings",a);const c=await f.toURLSearchParams(n),r=`/content/v2/discover/${e.accountId}/history?${c}`,s={method:"get",headers:{Authorization:e.token}};return f.makeRequest(o,r,s)},getRecommendations:async function({account:e,quantity:t,start:a,ratings:o}){const n="getRecommendations";d.debug(n);const c={locale:e.locale,preferred_audio_language:e.audioLanguage};f.addParam(c,"n",t,(e=>e>0)),f.addParam(c,"start",a,(e=>e>=0)),f.addParam(c,"ratings",o);const r=await f.toURLSearchParams(c),s=`/content/v2/discover/${e.accountId}/recommendations?${r}`,i={method:"get",headers:{Authorization:e.token}};return f.makeRequest(n,s,i)},getSeasonList:async function({account:e}){const t="getSeasonList";d.debug(t);const a={locale:e.locale,preferred_audio_language:e.audioLanguage},o=`/content/v2/discover/seasonal_tags?${await f.toURLSearchParams(a)}`,n={method:"get",headers:{Authorization:e.token}};return f.makeRequest(t,o,n)},getSimilar:async function({account:e,contentId:t,quantity:a,start:o,ratings:n}){const c="getSimilar";d.debug(c);const r={locale:e.locale,preferred_audio_language:e.audioLanguage};f.addParam(r,"n",a,(e=>e>0)),f.addParam(r,"start",o,(e=>e>=0)),f.addParam(r,"ratings",n);const s=await f.toURLSearchParams(r),i=`/content/v2/discover/${e.accountId}/similar_to/${t}?${s}`,u={method:"get",headers:{Authorization:e.token}};return f.makeRequest(c,i,u)},getNext:async function({account:e,contentId:t}){const a="getNext";d.debug(a);const o={locale:e.locale,preferred_audio_language:e.audioLanguage},n=`/content/v2/discover/up_next/${t}?${await f.toURLSearchParams(o)}`,c={method:"get",headers:{Authorization:e.token}};return f.makeRequest(a,n,c)},getPrev:async function({account:e,contentId:t}){const a="getPrev";d.debug(a);const o={locale:e.locale,preferred_audio_language:e.audioLanguage},n=`/content/v2/discover/previous_episode/${t}?${await f.toURLSearchParams(o)}`,c={method:"get",headers:{Authorization:e.token}};return f.makeRequest(a,n,c)},search:async function({account:e,query:t,quantity:a,start:o,type:c}){const r="search";d.debug(r);const s=l.contentTypes.concat(["top_results","music"]),i={locale:e.locale,preferred_audio_language:e.audioLanguage};if(f.addParam(i,"q",t),f.addParam(i,"n",a,(e=>e>0)),f.addParam(i,"start",o,(e=>e>=0)),c&&c.length){for(const e of c)if(!s.includes(e))throw new n("Wrong type value.");f.addParam(i,"type",c.join(","))}const u=`/content/v2/discover/search?${await f.toURLSearchParams(i)}`,g={method:"get",headers:{Authorization:e.token}};return f.makeRequest(r,u,g)},markAsWatched:async function({account:e,contentId:t}){const a="markAsWatched";d.debug(a);const o={locale:e.locale,preferred_audio_language:e.audioLanguage},n=await f.toURLSearchParams(o),c=`/content/v2/discover/${e.accountId}/mark_as_watched/${t}?${n}`,r={method:"post",headers:{Authorization:e.token}};return f.makeRequest(a,c,r)}};async function C({account:e,contentId:t,contentType:a}){const o="_getRatings";d.debug(o);const n={locale:e.locale},c=await f.toURLSearchParams(n);if(!l.contentTypes.includes(a))throw new Error(`ContentType ${a} is not valid.`);const r=`/content-reviews/v2/user/${e.accountId}/rating/${a}/${t}?${c}`,s={method:"get",headers:{Authorization:e.token}};return f.makeRequest(o,r,s)}const j={getProducts:async function({auth:e,source:t}){const a="getProducts";d.debug(a);const o={locale:e.locale};f.addParam(o,"source",t||"google-play");const n=`/subs/v2/products?${await f.toURLSearchParams(o)}`,c={method:"get",headers:{Authorization:e.token}};return f.makeRequest(a,n,c)},getUserBenefits:async function({auth:e,externalId:t}){const a="getUserBenefits";d.debug(a);const o={locale:e.locale},n=`/subs/v1/subscriptions/${t}/benefits?${await f.toURLSearchParams(o)}`,c={method:"get",headers:{Authorization:e.token}};return f.makeRequest(a,n,c)},getUserSubscription:async function({auth:e,externalId:t}){const a="getUserSubscription";d.debug(a);const o={locale:e.locale},n=`/subs/v1/subscriptions/${t}/products?${await f.toURLSearchParams(o)}`,c={method:"get",headers:{Authorization:e.token}};return f.makeRequest(a,n,c)}};const O={},x={account:$,assets:{getAvatar:async function({token:e,lang:t}){const a="getAvatar";d.debug(a);const o=`/assets/v2/${t}/avatar`,n={method:"get",headers:{Authorization:e}};return f.makeRequest(a,o,n)},getWallpaper:async function({token:e,lang:t}){const a="getWallpaper";d.debug(a);const o=`/assets/v2/${t}/wallpaper`,n={method:"get",headers:{Authorization:e}};return f.makeRequest(a,o,n)}},auth:v,cms:{getEpisode:async function({account:e,episodeId:t}){const a="getEpisode";d.debug(a);const o={locale:e.locale,preferred_audio_language:e.audioLanguage},n=`/content/v2/cms/episodes/${t}?${await f.toURLSearchParams(o)}`,c={method:"get",headers:{Authorization:e.token}};return f.makeRequest(a,n,c)},getEpisodes:async function({account:e,seasonId:t}){const a="getEpisodes";d.debug(a);const o={locale:e.locale,preferred_audio_language:e.audioLanguage},n=`/content/v2/cms/seasons/${t}/episodes?${await f.toURLSearchParams(o)}`,c={method:"get",headers:{Authorization:e.token}};return f.makeRequest(a,n,c)},getMovie:async function({account:e,movieId:t}){const a="getMovie";d.debug(a);const o={locale:e.locale,preferred_audio_language:e.audioLanguage},n=`/content/v2/cms/movies/${t}?${await f.toURLSearchParams(o)}`,c={method:"get",headers:{Authorization:e.token}};return f.makeRequest(a,n,c)},getMovieListing:async function({account:e,movieListingId:t}){const a="getMovieListing";d.debug(a);const o={locale:e.locale,preferred_audio_language:e.audioLanguage},n=`/content/v2/cms/movie_listings/${t}?${await f.toURLSearchParams(o)}`,c={method:"get",headers:{Authorization:e.token}};return f.makeRequest(a,n,c)},getMovieListingExtras:async function({account:e,movieListingId:t}){const a="getMovieListingExtras";d.debug(a);const o={locale:e.locale,preferred_audio_language:e.audioLanguage},n=`/content/v2/cms/movie_listings/${t}/extra_videos?${await f.toURLSearchParams(o)}`,c={method:"get",headers:{Authorization:e.token}};return f.makeRequest(a,n,c)},getMovies:async function({account:e,movieListingId:t}){const a="getMovies";d.debug(a);const o={locale:e.locale,preferred_audio_language:e.audioLanguage},n=`/content/v2/cms/movie_listings/${t}/movies?${await f.toURLSearchParams(o)}`,c={method:"get",headers:{Authorization:e.token}};return f.makeRequest(a,n,c)},getObjects:async function({account:e,objectIds:t,ratings:a}){const o="getObjects";d.debug(o);const n={locale:e.locale,preferred_audio_language:e.audioLanguage};f.addParam(n,"ratings",a);const c=await f.toURLSearchParams(n),r=`/content/v2/cms/objects/${t.join(",")}?${c}`,s={method:"get",headers:{Authorization:e.token}};return f.makeRequest(o,r,s)},getSeason:async function({account:e,seasonId:t}){const a="getSeason";d.debug(a);const o={locale:e.locale,preferred_audio_language:e.audioLanguage},n=`/content/v2/cms/seasons/${t}?${await f.toURLSearchParams(o)}`,c={method:"get",headers:{Authorization:e.token}};return f.makeRequest(a,n,c)},getSeasonExtras:async function({account:e,seasonId:t}){const a="getSeasonExtras";d.debug(a);const o={locale:e.locale,preferred_audio_language:e.audioLanguage},n=`/content/v2/cms/seasons/${t}/extra_videos?${await f.toURLSearchParams(o)}`,c={method:"get",headers:{Authorization:e.token}};return f.makeRequest(a,n,c)},getSeasons:async function({account:e,serieId:t}){const a="getSeasons";d.debug(a);const o={locale:e.locale,preferred_audio_language:e.audioLanguage},n=`/content/v2/cms/series/${t}/seasons?${await f.toURLSearchParams(o)}`,c={method:"get",headers:{Authorization:e.token}};return f.makeRequest(a,n,c)},getSeries:async function({account:e,serieId:t}){const a="getSeries";d.debug(a);const o={locale:e.locale,preferred_audio_language:e.audioLanguage},n=`/content/v2/cms/series/${t}?${await f.toURLSearchParams(o)}`,c={method:"get",headers:{Authorization:e.token}};return f.makeRequest(a,n,c)},getStreamsWithURL:async function({account:e,streamUrl:t}){const a="getStreamsWithURL";d.debug(a);const o={locale:e.locale,preferred_audio_language:e.audioLanguage},n=`${t}?${await f.toURLSearchParams(o)}`,c={method:"get",headers:{Authorization:e.token}};return f.makeRequest(a,n,c)},getStreams:async function({account:e,contentId:t}){const a="getStreams";d.debug(a);const o={locale:e.locale,preferred_audio_language:e.audioLanguage},n=`/content/v2/cms/videos/${t}/streams?${await f.toURLSearchParams(o)}`,c={method:"get",headers:{Authorization:e.token}};return f.makeRequest(a,n,c)},getSkiptEvents:async function({account:e,contentId:t}){const a="getSkiptEvents";d.debug(a);const o=`${l.urlStatic}/skip-events/production/${t}.json`,n={method:"get",headers:{Authorization:e.token},baseUrlIncluded:!0};let c=null;try{c=await f.makeRequest(a,o,n)}catch(e){}return c}},content:{addItemToCustomList:async function({account:e,listId:t,contentId:a}){const o="addItemToCustomList";d.debug(o);const n={locale:e.locale,preferred_audio_language:e.audioLanguage},c=await f.toURLSearchParams(n),r=`/content/v2/${e.accountId}/custom-lists/${t}?${c}`,s={method:"post",headers:{Authorization:e.token,"Content-Type":"application/json"},body:JSON.stringify({content_id:a})};return f.makeRequest(o,r,s)},addWatchlistItem:async function({account:e,contentId:t}){const a="addWatchlistItem";d.debug(a);const o={locale:e.locale,preferred_audio_language:e.audioLanguage},n=await f.toURLSearchParams(o),c=`/content/v2/${e.accountId}/watchlist?${n}`,r={method:"post",headers:{Authorization:e.token,"Content-Type":"application/json"},body:JSON.stringify({content_id:t})};return f.makeRequest(a,c,r)},changeCustomListItemPosition:async function({account:e,listId:t,contentId:a,location:o,refContentId:c}){const r="changeCustomListItemPosition";d.debug(r);const s={locale:e.locale,preferred_audio_language:e.audioLanguage},i=await f.toURLSearchParams(s),u=`/content/v2/${e.accountId}/custom-lists/${t}/${a}/position?${i}`;if(!["after","before"].includes(o))throw new n("Wrong location");const l={method:"put",headers:{Authorization:e.token,"Content-Type":"application/json"},body:JSON.stringify({location:o,ref_content_id:c})};return f.makeRequest(r,u,l)},createPrivateCustomList:async function({account:e,title:t}){const a="createPrivateCustomList";d.debug(a);const o={locale:e.locale,preferred_audio_language:e.audioLanguage},n=await f.toURLSearchParams(o),c=`/content/v2/${e.accountId}/custom-lists?${n}`,r={method:"post",headers:{Authorization:e.token,"Content-Type":"application/json"},body:JSON.stringify({title:t})};return f.makeRequest(a,c,r)},deleteCustomListItem:async function({account:e,listId:t,contentId:a}){const o="deleteCustomListItem";d.debug(o);const n={locale:e.locale,preferred_audio_language:e.audioLanguage},c=await f.toURLSearchParams(n),r=`/content/v2/${e.accountId}/custom-lists/${t}/${a}?${c}`,s={method:"delete",headers:{Authorization:e.token,"Content-Type":"application/json"}};return f.makeRequest(o,r,s)},deletePrivateCustomList:async function({account:e,listId:t}){const a="deletePrivateCustomList";d.debug(a);const o={locale:e.locale,preferred_audio_language:e.audioLanguage},n=await f.toURLSearchParams(o),c=`/content/v2/${e.accountId}/custom-lists/${t}?${n}`,r={method:"delete",headers:{Authorization:e.token,"Content-Type":"application/json"}};return f.makeRequest(a,c,r)},deleteWatchlistItem:async function({account:e,contentId:t}){const a="deleteWatchlistItem";d.debug(a);const o={locale:e.locale,preferred_audio_language:e.audioLanguage},n=await f.toURLSearchParams(o),c=`/content/v2/${e.accountId}/watchlist/${t}?${n}`,r={method:"delete",headers:{Authorization:e.token,"Content-Type":"application/json"}};return f.makeRequest(a,c,r)},getCustomListItems:async function({account:e,listId:t,page:a,pageSize:o,sort:c,order:r}){const s="getCustomListItems";d.debug(s);const i={locale:e.locale,preferred_audio_language:e.audioLanguage};if(f.addParam(i,"page",a),f.addParam(i,"page_size",o),c&&!["manual","date_added"].includes(c))throw new n("Wrong sort value");if(f.addParam(i,"sort_by",c),r&&!["asc","desc"].includes(r))throw new n("Wrong order value");f.addParam(i,"order",r);const u=await f.toURLSearchParams(i),l=`/content/v2/${e.accountId}/custom-lists/${t}?${u}`,g={method:"get",headers:{Authorization:e.token}};return f.makeRequest(s,l,g)},getCustomLists:async function({account:e}){const t="getCustomLists";d.debug(t);const a={locale:e.locale,preferred_audio_language:e.audioLanguage},o=await f.toURLSearchParams(a),n=`/content/v2/${e.accountId}/custom-lists?${o}`,c={method:"get",headers:{Authorization:e.token}};return f.makeRequest(t,n,c)},getData:async function({account:e,method:t="get",baseUrlIncluded:a=!1,url:o,body:n=null,headers:c={},queryParams:r={}}){const s="getData";d.debug(s);const i={locale:e.locale,preferred_audio_language:e.audioLanguage,...r},u=`${o}?${await f.toURLSearchParams(i)}`,l={method:t,headers:{Authorization:e.token,"Content-Type":"application/json",...c},baseUrlIncluded:a,body:n&&JSON.stringify(n)};return f.makeRequest(s,u,l)},getPlayheads:async function({account:e,contentIds:t}){return async function({account:e,contentIds:t,uploadOfflinePlayheads:a}){const o="_getPlayheads";d.debug(o);const n={locale:e.locale,preferred_audio_language:e.audioLanguage};f.addParam(n,"content_ids",t.join(","));const c=await f.toURLSearchParams(n),r=`/content/v2/${e.accountId}/playheads?${c}`,s={method:"get",headers:{Authorization:e.token,upload_offline_playheads:a}};return f.makeRequest(o,r,s)}({account:e,contentIds:t,uploadOfflinePlayheads:!0})},getWatchHistory:async function({account:e,page:t,pageSize:a}){const o="getWatchHistory";d.debug(o);const n={locale:e.locale,preferred_audio_language:e.audioLanguage};f.addParam(n,"page",t,(e=>e>0)),f.addParam(n,"page_size",a,(e=>e>0));const c=await f.toURLSearchParams(n),r=`/content/v2/${e.accountId}/watch-history?${c}`,s={method:"get",headers:{Authorization:e.token,upload_offline_playheads:!0}};return f.makeRequest(o,r,s)},getWatchlistItems:async function({account:e,contentIds:t}){const a="getWatchlistItems";d.debug(a);const o={locale:e.locale,preferred_audio_language:e.audioLanguage};t&&t.length&&f.addParam(o,"content_ids",t.join(","));const n=await f.toURLSearchParams(o);let c=`/content/v2/${e.accountId}/watchlist?${n}`;const r={method:"get",headers:{Authorization:e.token}};return f.makeRequest(a,c,r)},savePlayhead:async function({account:e,contentId:t,playhead:a}){const o="savePlayhead";d.debug(o);const n={locale:e.locale,preferred_audio_language:e.audioLanguage},c=await f.toURLSearchParams(n),r=`/content/v2/${e.accountId}/playheads?${c}`,s={method:"post",headers:{Authorization:e.token,"Content-Type":"application/json"},body:JSON.stringify({content_id:t,playhead:a})};return f.makeRequest(o,r,s)},updateCustomList:async function({account:e,listId:t,title:a}){const o="updateCustomList";d.debug(o);const n={locale:e.locale,preferred_audio_language:e.audioLanguage},c=await f.toURLSearchParams(n),r=`/content/v2/${e.accountId}/custom-lists/${t}?${c}`,s={method:"patch",headers:{Authorization:e.token,"Content-Type":"application/json"},body:JSON.stringify({title:a})};return f.makeRequest(o,r,s)},updateWatchlistItemFavoriteStatus:async function({account:e,contentId:t,isFavorite:a}){const o="updateWatchlistItemFavoriteStatus";d.debug(o);const n={locale:e.locale,preferred_audio_language:e.audioLanguage},c=await f.toURLSearchParams(n),r=`/content/v2/${e.accountId}/watchlist/${t}?${c}`,s={method:"patch",headers:{Authorization:e.token,"Content-Type":"application/json"},body:JSON.stringify({is_favorite:a})};return f.makeRequest(o,r,s)}},discover:z,drm:{getStream:async function({account:e,episodeId:t,type:a,browser:o}){const n="getStream";if(d.debug(n),a=a?`/${a}`:"",!["chrome","firefox","safari","explorer"].includes(o=o||"chrome"))throw new Error("Wrong browser, "+o);const c=`${l.urlDrm}/v1${a}/${t}/web/${o}/play`,r={method:"get",headers:{Authorization:e.token},baseUrlIncluded:!0};return f.makeRequest(n,c,r)},getAuth:async function({account:e,assetId:t,sessionId:a}){const o="getAuth";d.debug(o);const n=`${l.urlPl}/drm/v1/auth`,c={method:"post",headers:{Authorization:e.token},baseUrlIncluded:!0,body:JSON.stringify({accounting_id:l.accountingId,asset_id:t,session_id:a,user_id:e.accountId})};return f.makeRequest(o,n,c)},keepAlive:async function({account:e,token:t,episodeId:a,playhead:o}){const n="keepAlive";d.debug(n);const c={playhead:o},r=await f.toURLSearchParams(c),s=`${l.urlDrm}/v1/token/${a}/${t}/keepAlive?${r}`;let i=null,u=null;try{u=window.FormData}catch(e){}i=new u,i.append("position",o.toString());const g={method:"PATCH",headers:{Authorization:e.token},baseUrlIncluded:!0,body:i};return f.makeRequest(n,s,g)},revokeToken:async function({account:e,episodeId:t,token:a}){const o="revokeToken";d.debug(o);const n=`${l.urlDrm}/v1/token/${t}/${a}/delete`,c={method:"post",headers:{Authorization:e.token},baseUrlIncluded:!0};return f.makeRequest(o,n,c)},deleteToken:async function({account:e,episodeId:t,token:a}){const o="deleteToken";d.debug(o);const n=`${l.urlDrm}/v1/token/${t}/${a}`,c={method:"delete",headers:{Authorization:e.token},baseUrlIncluded:!0};return f.makeRequest(o,n,c)}},index:w,music:{getArtist:async function({account:e,artistIds:t}){const a="getArtist";d.debug(a);const o={locale:e.locale,preferred_audio_language:e.audioLanguage},n=await f.toURLSearchParams(o),c=`/content/v2/music/artists/${t.join(",")}?${n}`,r={method:"get",headers:{Authorization:e.token}};return f.makeRequest(a,c,r)},getArtistConcerts:async function({account:e,artistId:t}){const a="getArtistConcerts";d.debug(a);const o={locale:e.locale,preferred_audio_language:e.audioLanguage},n=`/content/v2/music/artists/${t}/concerts?${await f.toURLSearchParams(o)}`,c={method:"get",headers:{Authorization:e.token}};return f.makeRequest(a,n,c)},getArtistVideos:async function({account:e,artistId:t}){const a="getArtistVideos";d.debug(a);const o={locale:e.locale,preferred_audio_language:e.audioLanguage},n=`/content/v2/music/artists/${t}/music_videos?${await f.toURLSearchParams(o)}`,c={method:"get",headers:{Authorization:e.token}};return f.makeRequest(a,n,c)},getConcerts:async function({account:e,concertIds:t}){const a="getConcerts";d.debug(a);const o={locale:e.locale,preferred_audio_language:e.audioLanguage},n=await f.toURLSearchParams(o),c=`/content/v2/music/concerts/${t.join(",")}?${n}`,r={method:"get",headers:{Authorization:e.token}};return f.makeRequest(a,c,r)},getFeed:async function({account:e,quantity:t,start:a}){const o="getFeed";d.debug(o);const n={locale:e.locale,preferred_audio_language:e.audioLanguage};f.addParam(n,"n",t,(e=>e>0)),f.addParam(n,"start",a,(e=>e>=0));const c=await f.toURLSearchParams(n),r=`/content/v2/music/${e.accountId}/landing_feed?${c}`,s={method:"get",headers:{Authorization:e.token}};return f.makeRequest(o,r,s)},getStreams:async function({account:e,contentId:t}){const a="getStreams";d.debug(a);const o={locale:e.locale,preferred_audio_language:e.audioLanguage},n=`/content/v2/music/${t}/streams?${await f.toURLSearchParams(o)}`,c={method:"get",headers:{Authorization:e.token}};return f.makeRequest(a,n,c)},getStreamsWithURL:async function({account:e,streamUrl:t}){const a="getStreamsWithURL";d.debug(a);const o={locale:e.locale,preferred_audio_language:e.audioLanguage},n=`${t}?${await f.toURLSearchParams(o)}`,c={method:"get",headers:{Authorization:e.token}};return f.makeRequest(a,n,c)},getVideo:async function({account:e,musicIds:t}){const a="getVideo";d.debug(a);const o={locale:e.locale,preferred_audio_language:e.audioLanguage},n=await f.toURLSearchParams(o),c=`/content/v2/music/music_videos/${t.join(",")}?${n}`,r={method:"get",headers:{Authorization:e.token}};return f.makeRequest(a,c,r)},getFeatured:async function({account:e,contentId:t}){const a="getFeatured";d.debug(a);const o={locale:e.locale,preferred_audio_language:e.audioLanguage},n=`/content/v2/music/featured/${t}?${await f.toURLSearchParams(o)}`,c={method:"get",headers:{Authorization:e.token}};return f.makeRequest(a,n,c)}},review:{addEpisodeRating:async function({account:e,contentId:t,rating:a,contentType:o}){const n="addEpisodeRating";d.debug(n);const c={locale:e.locale},r=await f.toURLSearchParams(c);if(o=o||"episode",!l.contentTypes.includes(o))throw new Error(`ContentType ${o} is not valid.`);if(!l.ratingEpisodeTypes.includes(a))throw new Error(`Rating ${a} is not valid.`);const s=`/content-reviews/v2/user/${e.accountId}/rating/${o}/${t}?${r}`,i={method:"put",headers:{Authorization:e.token,"Content-Type":"application/json"},body:JSON.stringify({rating:a})};return f.makeRequest(n,s,i)},addRating:async function({account:e,contentId:t,rating:a,contentType:o}){const n="addRating";d.debug(n);const c={locale:e.locale},r=await f.toURLSearchParams(c);if(!l.contentTypes.includes(o))throw new Error(`ContentType ${o} is not valid.`);if(!l.ratingContentTypes.includes(a))throw new Error(`Rating ${a} is not valid.`);const s=`/content-reviews/v2/user/${e.accountId}/rating/${o}/${t}?${r}`,i={method:"put",headers:{Authorization:e.token,"Content-Type":"application/json"},body:JSON.stringify({rating:a})};return f.makeRequest(n,s,i)},getEpisodeRatings:async function({account:e,contentId:t}){return C({account:e,contentId:t,contentType:"episode"})},getRatings:async function({account:e,contentId:t,contentType:a}){return C({account:e,contentId:t,contentType:a})},removeRating:async function({account:e,contentId:t,contentType:a}){const o="removeRating";d.debug(o);const n={locale:e.locale},c=await f.toURLSearchParams(n);if(!l.contentTypes.includes(a))throw new Error(`ContentType ${a} is not valid.`);const r=`/content-reviews/v2/user/${e.accountId}/rating/${a}/${t}?${c}`,s={method:"delete",headers:{Authorization:e.token}};return f.makeRequest(o,r,s)}},subscription:j},E={logger:d,localStore:T,CrunchyrollError:n,config:l,api:x,utils:f};var W=t.II,D=t.Or,N=t.FH,M=t.$W,F=t.Ay,J=t.xM,B=t.vF,V=t.Wp;export{W as CrunchyrollError,D as Types,N as api,M as config,F as default,J as localStore,B as logger,V as utils};