youtube quality generator for capacitor android ionic 4
npm install youtube-quality-generator-devash
npm i youtube-quality-generator-deva
npx cap sync android
`
Create a service and import the plugin. I have also included a regex to take embed code or short link and convert it to full url by extracting the id. It should look like this =>
`sh
import {Injectable} from '@angular/core';
import {Plugins} from '@capacitor/core';
import 'youtube-quality-generator';
const {DevaYoutubeGenerator} = Plugins;
@Injectable()
export class YoutubeExtractService {
convertedData: any;
constructor() {
}
async getDataFromVideo(video: { link: string, isLive: boolean }) {
console.log(video);
const regExp = /^.((youtu.be\/)|(v\/)|(\/u\/\w\/)|(embed\/)|(watch\?))\??v?=?([^#\&\?]).*/;
const match = video.link.match(regExp);
if (match && match[7].length === 11) {
console.log(match[7]);
video.link = http://www.youtube.com/watch?v=${match[7]};
} else {
alert('Could not extract video ID.');
}
try {
const res = await DevaYoutubeGenerator.getDataFromLink(video);
console.log('line 27:', res);
console.log('line 28', JSON.stringify(res));
console.log('line 29', res['data']);
window.alert(res['data']);
this.convertedData = res['data'];
} catch (e) {
console.log(e);
} finally {
/ your logic for data modelling and sending it to video player*/
}
}
}
``