UNPKG

newpipe-extractor-js

Version:
116 lines 3.19 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.NewPipe = void 0; class NewPipe { /** * Initialize NewPipe with a downloader */ static init(downloader) { NewPipe.downloader = downloader; } /** * Get the downloader instance */ static getDownloader() { if (!NewPipe.downloader) { throw new Error('NewPipe not initialized. Call NewPipe.init() first.'); } return NewPipe.downloader; } /** * Register a streaming service */ static registerService(service) { NewPipe.services.set(service.getServiceId(), service); } /** * Get a service by ID */ static getService(serviceId) { const service = NewPipe.services.get(serviceId); if (!service) { throw new Error(`Service with ID ${serviceId} not found`); } return service; } /** * Get a service by name */ static getServiceByName(serviceName) { for (const service of NewPipe.services.values()) { if (service.getServiceInfo().name.toLowerCase() === serviceName.toLowerCase()) { return service; } } throw new Error(`Service "${serviceName}" not found`); } /** * Get all registered services */ static getServices() { return Array.from(NewPipe.services.values()); } /** * Get the service that handles a given URL */ static getServiceByUrl(url) { for (const service of NewPipe.services.values()) { try { if (service.getLinkHandler()?.acceptUrl(url)) { return service; } } catch (e) { // Continue to next service } } throw new Error(`No service found for URL: ${url}`); } /** * Set the preferred localization */ static setPreferredLocalization(localization) { NewPipe.preferredLocalization = localization; } /** * Get the preferred localization */ static getPreferredLocalization() { return NewPipe.preferredLocalization; } /** * Set the preferred content country */ static setPreferredContentCountry(contentCountry) { NewPipe.preferredContentCountry = contentCountry; } /** * Get the preferred content country */ static getPreferredContentCountry() { return NewPipe.preferredContentCountry; } /** * Get version information */ static getVersion() { return '1.0.0'; // This would be populated from package.json } /** * Check if a URL is supported by any service */ static isUrlSupported(url) { try { NewPipe.getServiceByUrl(url); return true; } catch (e) { return false; } } } exports.NewPipe = NewPipe; NewPipe.services = new Map(); NewPipe.preferredLocalization = { languageCode: 'en', countryCode: 'US' }; NewPipe.preferredContentCountry = { languageCode: 'en', countryCode: 'US' }; //# sourceMappingURL=NewPipe.js.map