matjaz/homey-youtube

Prevent using external download-service

Opened this issue · 9 comments

https://stackoverflow.com/a/45375023
Try to use a direct stream URL first?

https://github.com/rg3/youtube-dl/blob/master/youtube_dl/extractor/youtube.py
get the info for a file and see if there's an audio-file:
youtube-dl -f bestaudio "https://www.youtube.com/watch?t=4&v=-cqXcHcF_A4"

youtube-dl -F "https://www.youtube.com/watch?t=4&v=z9pr22fnZKk"
[youtube] z9pr22fnZKk: Downloading webpage
[youtube] z9pr22fnZKk: Downloading video info webpage
[youtube] z9pr22fnZKk: Extracting video information
WARNING: unable to extract uploader nickname
[youtube] z9pr22fnZKk: Downloading MPD manifest
[info] Available formats for z9pr22fnZKk:
format code extension resolution note
139 m4a audio only DASH audio 56k , m4a_dash container, mp4a.40.5@ 48k (22050Hz)
249 webm audio only DASH audio 62k , opus @ 50k, 43.46MiB
250 webm audio only DASH audio 76k , opus @ 70k, 54.89MiB
171 webm audio only DASH audio 108k , vorbis@128k, 87.63MiB
251 webm audio only DASH audio 130k , opus @160k, 99.15MiB
140 m4a audio only DASH audio 135k , m4a_dash container, mp4a.40.2@128k (44100Hz)
160 mp4 256x144 DASH video 115k , avc1.4d400c, 25fps, video only
278 webm 256x144 144p 163k , webm container, vp9, 25fps, video only, 86.47MiB
133 mp4 426x240 DASH video 290k , avc1.4d4015, 25fps, video only
242 webm 426x240 240p 337k , vp9, 25fps, video only, 150.34MiB
243 webm 640x360 360p 620k , vp9, 25fps, video only, 280.17MiB
134 mp4 640x360 DASH video 652k , avc1.4d401e, 25fps, video only
244 webm 854x480 480p 1133k , vp9, 25fps, video only, 483.39MiB
135 mp4 854x480 DASH video 1291k , avc1.4d401e, 25fps, video only
247 webm 1280x720 720p 2127k , vp9, 25fps, video only, 955.19MiB
136 mp4 1280x720 DASH video 2582k , avc1.4d401f, 25fps, video only
248 webm 1920x1080 1080p 3650k , vp9, 25fps, video only, 1.71GiB
137 mp4 1920x1080 DASH video 4445k , avc1.640028, 25fps, video only
17 3gp 176x144 small , mp4v.20.3, mp4a.40.2@ 24k
36 3gp 320x180 small , mp4v.20.3, mp4a.40.2
43 webm 640x360 medium , vp8.0, vorbis@128k
18 mp4 640x360 medium , avc1.42001E, mp4a.40.2@ 96k
22 mp4 1280x720 hd720 , avc1.64001F, mp4a.40.2@192k (best)

And another one:
youtube-dl -F "https://www.youtube.com/watch?t=4&v=-cqXcHcF_A4"
[youtube] -cqXcHcF_A4: Downloading webpage
[youtube] -cqXcHcF_A4: Downloading video info webpage
[youtube] -cqXcHcF_A4: Extracting video information
WARNING: unable to extract uploader nickname
[youtube] -cqXcHcF_A4: Downloading MPD manifest
[info] Available formats for -cqXcHcF_A4:
format code extension resolution note
139 m4a audio only DASH audio 53k , m4a_dash container, mp4a.40.5@ 48k (22050Hz)
249 webm audio only DASH audio 62k , opus @ 50k, 29.67MiB
250 webm audio only DASH audio 81k , opus @ 70k, 38.76MiB
140 m4a audio only DASH audio 132k , m4a_dash container, mp4a.40.2@128k (44100Hz)
171 webm audio only DASH audio 144k , vorbis@128k, 68.33MiB
251 webm audio only DASH audio 150k , opus @160k, 76.67MiB
160 mp4 256x144 DASH video 115k , avc1.4d400c, 30fps, video only
278 webm 256x144 144p 139k , webm container, vp9, 30fps, video only, 56.72MiB
133 mp4 426x240 DASH video 267k , avc1.4d4015, 30fps, video only
242 webm 426x240 240p 316k , vp9, 30fps, video only, 124.71MiB
243 webm 640x360 360p 567k , vp9, 30fps, video only, 232.27MiB
134 mp4 640x360 DASH video 646k , avc1.4d401e, 30fps, video only
244 webm 854x480 480p 1009k , vp9, 30fps, video only, 419.75MiB
135 mp4 854x480 DASH video 1186k , avc1.4d401f, 30fps, video only
247 webm 1280x720 720p 2003k , vp9, 30fps, video only, 846.50MiB
136 mp4 1280x720 DASH video 2403k , avc1.4d401f, 30fps, video only
17 3gp 176x144 small , mp4v.20.3, mp4a.40.2@ 24k
36 3gp 320x180 small , mp4v.20.3, mp4a.40.2
43 webm 640x360 medium , vp8.0, vorbis@128k
18 mp4 640x360 medium , avc1.42001E, mp4a.40.2@ 96k
22 mp4 1280x720 hd720 , avc1.64001F, mp4a.40.2@192k (best)

Mmm, getting vorbis, opus or m4a to stream is going to be hard withour ffmpeg...

Homey supports following codecs: mp3, ogg, flac. https://apps.developer.athom.com/tutorial-Media-Codecs.html
There is no option to use ffmpeg on Homey, so transcoding should be done on some other device or in pure JS, which Homey is resource limited.
So IMO no easy option.

transcoding in pure js, didn't know that was possible 👍
https://github.com/sopel39/audioconverter.js
from: http://karolsobczak.com/?p=133
worth some testing....

Currently I'm in a process of rewriting app using Homey SDK 2 and oAuth.
Please feel free to make standalone POC of Homey audio conversion app. (from youtube to playback directly on Homey).

Don't feel like I'm rushing you ;-) Using this bug to gather research for better youtube-audio support in Homey...

I don't see a format which is directly supported in Homey. Vorbis is in webm container.
I've managed to download youtube video using ytdl-core, convert it using audioconverter.js and play it in media manager using local streaming server.
But in order to do that I needed to tweak pure js ffmpeg and create local streaming server.
So technically it's possible, but practically it's not for realtime "search youtube and play" use case, because Homey is just to slow. It took me around 5 mins, to convert 3:26 video, while I received many cpuwarns.
So maybe to create a pre defined list from YouTube and convert videos to mp3 and later play, it would be possible (but limited to disk space).
Another option is to move transcoding to more powerful machine (server, nas, raspberry)