UNPKG

crunchyroll-js-api

Version:
1 lines 37.8 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:()=>j});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.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 l=null;function g(){return`Crunchyroll/${d.versionName} Android/${d.osReleaseVersion}`}async function f(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 h(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"]=g(),l)o=l;else try{o=window.fetch}catch(e){}return o(e,t,n||{})}const m={camelCase:function(e){return e.replace(/_([a-z])/g,(e,t)=>t.toUpperCase())},logRes:f,makeRawRequest:h,makeRequest:async function(e,t,n,o){const a=await h(t,n,o);await f(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:g};function p(){const e=`${d.clientId}:${d.clientSecret}`;return Buffer.from(e).toString("base64")}async function y({device:e,credentials:t,grantType:n,scope:o,fnConfig:a}){const c="_makeLogin";u.debug(c);const r=p(),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 m.toURLSearchParams(s),headers:{Authorization:`Basic ${r}`,"Content-Type":"application/x-www-form-urlencoded","ETP-Anonymous-ID":null}},d=await m.makeRequest(c,"/auth/v1/token",i,a);return d&&(d.created_date=(new Date).toISOString()),d}const k={getDeviceCode:async function(e){const t="getDeviceCode";u.debug(t);const n=p(),o={method:"post",body:await m.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 m.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=p(),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 m.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"),y({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"),y({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"),y({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"),y({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=p(),a={token:e},c={method:"post",body:await m.toURLSearchParams(a),headers:{Authorization:`Basic ${o}`,"Content-Type":"application/x-www-form-urlencoded","ETP-Anonymous-ID":null}};return m.makeRequest(n,"/auth/v1/revoke",c,t)},switchProfile:async function({device:e,scope:t,refreshToken:n,profileId:o,fnConfig:a}){return u.debug("switchProfile"),y({device:e,scope:t,grantType:"refresh_token_profile_id",credentials:{refresh_token:n,profile_id:o},fnConfig:a})}};const v={getIndexConfig:async function({token:e,fnConfig:t}){const n="getIndexConfig";u.debug(n);const o={method:"get",headers:{Authorization:e}};return m.makeRequest(n,"/index/v2",o,t)}};const w={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 m.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 m.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 m.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 m.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 m.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 m.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 m.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 m.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 m.makeRequest(a,c,r,o)}},$={credential:null,device:null,token:null,cms:null,account:null};let _=null,R=null;function b(e){return S(e,m.toCamel)}async function C(e){e?($.token=b(e),$.token.token=`${$.token.tokenType} ${$.token.accessToken}`):$.token=null,await I()}async function L(){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 k.getRefreshToken({...$.token,device:$.device}):$.credential&&(t=await k.getToken({...$.credential,device:$.device})),await C(t),e=$.token}if(!e)throw new o("No auth token found.");return e.token}async function P(){return await L(),$.token}async function I(){const e=await A(),t=JSON.stringify(S($,m.toSnake),null,"\t");try{_?await _(t):window.localStorage.setItem(e,btoa(t))}catch(e){}}function S(e,t){let n;if(e)if(Array.isArray(e)){n=[];for(const o of e)n.push(S(o,t))}else if("object"==typeof e||Object.prototype.isPrototypeOf.call(e,Object)){n={};for(const o of Object.keys(e))n[t(o)]=S(e[o],t)}else n=e;else n=e;return n}async function A(){return"crunchyData"}const q={storage:$,getAuthToken:L,getToken:P,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 v.getIndexConfig({token:await L()}),$.cms=b(e.cms),e=$.cms,await I()),e},getContentParam:async function(e){return{...await P(),locale:e.preferred_communication_language,audioLanguage:e.preferred_content_audio_language}},loadFromLocal:async function(){let e=null;const t=await A();try{if(R)e=await R();else{const n=window.localStorage.getItem(t);n&&(e=atob(n))}}catch(e){}if(e){const t=JSON.parse(e);Object.assign($,b(t))}},saveToLocal:I,authDataFile:A,getAccount:async function(){if(!$.account||!$.account.accountId){const e=await w.getAccountId({token:await L()});$.account=b(e),await I()}return $.account},saveToken:C,setExternalStorage:function({save:e,load:t}){void 0!==t&&(R=t),void 0!==e&&(_=e)},setNewData:async function(e){Object.assign($,e),await I()},switchProfile:async function(e){const t=await k.switchProfile({...$.token,device:$.device,profileId:e});return await C(t),$.token},revokeToken:async function(){$.token&&await k.revokeRefreshToken($.token),$.token=null,await I()}};const U={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(m.addParam(i,"n",t,e=>e>0),m.addParam(i,"start",n,e=>e>=0),m.addParam(i,"ratings",a),c&&!["desc","asc"].includes(c))throw new o("Wrong order value");m.addParam(i,"order",c);const d=await m.toURLSearchParams(i),l=`/content/v2/discover/${e.accountId}/watchlist?${d}`,g={method:"get",headers:{Authorization:e.token}};return m.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(m.addParam(h,"n",t,e=>e>0),m.addParam(h,"start",n,e=>e>=0),a&&a.length&&m.addParam(h,"categories",a.join(",")),m.addParam(h,"q",c),m.addParam(h,"seasonal_tag",r),s&&!d.sortByValues.includes(s))throw new o("Wrong sort value");m.addParam(h,"sort_by",s),m.addParam(h,"type",i),m.addParam(h,"ratings",l);const p=`/content/v2/discover/browse?${await m.toURLSearchParams(h)}`,y={method:"get",headers:{Authorization:e.token,add_watchlist_status:!0}};return m.makeRequest(f,p,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&&m.addParam(s,"categories",t.join(",")),n&&!d.sortByValues.includes(n))throw new o("Wrong sort value");m.addParam(s,"sort_by",n),m.addParam(s,"ratings",a);const i=`/content/v2/discover/browse/index?${await m.toURLSearchParams(s)}`,l={method:"get",headers:{Authorization:e.token,add_watchlist_status:!0}};return m.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};m.addParam(a,"guid",t);const c=`/content/v2/discover/categories?${await m.toURLSearchParams(a)}`,r={method:"get",headers:{Authorization:e.token,add_watchlist_status:!0}};return m.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};m.addParam(a,"parent_category",t);const c=`/content/v2/discover/categories/${t}/sub_categories?${await m.toURLSearchParams(a)}`,r={method:"get",headers:{Authorization:e.token}};return m.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 m.toURLSearchParams(o),c=`${d.url}/f/v1/home?${a}`,r={method:"get",headers:{Authorization:e.token},baseUrlIncluded:!0};return m.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};m.addParam(c,"n",t,e=>e>0),m.addParam(c,"start",n,e=>e>=0);const r=await m.toURLSearchParams(c),s=`/content/v2/discover/${e.accountId}/home_feed?${r}`,i={method:"get",headers:{Authorization:e.token}};return m.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 m.toURLSearchParams(r),i=`${d.url}/personalization/v2/personalization?${s}`,l={method:"get",headers:{Authorization:e.token},baseUrlIncluded:!0};return m.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};m.addParam(c,"n",t,e=>e>0),m.addParam(c,"ratings",n);const r=await m.toURLSearchParams(c),s=`/content/v2/discover/${e.accountId}/history?${r}`,i={method:"get",headers:{Authorization:e.token}};return m.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};m.addParam(r,"n",t,e=>e>0),m.addParam(r,"start",n,e=>e>=0),m.addParam(r,"ratings",o);const s=await m.toURLSearchParams(r),i=`/content/v2/discover/${e.accountId}/recommendations?${s}`,d={method:"get",headers:{Authorization:e.token}};return m.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 m.toURLSearchParams(o)}`,c={method:"get",headers:{Authorization:e.token}};return m.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};m.addParam(s,"n",n,e=>e>0),m.addParam(s,"start",o,e=>e>=0),m.addParam(s,"ratings",a);const i=await m.toURLSearchParams(s),d=`/content/v2/discover/${e.accountId}/similar_to/${t}?${i}`,l={method:"get",headers:{Authorization:e.token}};return m.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 m.toURLSearchParams(a)}`,r={method:"get",headers:{Authorization:e.token}};return m.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 m.toURLSearchParams(a)}`,r={method:"get",headers:{Authorization:e.token}};return m.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(m.addParam(l,"q",t),m.addParam(l,"n",n,e=>e>0),m.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.");m.addParam(l,"type",c.join(","))}const g=`/content/v2/discover/search?${await m.toURLSearchParams(l)}`,f={method:"get",headers:{Authorization:e.token}};return m.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 m.toURLSearchParams(a),r=`/content/v2/discover/${e.accountId}/mark_as_watched/${t}?${c}`,s={method:"post",headers:{Authorization:e.token}};return m.makeRequest(o,r,s,n)}};async function T({account:e,contentId:t,contentType:n,fnConfig:o}){const a="_getRatings";u.debug(a);const c={locale:e.locale},r=await m.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 m.makeRequest(a,s,i,o)}const z={getProducts:async function({auth:e,source:t,fnConfig:n}){const o="getProducts";u.debug(o);const a={locale:e.locale};m.addParam(a,"source",t||"google-play");const c=`/subs/v2/products?${await m.toURLSearchParams(a)}`,r={method:"get",headers:{Authorization:e.token}};return m.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 m.toURLSearchParams(a)}`,r={method:"get",headers:{Authorization:e.token}};return m.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 m.toURLSearchParams(a)}`,r={method:"get",headers:{Authorization:e.token}};return m.makeRequest(o,c,r,n)}};const j={},O={account:w,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 m.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 m.makeRequest(o,a,c,n)}},auth:k,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 m.toURLSearchParams(a)}`,r={method:"get",headers:{Authorization:e.token}};return m.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 m.toURLSearchParams(a)}`,r={method:"get",headers:{Authorization:e.token}};return m.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 m.toURLSearchParams(a)}`,r={method:"get",headers:{Authorization:e.token}};return m.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 m.toURLSearchParams(a)}`,r={method:"get",headers:{Authorization:e.token}};return m.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 m.toURLSearchParams(a)}`,r={method:"get",headers:{Authorization:e.token}};return m.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 m.toURLSearchParams(a)}`,r={method:"get",headers:{Authorization:e.token}};return m.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};m.addParam(c,"ratings",n);const r=await m.toURLSearchParams(c),s=`/content/v2/cms/objects/${t.join(",")}?${r}`,i={method:"get",headers:{Authorization:e.token}};return m.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 m.toURLSearchParams(a)}`,r={method:"get",headers:{Authorization:e.token}};return m.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 m.toURLSearchParams(a)}`,r={method:"get",headers:{Authorization:e.token}};return m.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 m.toURLSearchParams(a)}`,r={method:"get",headers:{Authorization:e.token}};return m.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 m.toURLSearchParams(a)}`,r={method:"get",headers:{Authorization:e.token}};return m.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 m.toURLSearchParams(a)}`,r={method:"get",headers:{Authorization:e.token}};return m.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 m.toURLSearchParams(a)}`,r={method:"get",headers:{Authorization:e.token}};return m.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 m.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 m.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 m.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 m.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 m.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 m.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 m.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 m.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 m.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 m.toURLSearchParams(c),s=`/content/v2/${e.accountId}/custom-lists/${t}/${n}?${r}`,i={method:"delete",headers:{Authorization:e.token,"Content-Type":"application/json"}};return m.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 m.toURLSearchParams(a),r=`/content/v2/${e.accountId}/custom-lists/${t}?${c}`,s={method:"delete",headers:{Authorization:e.token,"Content-Type":"application/json"}};return m.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 m.toURLSearchParams(a),r=`/content/v2/${e.accountId}/watchlist/${t}?${c}`,s={method:"delete",headers:{Authorization:e.token,"Content-Type":"application/json"}};return m.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(m.addParam(d,"page",n),m.addParam(d,"page_size",a),c&&!["manual","date_added"].includes(c))throw new o("Wrong sort value");if(m.addParam(d,"sort_by",c),r&&!["asc","desc"].includes(r))throw new o("Wrong order value");m.addParam(d,"order",r);const l=await m.toURLSearchParams(d),g=`/content/v2/${e.accountId}/custom-lists/${t}?${l}`,f={method:"get",headers:{Authorization:e.token}};return m.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 m.toURLSearchParams(o),c=`/content/v2/${e.accountId}/custom-lists?${a}`,r={method:"get",headers:{Authorization:e.token}};return m.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 m.toURLSearchParams(d)}`,g={method:t,headers:{Authorization:e.token,"Content-Type":"application/json",...c},baseUrlIncluded:n,body:a&&JSON.stringify(a)};return m.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};m.addParam(c,"content_ids",t.join(","));const r=await m.toURLSearchParams(c),s=`/content/v2/${e.accountId}/playheads?${r}`,i={method:"get",headers:{Authorization:e.token,upload_offline_playheads:n}};return m.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};m.addParam(c,"page",t,e=>e>0),m.addParam(c,"page_size",n,e=>e>0);const r=await m.toURLSearchParams(c),s=`/content/v2/${e.accountId}/watch-history?${r}`,i={method:"get",headers:{Authorization:e.token,upload_offline_playheads:!0}};return m.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&&m.addParam(a,"content_ids",t.join(","));const c=await m.toURLSearchParams(a);let r=`/content/v2/${e.accountId}/watchlist?${c}`;const s={method:"get",headers:{Authorization:e.token}};return m.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 m.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 m.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 m.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 m.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 m.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 m.makeRequest(a,s,i,o)}},discover:U,drm:{getStream:async function({account:e,episodeId:t,type:n,browser:o,fnConfig:a}){const c="getStream";if(u.debug(c),n=n?`/${n}`:"",!["chrome","firefox","safari","explorer"].includes(o=o||"chrome"))throw new Error("Wrong browser, "+o);const r=`${d.urlDrm}/v1${n}/${t}/web/${o}/play`,s={method:"get",headers:{Authorization:e.token},baseUrlIncluded:!0};return m.makeRequest(c,r,s,a)},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 m.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 m.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 m.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 m.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 m.makeRequest(a,c,r,o)}},index:v,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 m.toURLSearchParams(a),r=`/content/v2/music/artists/${t.join(",")}?${c}`,s={method:"get",headers:{Authorization:e.token}};return m.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 m.toURLSearchParams(a)}`,r={method:"get",headers:{Authorization:e.token}};return m.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 m.toURLSearchParams(a)}`,r={method:"get",headers:{Authorization:e.token}};return m.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 m.toURLSearchParams(a),r=`/content/v2/music/concerts/${t.join(",")}?${c}`,s={method:"get",headers:{Authorization:e.token}};return m.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};m.addParam(c,"n",t,e=>e>0),m.addParam(c,"start",n,e=>e>=0);const r=await m.toURLSearchParams(c),s=`/content/v2/music/${e.accountId}/landing_feed?${r}`,i={method:"get",headers:{Authorization:e.token}};return m.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 m.toURLSearchParams(a)}`,r={method:"get",headers:{Authorization:e.token}};return m.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 m.toURLSearchParams(a)}`,r={method:"get",headers:{Authorization:e.token}};return m.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 m.toURLSearchParams(a),r=`/content/v2/music/music_videos/${t.join(",")}?${c}`,s={method:"get",headers:{Authorization:e.token}};return m.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 m.toURLSearchParams(a)}`,r={method:"get",headers:{Authorization:e.token}};return m.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 m.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 m.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 m.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 m.makeRequest(c,i,l,a)},getEpisodeRatings:async function({account:e,contentId:t,fnConfig:n}){return T({account:e,contentId:t,contentType:"episode",fnConfig:n})},getRatings:async function({account:e,contentId:t,contentType:n,fnConfig:o}){return T({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 m.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 m.makeRequest(a,s,i,o)}},subscription:z},x={logger:u,localStore:q,CrunchyrollError:o,config:d,api:O,utils:m};export{o as CrunchyrollError,t as Types,O as api,d as config,x as default,q as localStore,u as logger,m as utils};