Add IGTV
This commit is contained in:
@@ -12,7 +12,7 @@ const requestCache = new RequestCache(constants.caching.resource_cache_time)
|
||||
const userRequestCache = new UserRequestCache(constants.caching.resource_cache_time)
|
||||
/** @type {import("./cache").TtlCache<import("./structures/TimelineEntry")>} */
|
||||
const timelineEntryCache = new TtlCache(constants.caching.resource_cache_time)
|
||||
const history = new RequestHistory(["user", "timeline", "post", "reel"])
|
||||
const history = new RequestHistory(["user", "timeline", "igtv", "post", "reel"])
|
||||
|
||||
const AssistantSwitcher = require("./structures/AssistantSwitcher")
|
||||
const assistantSwitcher = new AssistantSwitcher()
|
||||
@@ -306,12 +306,12 @@ function fetchIGTVPage(userID, after) {
|
||||
if (res.status === 429) throw constants.symbols.RATE_LIMITED
|
||||
}).then(g => g.json()).then(root => {
|
||||
/** @type {import("./types").PagedEdges<import("./types").TimelineEntryN2>} */
|
||||
const timeline = root.data.user.edge_owner_to_timeline_media
|
||||
history.report("timeline", true)
|
||||
const timeline = root.data.user.edge_felix_video_timeline
|
||||
history.report("igtv", true)
|
||||
return timeline
|
||||
}).catch(error => {
|
||||
if (error === constants.symbols.RATE_LIMITED) {
|
||||
history.report("timeline", false)
|
||||
history.report("igtv", false)
|
||||
}
|
||||
throw error
|
||||
})
|
||||
@@ -422,6 +422,7 @@ function fetchShortcodeData(shortcode) {
|
||||
|
||||
module.exports.fetchUser = fetchUser
|
||||
module.exports.fetchTimelinePage = fetchTimelinePage
|
||||
module.exports.fetchIGTVPage = fetchIGTVPage
|
||||
module.exports.getOrCreateShortcode = getOrCreateShortcode
|
||||
module.exports.fetchShortcodeData = fetchShortcodeData
|
||||
module.exports.userRequestCache = userRequestCache
|
||||
|
||||
@@ -12,8 +12,8 @@ class ReelUser extends BaseUser {
|
||||
this.posts = 0
|
||||
this.following = data.edge_follow ? data.edge_follow.count : 0
|
||||
this.followedBy = data.edge_followed_by ? data.edge_followed_by.count : 0
|
||||
/** @type {import("./Timeline")} */
|
||||
this.timeline = new Timeline(this)
|
||||
this.timeline = new Timeline(this, "timeline")
|
||||
this.igtv = new Timeline(this, "igtv")
|
||||
this.cachedAt = Date.now()
|
||||
this.computeProxyProfilePic()
|
||||
}
|
||||
|
||||
@@ -21,9 +21,12 @@ function transformEdges(edges) {
|
||||
class Timeline {
|
||||
/**
|
||||
* @param {import("./User")|import("./ReelUser")} user
|
||||
* @param {string} type
|
||||
*/
|
||||
constructor(user) {
|
||||
constructor(user, type) {
|
||||
this.user = user
|
||||
/** one of: "timeline", "igtv" */
|
||||
this.type = type
|
||||
/** @type {import("./TimelineEntry")[][]} */
|
||||
this.pages = []
|
||||
if (this.user.data.edge_owner_to_timeline_media) {
|
||||
@@ -32,12 +35,17 @@ class Timeline {
|
||||
}
|
||||
|
||||
hasNextPage() {
|
||||
return this.page_info.has_next_page
|
||||
return !this.page_info || this.page_info.has_next_page
|
||||
}
|
||||
|
||||
fetchNextPage() {
|
||||
if (!this.hasNextPage()) return constants.symbols.NO_MORE_PAGES
|
||||
return collectors.fetchTimelinePage(this.user.data.id, this.page_info.end_cursor).then(page => {
|
||||
const method =
|
||||
this.type === "timeline" ? collectors.fetchTimelinePage
|
||||
: this.type === "igtv" ? collectors.fetchIGTVPage
|
||||
: null
|
||||
const after = this.page_info ? this.page_info.end_cursor : ""
|
||||
return method(this.user.data.id, after).then(page => {
|
||||
this.addPage(page)
|
||||
return this.pages.slice(-1)[0]
|
||||
})
|
||||
|
||||
@@ -172,13 +172,23 @@ class TimelineEntry extends TimelineBaseMethods {
|
||||
config_height: found.config_height,
|
||||
src: proxyImage(found.src, found.config_width) // force resize to config rather than requested
|
||||
}
|
||||
} else if (this.data.thumbnail_src) {
|
||||
return {
|
||||
config_width: size, // probably?
|
||||
config_height: size,
|
||||
src: proxyImage(this.data.thumbnail_src, size) // force resize to requested
|
||||
}
|
||||
} else {
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
getThumbnailSizes() {
|
||||
return `(max-width: 820px) 200px, 260px` // from css :(
|
||||
if (this.data.thumbnail_resources) {
|
||||
return `(max-width: 820px) 200px, 260px` // from css :(
|
||||
} else {
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
async fetchChildren() {
|
||||
|
||||
@@ -13,7 +13,8 @@ class User extends BaseUser {
|
||||
this.following = data.edge_follow.count
|
||||
this.followedBy = data.edge_followed_by.count
|
||||
this.posts = data.edge_owner_to_timeline_media.count
|
||||
this.timeline = new Timeline(this)
|
||||
this.timeline = new Timeline(this, "timeline")
|
||||
this.igtv = new Timeline(this, "igtv")
|
||||
this.cachedAt = Date.now()
|
||||
this.computeProxyProfilePic()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user