Reputation: 331
I'm going to play YouTube and Vimeo videos using React-Native. For now I implemented React-Native-Video and it does not support to play YouTube or Vimeo urls while can play direct video urls. So I just want to get a direct reference to a file (or a stream?) from YouTube Video URL. e.g from
https://www.youtube.com/watch?v=PCwL3-hkKrg
Is there any good third party services or websites to solve this problem? No matter what types of code or ways you will use though I'm using React-Native to play YouTube videos currently.
Upvotes: 4
Views: 17445
Reputation: 410
You can obtain video urls of YouTube by this code:
// ES6 version
const videoUrls = ytplayer.config.args.adaptive_fmts
.split(',')
.map(item => item
.split('&')
.reduce((prev, curr) => (curr = curr.split('='),
Object.assign(prev, {[curr[0]]: decodeURIComponent(curr[1])})
), {})
)
.reduce((prev, curr) => Object.assign(prev, {
[curr.quality_label || curr.type]: curr
}), {});
console.log(videoUrls);
// ES5 version
var videoUrls = ytplayer.config.args.adaptive_fmts
.split(',')
.map(function (item) {
return item
.split('&')
.reduce(function (prev, curr) {
curr = curr.split('=');
return Object.assign(prev, {[curr[0]]: decodeURIComponent(curr[1])})
}, {});
})
.reduce(function (prev, curr) {
return Object.assign(prev, {
[curr.quality_label || curr.type]: curr
});
}, {});
console.log(videoUrls);
Upvotes: 2
Reputation: 331
Finally, I was able to get youtube video file reference url from KeepVid website.
Because I don't think the website supports restful api, I fetched its html content and parsed to get download urls. I didn't write code here as it is very simple. I would be glad if it helped you.
Upvotes: 2
Reputation: 1
I can understand what you want - downloading or playing a video[stream] from URL of Youtube or Vimeo.
The only possible way is to use WebView since it's not possible to get the link to the regarding file (not "direct url") of Vimeo nor YouTube for playing (maybe possible for downloading).
If you have to compose customized control, e.g. with your own SeekBar or buttons, ... then you can implement it by combining with WebView control, right? I don't expect this will be much trouble to implement.
Upvotes: 0