UNPKG

crunchyroll-js-api

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