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

YouTube #48

Open
ghost opened this issue Mar 3, 2016 · 18 comments
Open

YouTube #48

ghost opened this issue Mar 3, 2016 · 18 comments

Comments

@ghost
Copy link

ghost commented Mar 3, 2016

Moggio appears to be similar to Raddit:

http://reddit.com/r/radd_it

In that it can play from multiple streaming sources. However Moggio has the glaring omission of YouTube support. I see YouTube mentioned in #16, but you closed without comment?

@ghost ghost mentioned this issue Mar 3, 2016
Closed
9 tasks
@maddyblue
Copy link
Owner

I would love youtube support. I have already done some work on it: https://github.com/mjibson/moggio/tree/youtube

The difficulty is that we have to extract the audio from a video file. Youtube supports webm files, which are mkv files. There are a few go projects to sort-of decode them. You can see my work off of those in the linked branch. From there we can extract a Vorbis (not Ogg-encapsulated, though) file. However the ogg vorbis decoder that moggio uses is written in C and currently only decodes Ogg Vorbis files. So we'd have to create an ogg vorbis from the vorbis and feed it to that.

The youtube branch is currently missing two parts: 1) the extraction of the actual data bytes of the vorbis file frames (it currently has just one level above that, so I think it's really close), and 2) creating ogg vorbis from vorbis. I don't think either of these are too complicated, but I don't have expertise in this area and it's not obvious to me what the next parts are. I'll try again at some point. But yes, I really want this. Youtube is the only music source I use that moggio doesn't support.

@ghost
Copy link
Author

ghost commented Mar 3, 2016

YouTube has DASH audio only streams, why not utilize those? See
"Comparison of YouTube media encoding options" table on this page:

http://wikipedia.org/wiki/YouTube#Quality_and_formats

@maddyblue
Copy link
Owner

DASH would be nice. I'm not sure how hard it would be. I don't see any Go packages for it.

@ghost
Copy link
Author

ghost commented Mar 3, 2016

I guess I dont understand what Moggio actually does. Wouldnt it be easier just to do something like this:

<iframe src="http://youtube.com/embed/<videoId>?autoplay=1"></iframe>

@maddyblue
Copy link
Owner

The moggio web interface is just a controller for the server. You don't need to have a browser open at all to use moggio. The server is what streams and plays the music, and it's all Go.

@ghost
Copy link
Author

ghost commented Mar 3, 2016

That still doesnt make sense. YouTube is a streaming site. Sure, there are tool out there to download audio/video from YouTube, but why do that? Why wait for an entire song to download when you could easily stream it using an iframe like above?

@maddyblue
Copy link
Owner

iframes are a browser thing. You can use moggio without ever opening a web browser. The browser does not play the music. moggio is a program that streams music to the sound system itself. You can use a browser to tell moggio what do to, but the browser is not the thing streaming the music.

@ghost
Copy link
Author

ghost commented Mar 3, 2016

Yeah, but how the hell are you going to steam YouTube? As far as I know the only "API" for this is using an iframe, which yes, requires a browser. Failing that any solution will require fully downloading the file before playing. The only other thing that comes to mind is FFmpeg "http://" protocol, which who knows if that is possible in Golang

@maddyblue
Copy link
Owner

Look at my youtube branch and https://godoc.org/github.com/otium/ytdl. You can get a URL, make a web request, then stream the resp.Body into some decoders. moggio already does this with, for example, mp3s hosted on dropbox or google drive. No need to download the whole file first, can just stream and decode as needed.

@ghost
Copy link
Author

ghost commented Mar 3, 2016

Ok then. Well if you need help pull DASH URLs, I can do this. I know how to access them, and have code for it in JavaScript already. I could port it to Golang, or send you the algo so you could do it

Check that, it looks like Otium does this already?

best-audio

http://github.com/otium/ytdl#options

@maddyblue
Copy link
Owner

The last time I looked at that it wasn't clear to me how to just get a mp3 or vorbis stream. I would love having a Go library that can get me DASH URL if they can indeed provide audio-only streams. Where's your JS library in the mean time?

@ghost
Copy link
Author

ghost commented Mar 3, 2016

You might want to drop the idea of MP3/Vorbis sir. YouTube is LARGELY AAC, so you are going to
need an AAC decoder if you dont have it already. Consider this video upload by YouTube themself:

http://youtube.com/watch?v=WeYVLG1bsV0

Here are the available streams:

128k AAC
720p H.264 192k AAC
360p H.264 96k AAC
240p MPEG-4 36k AAC
144p MPEG-4 24k AAC
360p VP8 128k Vorbis
240p H.263 64k MP3
1080p H.264
720p H.264
480p H.264
360p H.264
240p H.264
144p H.264

Notice carefully the only "audio only" stream is:

128k AAC

So if you want to dutifully stick to MP3/Vorbis you will need to stream a
video/audio file, or download a video/audio file and extract the audio. Here is my work, note it is not a library per se, but it could push you in the right direction:

http://github.com/svnpenn/bm/blob/gh-pages/yt-dl.js

@maddyblue
Copy link
Owner

I have looked but not found anything I could use to decode AAC from Go, including C libraries. I'm OK using C for AAC decoding for now, but it would need to be a self-contained package like the vorbis package is (https://github.com/mccoyst/vorbis). Hence the desire to use the webm format and extract the vorbis audio out of it, because moggio can decode ogg vorbis already.

@ghost
Copy link
Author

ghost commented Mar 3, 2016

I use FDK-AAC library in my FFmpeg builds:

http://github.com/mstorsjo/fdk-aac

It is C++, but might work for your needs?

@maddyblue
Copy link
Owner

Yes, that may work. Will experiment.

@JalonSolov
Copy link

@mvpmvh
Copy link

mvpmvh commented Nov 11, 2020

I'm looking to do exactly what this repo is doing: building a go-only media player. I specifically want to build a media player that streams audio directly from YouTube. Is your branch workable? Did you end up finding another workable solution?

@maddyblue
Copy link
Owner

I was never able to stream audio from youtube, but it's been years since I've tried. If I were to try again today I'd look into the youtube music API (well, the unofficial API), probably starting with the python project.

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

No branches or pull requests

3 participants