fent / node-ytdl-core

YouTube video downloader in javascript.
MIT License
4.52k stars 799 forks source link

play live videos #166

Closed YinglunQ closed 7 years ago

YinglunQ commented 7 years ago

Hi, I am wondering if ytdl-core can play any live videos? I try to do it with this video https://www.youtube.com/watch?v=1-AODuJpCG4 and it played only for like 1 second and then nothing else is playing. Thanks!

fent commented 7 years ago

Yes, it should be able to play it. And it works for me when I try it.

How are you calling ytdl-core?

YinglunQ commented 7 years ago

I am using ytdl-core in an discord bot program. And I call it using something like this: let stream = ytdl(songId, {filter : 'audioonly'}); let dispatcher = voiceConnection.playStream(stream);

fent commented 7 years ago

The audioonly filters gets the highest quality, which may not always be the "live" version. Itags 91 through 95 are for live streaming.

YinglunQ commented 7 years ago

ohh i see. Thank you so much for the info! And thank you for making ytdl-core! :DDD

YinglunQ commented 7 years ago

Hi fent, I have a problem resuming live videos and wondering if you have any insights on this.

I first play the live video using let dispatcher = connection.playStream(liveStream), and then I pause it using dispatcher.pause(). After pausing around 5 minutes, I resume it using dispatcher.resume(), and the dispatcher just ends with reason undefined.

I am not too sure if it's a discord.js or ytdl-core problem, so I also asked the same question in discord.js, and @iCrawl has suggested livestreams had some issues before, and wondered maybe you have some insights on this. Thanks!

fent commented 7 years ago

YouTube does not allow you to pause a live video. If you go to a live video page, you'll notice that there is no pause option, there's a stop option instead. This sounds fine, as it doesn't make sense to be able to pause a live video.

There are services like Twitch that allow you to pause live playback. But sometimes, if you pause for too long, it'll start streaming the latest live portion anyway.

YinglunQ commented 7 years ago

ahh i see. Thanks for the info again! :D

Rainbowdashboygamer commented 6 years ago

if (prefix + "play") { const voiceChannel = message.member.voiceChannel; if (!voiceChannel) { } voiceChannel.join().then(connection => { let stream = yt(args.join(" "), { audioonly: true }); yt.getInfo(args.join(" "), function(err, info) { const title = info.title; console.log(${message.author.username}, Queued the song '${title}.'); message.channel.sendMessage(\${title}``); }); const dispatcher = connection.playStream(stream); dispatcher .on("end", () => { voiceChannel.leave(); var channel = message.member.voiceChannel;

        if (!message.guild.voiceConnection) channel
            .join()
            .then(function(connection) {
              play(connection, message);
            }); 
            console.error(Error);
            const video= ('ytdl') 

     });
  });
}          

});