/node-ytas

NOTE: Due to Youtube API v2 no longer working, this is broken. This is only still up because it was my first project at 13yo. YouTube video to audio stream with seeking

Primary LanguageJavaScriptGNU General Public License v2.0GPL-2.0

#YTAS - YouTube Audio Streamer

This is a node.js script that uses youtube-dl, request, through2 and liquid-ffmpeg modules to stream audio straight from a video.

On a side note, YTAS will also work with the fluent-ffmpeg module, but liquid-ffmpeg takes up less space and seemingly less memory. To switch to fluent, just change the var ffmpeg = require('liquid-ffmpeg'); to var ffmpeg = require('fluent-ffmpeg'); . Make sure to also npm install fluent-ffmpeg (and, if you want, npm uninstall liquid-ffmpeg)!

Speaking of things this could work with, one could also use the ytdl-core node module, but it fails when downloading copyrighted things like music. You could use similar steps as the instructions above.

First, change

var ytdl = require('youtube-dl');

in server.js to

var ytdl = require('ytdl-core');

then run:

npm install ytdl-core
npm uninstall youtube-dl

To start the server, simply run one of two commands:

npm start or node server.js

They're both exactly the same, so I guess you can just choose arbitrarily.

Then, all you have to do is navigate to this URL in any browser that is not Safari. (TODO: Add Safari seeking support)

http://localhost:3000/?i=youtube video ID here&s=0 or 1 to toggle seeking

NOTE: If the "seeking" parameter is not filled in, it will default to true.

This will return your stream. You can also change the bitrate in the options.json file.

If seeking is true, this application will use the bitrate and the duration (from YouTube API v2) to get the full length of the audio file in bytes, which allows the video stream to support seeking in most browsers, but Safari seems to ignore the HTTP status.

For a demo, you can look at http://ytas-demo.herokuapp.com/?i=sN36JM8l52g. You can also change the "i" parameter or set the "s" parameter if you want.

#Installation Installation is fairly simple. Just download or clone all the files into a folder anywhere. Make sure you have both node and npm installed. If you are unsure, run the command which node and then which npm. If you get something like /usr/local/bin/node, it is installed. If a blank line comes up and then it prompts you to write a new command, node is not installed. Simply go to http://www.nodejs.org and install it from there.

After node and npm are installed, navigate to the directory YTAS was saved to using the cd command. Run:

npm install

If you do not get a bunch of lines that say npm ERR!, you're good. Run one of the starting commands above and you're set!

#Changelog

0.0.1

Added option to enable or disable seeking