add: instagram tags (#6447)

This commit is contained in:
oppilate 2020-12-15 11:37:25 +00:00 committed by GitHub
parent 4929eac2a7
commit de2bd58daa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 43 additions and 20 deletions

View File

@ -9,7 +9,7 @@ module.exports = async (ctx) => {
// "discover", "pendingFriendships", "blockedUsers", "directInbox", "directPending",
// "directThread", "user", "tag", "location", "mediaComments", "reelsMedia", "reelsTray",
// "timeline", "musicTrending", "musicSearch", "musicGenre", "musicMood", "usertags", "saved"];
const availableCategories = ['user'];
const availableCategories = ['user', 'tag'];
const category = ctx.params.category;
if (!availableCategories.includes(category)) {
throw Error('Such feed is not supported.');
@ -30,25 +30,48 @@ module.exports = async (ctx) => {
const key = ctx.params.key;
// TODO: extend to other feed categories
const usernameOrId = key;
let userInfo, username, id;
if (!isNaN(usernameOrId)) {
id = usernameOrId;
userInfo = await ig.user.info(id);
username = userInfo.username;
} else {
username = usernameOrId;
id = await ig.user.getIdByUsername(username);
userInfo = await ig.user.info(id);
const nameOrId = key;
let title, link, description, logo;
let itemsRaw;
switch (category) {
case 'user': {
let userInfo, username, id;
if (!isNaN(nameOrId)) {
id = nameOrId;
userInfo = await ig.user.info(id);
username = userInfo.username;
} else {
username = nameOrId;
id = await ig.user.getIdByUsername(username);
userInfo = await ig.user.info(id);
}
description = userInfo.biography;
logo = userInfo.hd_profile_pic_url_info.url;
const fullName = userInfo.full_name;
title = `${fullName} (@${username}) - Instagram`;
link = path.join('https://www.instagram.com', username);
itemsRaw = await ig.feed.user(id).items();
break;
}
case 'tag': {
const tag = nameOrId;
title = `#${tag}) - Instagram`;
link = path.join('https://www.instagram.com', 'explore', 'tags', tag);
itemsRaw = await (await ig.feed.tags(tag).items()).slice(1); // the 0 item is undefined for unknown reason
break;
}
default: {
break;
}
}
const description = userInfo.biography;
const logo = userInfo.hd_profile_pic_url_info.url;
const fullName = userInfo.full_name;
const itemsPromise = await ig.feed.user(id).items();
const items = await Promise.all(
itemsPromise.map(async (item) => {
itemsRaw.map(async (item) => {
// Content
const summary = item.caption ? item.caption.text : '';
const $ = cheerio.load(`<p>${summary}</p>`);
@ -81,9 +104,9 @@ module.exports = async (ctx) => {
);
ctx.state.data = {
title: `${fullName} (@${username}) - Instagram`,
link: path.join('https://www.instagram.com', username),
description: description,
title,
link,
description,
item: items,
icon: 'https://www.instagram.com/static/images/ico/xxhdpi_launcher.png/99cf3909d459.png',
logo,