/** * @deprecated The method should not be used */ private async prepareSourceStream(url: string): Promise { const Buffer = require('buffer').Buffer; const { originURL, cacheKey: prepareCacheKey } = getCacheKey( url, this.cacheFolder, KEY_PREFIX ); // download INDEPENDENT-SEGMENTS // download first SEGMENT // download MEDIA-SEQUENCE of SEGMENT // ignore download to file system // manually write it by cache provider try { // start download const httpRequest = this.sessionTask.dataTask(originURL.href, {}); // mark it as downloading this.cachingUrl[originURL.href] = httpRequest; const { data } = await httpRequest; const newTextData: string[] = Buffer.from(data, 'base64') .toString('utf8') .split('\n'); const scheme = originURL.protocol; const host = originURL.host; const firstPlaylist = newTextData.find((line) => line.endsWith('.m3u8')); const firstSegment = newTextData.find((line) => line.endsWith('.ts')); // manually write // this.cache.write(originURL.href, data); // prepare next download if (firstPlaylist) { const playlist = `${scheme}//${host}${pathReplaceLast( originURL.href, firstPlaylist )}`; // caching playlist only this.delegate?.onCachingPlaylistSource( originURL.href, data, this.cacheFolder ); // ignore segment cache file response // const resolutionPlaylist = await this.prepareSourceStream(playlist); } else if (firstSegment) { // ignore all media sequence cache file response const allMediaSequence = newTextData .filter((line) => line.includes('.ts')) .map( (line) => `${scheme}//${host}${pathReplaceLast(originURL.href, line)}` ); // const segments = await Promise.all( allMediaSequence.map((sequenceUrl) => this.prepareSourceStream(sequenceUrl) ) ); } // ignore ts cache key for downloaded ts file and segment m3u8 // if (prepareCacheKey.endsWith('.ts') || firstSegment) { // return ''; // } // return root m3u8 cache file if (this.errorCachingList[originURL.href]) { delete this.errorCachingList[originURL.href]; } return prepareCacheKey; } catch (error) { this.errorCachingList[originURL.href] = prepareCacheKey; throw error; // throw error; } finally { delete this.cachingUrl[originURL.href]; } }