mirror of
https://github.com/YuzuZensai/play-dl-test.git
synced 2026-01-31 14:58:05 +00:00
Docs + Pretty code
This commit is contained in:
@@ -23,7 +23,7 @@ export class LiveStreaming {
|
||||
private segments_urls: string[];
|
||||
private request: IncomingMessage | null;
|
||||
constructor(dash_url: string, target_interval: number, video_url: string) {
|
||||
this.stream = new Readable({ highWaterMark: 10 * 1000 * 1000, read(){} });
|
||||
this.stream = new Readable({ highWaterMark: 10 * 1000 * 1000, read() {} });
|
||||
this.type = StreamType.Arbitrary;
|
||||
this.url = dash_url;
|
||||
this.base_url = '';
|
||||
@@ -102,8 +102,8 @@ export class LiveStreaming {
|
||||
}
|
||||
this.request = stream;
|
||||
stream.on('data', (c) => {
|
||||
this.stream.push(c)
|
||||
})
|
||||
this.stream.push(c);
|
||||
});
|
||||
stream.on('end', () => {
|
||||
this.packet_count++;
|
||||
resolve('');
|
||||
@@ -143,7 +143,7 @@ export class Stream {
|
||||
video_url: string,
|
||||
options: StreamOptions
|
||||
) {
|
||||
this.stream = new Readable({ highWaterMark : 10 * 1000 * 1000, read(){} });
|
||||
this.stream = new Readable({ highWaterMark: 10 * 1000 * 1000, read() {} });
|
||||
this.url = url;
|
||||
this.quality = options.quality as number;
|
||||
this.proxy = options.proxy || undefined;
|
||||
@@ -204,8 +204,8 @@ export class Stream {
|
||||
}
|
||||
this.request = stream;
|
||||
stream.on('data', (c) => {
|
||||
this.stream.push(c)
|
||||
})
|
||||
this.stream.push(c);
|
||||
});
|
||||
|
||||
stream.once('error', async (err) => {
|
||||
this.cleanup();
|
||||
|
||||
@@ -3,12 +3,12 @@ import fs from 'fs';
|
||||
let youtubeData: youtubeDataOptions;
|
||||
if (fs.existsSync('.data/youtube.data')) {
|
||||
youtubeData = JSON.parse(fs.readFileSync('.data/youtube.data').toString());
|
||||
youtubeData.file = true
|
||||
youtubeData.file = true;
|
||||
}
|
||||
|
||||
interface youtubeDataOptions {
|
||||
cookie?: Object;
|
||||
file? : boolean;
|
||||
file?: boolean;
|
||||
}
|
||||
|
||||
export function getCookies(): undefined | string {
|
||||
@@ -29,11 +29,12 @@ export function setCookie(key: string, value: string): boolean {
|
||||
}
|
||||
|
||||
export function uploadCookie() {
|
||||
if (youtubeData.cookie && youtubeData.file) fs.writeFileSync('.data/youtube.data', JSON.stringify(youtubeData, undefined, 4));
|
||||
if (youtubeData.cookie && youtubeData.file)
|
||||
fs.writeFileSync('.data/youtube.data', JSON.stringify(youtubeData, undefined, 4));
|
||||
}
|
||||
|
||||
export function setCookieToken(options : { cookie : string }){
|
||||
let cook = options.cookie
|
||||
export function setCookieToken(options: { cookie: string }) {
|
||||
let cook = options.cookie;
|
||||
let cookie: Object = {};
|
||||
cook.split(';').forEach((x) => {
|
||||
const arr = x.split('=');
|
||||
@@ -42,6 +43,6 @@ export function setCookieToken(options : { cookie : string }){
|
||||
const value = arr.join('=').trim();
|
||||
Object.assign(cookie, { [key]: value });
|
||||
});
|
||||
youtubeData = { cookie }
|
||||
youtubeData.file = false
|
||||
}
|
||||
youtubeData = { cookie };
|
||||
youtubeData.file = false;
|
||||
}
|
||||
|
||||
@@ -30,7 +30,8 @@ export function yt_validate(url: string): 'playlist' | 'video' | 'search' | fals
|
||||
if (url.match(video_pattern)) {
|
||||
let id: string;
|
||||
if (url.includes('youtu.be/')) id = url.split('youtu.be/')[1].split(/(\?|\/|&)/)[0];
|
||||
else if (url.includes('youtube.com/embed/')) id = url.split('youtube.com/embed/')[1].split(/(\?|\/|&)/)[0];
|
||||
else if (url.includes('youtube.com/embed/'))
|
||||
id = url.split('youtube.com/embed/')[1].split(/(\?|\/|&)/)[0];
|
||||
else id = url.split('watch?v=')[1].split(/(\?|\/|&)/)[0];
|
||||
if (id.match(video_id_pattern)) return 'video';
|
||||
else return false;
|
||||
@@ -57,7 +58,8 @@ export function extractID(url: string): string {
|
||||
if (url.indexOf('list=') === -1) {
|
||||
let video_id: string;
|
||||
if (url.includes('youtu.be/')) video_id = url.split('youtu.be/')[1].split(/(\?|\/|&)/)[0];
|
||||
else if (url.includes('youtube.com/embed/')) video_id = url.split('youtube.com/embed/')[1].split(/(\?|\/|&)/)[0];
|
||||
else if (url.includes('youtube.com/embed/'))
|
||||
video_id = url.split('youtube.com/embed/')[1].split(/(\?|\/|&)/)[0];
|
||||
else video_id = url.split('watch?v=')[1].split(/(\?|\/|&)/)[0];
|
||||
return video_id;
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user