Overview
The NewPipe class is the main entry point for the NewPipe Extractor library. It provides static methods to initialize the library, access streaming services, and configure localization settings.
This class manages:
- Initialization with a Downloader instance
- Access to all supported streaming services
- Localization and content country preferences
- Service lookup by ID, name, or URL
Initialization
init()
Initialize NewPipe with a downloader instance.
The downloader implementation to use for HTTP requests
NewPipe.init(new DownloaderTestImpl());
init() with Localization
Initialize NewPipe with a downloader and localization.
The downloader implementation to use for HTTP requests
The preferred localization for content
NewPipe.init(new DownloaderTestImpl(), Localization.fromLocale(Locale.US));
init() with Localization and ContentCountry
Initialize NewPipe with full configuration.
The downloader implementation to use for HTTP requests
The preferred localization for content
The preferred content country
NewPipe.init(
new DownloaderTestImpl(),
new Localization("en", "US"),
new ContentCountry("US")
);
Service Access
getServices()
Get all supported streaming services.
A list of all available streaming services
List<StreamingService> services = NewPipe.getServices();
for (StreamingService service : services) {
System.out.println(service.getServiceInfo().getName());
}
getService() by ID
Get a specific streaming service by its ID.
The unique identifier of the service
The streaming service with the specified ID
If no service exists with the given ID
try {
StreamingService youtube = NewPipe.getService(0);
System.out.println(youtube.getServiceInfo().getName());
} catch (ExtractionException e) {
e.printStackTrace();
}
getService() by Name
Get a specific streaming service by its name.
The name of the service (e.g., “YouTube”, “SoundCloud”)
The streaming service with the specified name
If no service exists with the given name
try {
StreamingService youtube = NewPipe.getService("YouTube");
System.out.println("Service ID: " + youtube.getServiceId());
} catch (ExtractionException e) {
e.printStackTrace();
}
getServiceByUrl()
Determine which service can handle a given URL.
The streaming service that can handle the URL
If no service can handle the URL
try {
String url = "https://www.youtube.com/watch?v=dQw4w9WgXcQ";
StreamingService service = NewPipe.getServiceByUrl(url);
System.out.println("URL handled by: " + service.getServiceInfo().getName());
} catch (ExtractionException e) {
System.out.println("No service can handle this URL");
}
Downloader Management
getDownloader()
Get the currently configured downloader instance.
The active downloader instance
Downloader downloader = NewPipe.getDownloader();
Localization Configuration
setupLocalization()
Configure localization preferences.
The preferred localization
NewPipe.setupLocalization(new Localization("de", "DE"));
setupLocalization() with ContentCountry
Configure localization and content country preferences.
The preferred localization
thePreferredContentCountry
The preferred content country (nullable)
NewPipe.setupLocalization(
new Localization("fr", "FR"),
new ContentCountry("FR")
);
getPreferredLocalization()
Get the current preferred localization.
The current preferred localization, or DEFAULT if not set
Localization locale = NewPipe.getPreferredLocalization();
System.out.println("Language: " + locale.getLanguageCode());
setPreferredLocalization()
Set the preferred localization.
The new preferred localization
NewPipe.setPreferredLocalization(new Localization("es", "ES"));
getPreferredContentCountry()
Get the current preferred content country.
The current preferred content country, or DEFAULT if not set
ContentCountry country = NewPipe.getPreferredContentCountry();
System.out.println("Country: " + country.getCountryCode());
setPreferredContentCountry()
Set the preferred content country.
The new preferred content country
NewPipe.setPreferredContentCountry(new ContentCountry("GB"));
Usage Example
import org.schabi.newpipe.extractor.NewPipe;
import org.schabi.newpipe.extractor.StreamingService;
import org.schabi.newpipe.extractor.localization.Localization;
import org.schabi.newpipe.extractor.localization.ContentCountry;
public class Example {
public static void main(String[] args) {
// Initialize NewPipe
NewPipe.init(new DownloaderTestImpl());
// Configure localization
NewPipe.setupLocalization(
new Localization("en", "US"),
new ContentCountry("US")
);
try {
// Get a service by URL
String videoUrl = "https://www.youtube.com/watch?v=dQw4w9WgXcQ";
StreamingService service = NewPipe.getServiceByUrl(videoUrl);
// Get stream extractor
StreamExtractor extractor = service.getStreamExtractor(videoUrl);
extractor.fetchPage();
System.out.println("Title: " + extractor.getName());
} catch (Exception e) {
e.printStackTrace();
}
}
}