Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New process to upload a broadcast replay to IGTV #1364

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

omouren
Copy link

@omouren omouren commented Jan 31, 2021

The broadcast replay to IGTV has changed in the app, the endpoint "/api/v1/live/add_post_live_to_igtv/" no longer exists
#1304

let data = await ig.live.getPostLiveThumbnails(broadcast_id)

// Download any thumb
let file = await new Promise((resolve) => https.get(data.thumbnails[0], (download) => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here you could use request-promise as it's already a dependency of this library.

Comment on lines 91 to 116
let igtv = null
let currentRetry = 0
let maxRetry = 3
let retryDelay = 4
while (!igtv) {
// This endpoint can return an error "202 Accepted; Transcode not finished yet" if Instagram has not finished to process the previous upload, so retry later in this case
try {
igtv = await ig.media.configureToIgtv({
upload_id: upload.upload_id,
title: 'A title',
caption: 'A description',
igtv_share_preview_to_feed: '1',
})

console.log(`Live posted to IGTV : ${igtv.upload_id}`))
} catch (e) {
currentRetry++
if (currentRetry > maxRetry) {
throw e
} else {
await (new Promise(resolve => {
setTimeout(resolve, currentRetry * retryDelay)
}))
}
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could live in its own function and not pollute the current function.

For example:

async function retryDelayed<T>(fn: () => Promise<T>, retryOptions: { retries: number, delayMs: number }): Promise<T> {
  let step = 0;
  while(step++ < retryOptions.retries) {
    try {
      return await fn();
    } catch(e) {
      if(step >= retryOptions.retries) throw e;
      
      await new Promise(r => setTimeout(r, step * retryOptions.delayMs));
    }
  }
}

//  used like this:
const user = await retryDelayed(() => ig.user.info(123), {retries: 2, delayMs: 2 * 1000 /* 2s */ });

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the tips @Nerixyz .
But before doing this... I really can't understand, it's not working anymore. I made and tested this PR yesterday, and today, I got a 500 error with the endpoint "/api/v1/media/configure_to_igtv/".
I think that there is a problem with my picture upload because if I use in the configureToIgtv method an existing "upload_id" (that I get from the app directly, so i'm bypassing the "download, convert and upload thumb for broadcast" step), it works.
If you have any idea... You're welcome!

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

content/site-policy/content-removal-policies/github-private-information-removal-policy.md

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the tips @Nerixyz .
But before doing this... I really can't understand, it's not working anymore. I made and tested this PR yesterday, and today, I got a 500 error with the endpoint "/api/v1/media/configure_to_igtv/".
I think that there is a problem with my picture upload because if I use in the configureToIgtv method an existing "upload_id" (that I get from the app directly, so i'm bypassing the "download, convert and upload thumb for broadcast" step), it works.
If you have any idea... You're welcome!

@omouren omouren force-pushed the hotfix/new-post-live-to-igtv branch from fb238a8 to 774885a Compare February 3, 2021 20:01
@omouren
Copy link
Author

omouren commented Feb 3, 2021

I moved the retry step in case of a "202 Accepted; Transcode not finished yet" to the repository with an optional parameter on the configureToIgtv method to set the retry delay.
I updated my example to make it simplier. I used Axios HTTP client to download thumb because I am used to work with it and I think that it's a good client, and because request-promise is now deprecated.

I didn't found why certain of my broadcast can't be uploaded as an IGTV and still get an 500 error... My update works with new broadcasts.

@omouren omouren force-pushed the hotfix/new-post-live-to-igtv branch from 774885a to 671f8da Compare February 3, 2021 20:13
@omouren omouren requested a review from Nerixyz February 3, 2021 20:14
@Nerixyz
Copy link
Collaborator

Nerixyz commented Feb 3, 2021

because I am used to work with it and I think that it's a good client, and because request-promise is now deprecated.

It's probably still the best to stick to request. We know request is deprecated now and probably the best alternative would be got. But that'd be a huge refactoring (It's already done in V2).

Copy link
Collaborator

@Nerixyz Nerixyz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if this may introduce an infinite loop as Instagram may always send 202. But I don't think they'd do this; after a while we'd probably get a spam-error or 500.

});

let body = null;
let response = null;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This variable doesn't need to be here. It can live in the while body.

@omouren
Copy link
Author

omouren commented Feb 4, 2021

because I am used to work with it and I think that it's a good client, and because request-promise is now deprecated.

It's probably still the best to stick to request. We know request is deprecated now and probably the best alternative would be got. But that'd be a huge refactoring (It's already done in V2).

Yes I know, but I took the liberty of choosing an other HTTP client because it's just an example file and not part of the library.

@omouren omouren force-pushed the hotfix/new-post-live-to-igtv branch from 785ccb5 to 351a3a8 Compare February 5, 2021 21:27
@omouren omouren force-pushed the hotfix/new-post-live-to-igtv branch from 351a3a8 to 2fedb9a Compare February 5, 2021 21:29
@omouren
Copy link
Author

omouren commented Feb 5, 2021

Updated to use the publish service

@Nesslax
Copy link

Nesslax commented Jun 25, 2021

Hello guys
any news about this PR ?

@ctle-vn
Copy link

ctle-vn commented Oct 25, 2021

Is this PR going to be merged? I believe this issue still persists.

@FALA00
Copy link

FALA00 commented Feb 12, 2023

Thanks for the tips @Nerixyz .
But before doing this... I really can't understand, it's not working anymore. I made and tested this PR yesterday, and today, I got a 500 error with the endpoint "/api/v1/media/configure_to_igtv/".
I think that there is a problem with my picture upload because if I use in the configureToIgtv method an existing "upload_id" (that I get from the app directly, so i'm bypassing the "download, convert and upload thumb for broadcast" step), it works.
If you have any idea... You're welcome!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants