import{t as e}from"./ofetch-Dl6dVB_5.mjs";import{t}from"./config-BYRrjYC5.mjs";import{t as n}from"./cache-DUthuMSu.mjs";import{t as r}from"./parse-date-BdYTmLpo.mjs";import{t as i}from"./invalid-parameter-DLv2wPKB.mjs";import{t as a}from"./config-not-found-B9AOp828.mjs";import{n as o,r as s,t as c}from"./common-utils-BJZsKfCy.mjs";import{CookieJar as l}from"tough-cookie";const u=`https://www.instagram.com`,d=u,f=async e=>(await e.getCookieString(d)).match(/csrftoken=([^;]+)/)?.[1],p=async e=>({"sec-fetch-dest":`empty`,"sec-fetch-mode":`cors`,"sec-fetch-site":`same-origin`,"x-asbd-id":359341,"x-csrftoken":await f(e),"x-ig-app-id":936619743392459,"x-ig-www-claim":`0`}),m=async t=>(await e(`${u}/api/v1/web/fxcal/ig_sso_users/`,{headers:{"content-type":`application/x-www-form-urlencoded`,cookie:await t.getCookieString(d),...await p(t)},method:`POST`})).status===`ok`,h=async(t,r)=>{let i,o=await n.get(`instagram:getIdByUsername:${t}`),s=await n.get(`instagram:userInfo:${o}`);if(s=s&&typeof s==`string`?JSON.parse(s):s,!s)try{let s=await e.raw(`${u}/api/v1/users/web_profile_info/`,{headers:{cookie:await r.getCookieString(d),...await p(r)},query:{username:t}});if(s.url.includes(`/accounts/login/`))throw new a(`Invalid cookie`);i=s._data.data.user,o=i.id,await n.set(`instagram:getIdByUsername:${t}`,o,31536e3),await n.set(`instagram:userInfo:${o}`,i)}catch(e){throw e.message.includes(`Cookie not in this host's domain`)?new a(`Invalid cookie`):e}return s||i},g=(r,i,o)=>n.tryGet(`instagram:feed:${r}`,async()=>{let t=await e.raw(`${u}/api/v1/feed/user/${i}/username/`,{headers:{cookie:await o.getCookieString(d),...await p(o)},query:{count:30}});if(t.url.includes(`/accounts/login/`))throw new a(`Invalid cookie.
                Please also check if your account is being blocked by Instagram.`);return t._data.items},t.cache.routeExpire,!1),_=(r,i)=>n.tryGet(`instagram:tags:${r}`,async()=>(await e(`${u}/api/v1/tags/web_info/`,{headers:{cookie:await i.getCookieString(d),...await p(i)},query:{tag_name:r}})).data,t.cache.routeExpire,!1),v=e=>{let t=(e,t)=>o({summary:t,image:e.display_url,video:{url:e.video_url,height:e.dimensions.height,width:e.dimensions.width}}),n=(e,t)=>s({summary:t,images:[{url:e.display_url,height:e.dimensions.height,width:e.dimensions.width}]});return e.map(({node:e})=>{let i=e.__typename,a=e.edge_media_to_caption.edges[0]?.node.text??``,o;switch(i){case`GraphSidecar`:o=e.edge_sidecar_to_children?e.edge_sidecar_to_children.edges.map(({node:e},r)=>{let i=e.__typename;switch(i){case`GraphVideo`:return t(e,r===0?a:``);case`GraphImage`:return n(e,r===0?a:``);default:throw Error(`Instagram: Unhandled carousel type: ${i}`)}}).join(``):s(e,a);break;case`GraphVideo`:o=t(e,a);break;case`GraphImage`:o=n(e,a);break;default:throw Error(`Instagram: Unhandled feed type: ${i}`)}return{title:a.split(`
`)[0],id:e.id,pubDate:r(e.taken_at_timestamp,`X`),author:e.owner.username,link:`${u}/p/${e.shortcode}/`,summary:a,description:o}})},y={path:`/2/:category/:key`,categories:[`social-media`],example:`/instagram/2/user/stefaniejoosten`,parameters:{category:`Feed category, see table below`,key:`Username / Hashtag name`},features:{requireConfig:!1,requirePuppeteer:!1,antiCrawler:!0,supportBT:!1,supportPodcast:!1,supportScihub:!1},name:`User Profile / Hashtag`,maintainers:[`TonyRL`],handler:b,description:`::: tip
You may need to setup cookie for a less restrictive rate limit and private profiles.
:::


| User timeline | Hashtag |
| ------------- | ------- |
| user          | tags    |`};async function b(e){let r=[`user`,`tags`],{category:o,key:s}=e.req.param(),{cookie:f}=t.instagram;if(!r.includes(o))throw new i(`Such feed is not supported.`);let p=await n.get(`instagram:cookieJar`);if(p)p=l.fromJSON(p);else if(p=new l,f)for await(let e of f.split(`; `))await p.setCookie(e,d);if(f&&!await m(p))throw new a(`Invalid cookie`);let y,b,x,S,C;switch(o){case`user`:{let e=await h(s,p),t=e.biography,n=e.full_name,r=e.id,i=e.username;y=`${n} (@${i}) - Instagram`,x=t,S=e.profile_pic_url_hd??e.hd_profile_pic_url_info?.url??e.profile_pic_url,b=`${u}/${i}`,C=f?await g(r,i,p):[...e.edge_felix_video_timeline.edges,...e.edge_owner_to_timeline_media.edges];break}case`tags`:{if(!t.instagram||!t.instagram.cookie)throw new a(`Instagram RSS is disabled due to the lack of <a href="https://docs.rsshub.app/deploy/config#route-specific-configurations">relevant config</a>`);let e=s;y=`#${e} - Instagram`,b=`${u}/explore/search/keyword/?q=%23${e}`;let n=await _(e,p);S=n.profile_pic_url,C=n.top.sections.flatMap(e=>(e.feed_type===`media`?e.layout_content.medias:[...e.layout_content.one_by_two_item.clips.items,...e.layout_content.fill_items]).map(e=>e.media));break}default:break}return await n.set(`instagram:cookieJar`,p.toJSON(),31536e3),{title:y,link:b,description:x,item:f?c(C):v(C),icon:`${u}/static/images/ico/xxhdpi_launcher.png/99cf3909d459.png`,logo:S,image:S,allowEmpty:!0}}export{y as route};