nicholastay / node-twitch-get-stream

Gets the m3u8 direct stream URLs of a live stream on twitch.tv.
MIT License
48 stars 26 forks source link

After sometime it stop returning #5

Closed anonym24 closed 6 years ago

anonym24 commented 6 years ago

When I run node main.js:

var twitchStreams = require('twitch-get-stream')('*(*******-my-cliend-id******');
twitchStreams.get('inexpensivegamer')
.then(function(streams) {
    console.log(streams);
});

it would return streams (print them to Ubuntu terminal console)

but after sometimes it doesn't print anything (doesn't return anything?)

what could be a problem here?

nicholastay commented 6 years ago

We are using Promises here, and it looks like you aren't catching the errors, so maybe they're being silently dropped. Maybe try tacking on and see how it goes:

.catch(console.error);
anonym24 commented 6 years ago

It was because of https. Originally we have http in js file:

var getAccessToken = function(channel) {
  // Get access token
  return new Promise(function(resolve, reject) {
    request
      .get('http://api.twitch.tv/api/channels/' + channel + '/access_token')
      .set({ 'Client-ID': clid })
      .end(function(err, res) {
        if (err) return reject(err);
        if (!res.ok) return reject(new Error('Could not access the twitch API to get the access token, maybe your internet or twitch is down.'));

        return resolve(res.body);
      });
  });
}

var getPlaylist = function(channel, accessToken) {
  // Get the playlist with given access token data (parsed /access_token response)
  return new Promise(function(resolve, reject) {
    request
      .get('http://usher.twitch.tv/api/channel/hls/' + channel + '.m3u8')

It works ok on Ubuntu with node (and it doesn't work with https)

But with Chrome extension and Twitch channel page opened it requires https (doesn't wok with http)

nicholastay commented 6 years ago

Interesting. This project was designed originally for node as the repo name suggests so I didn't have browser support in mind, but as I have hinted to I may look into that in the future if it is feasible.