Skip to main content

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.
d
Downloader
required
The downloader implementation to use for HTTP requests
NewPipe.init(new DownloaderTestImpl());

init() with Localization

Initialize NewPipe with a downloader and localization.
d
Downloader
required
The downloader implementation to use for HTTP requests
l
Localization
required
The preferred localization for content
NewPipe.init(new DownloaderTestImpl(), Localization.fromLocale(Locale.US));

init() with Localization and ContentCountry

Initialize NewPipe with full configuration.
d
Downloader
required
The downloader implementation to use for HTTP requests
l
Localization
required
The preferred localization for content
c
ContentCountry
required
The preferred content country
NewPipe.init(
    new DownloaderTestImpl(),
    new Localization("en", "US"),
    new ContentCountry("US")
);

Service Access

getServices()

Get all supported streaming services.
return
List<StreamingService>
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.
serviceId
int
required
The unique identifier of the service
return
StreamingService
The streaming service with the specified ID
throws
ExtractionException
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.
serviceName
String
required
The name of the service (e.g., “YouTube”, “SoundCloud”)
return
StreamingService
The streaming service with the specified name
throws
ExtractionException
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.
url
String
required
The URL to check
return
StreamingService
The streaming service that can handle the URL
throws
ExtractionException
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.
return
Downloader
The active downloader instance
Downloader downloader = NewPipe.getDownloader();

Localization Configuration

setupLocalization()

Configure localization preferences.
thePreferredLocalization
Localization
required
The preferred localization
NewPipe.setupLocalization(new Localization("de", "DE"));

setupLocalization() with ContentCountry

Configure localization and content country preferences.
thePreferredLocalization
Localization
required
The preferred localization
thePreferredContentCountry
ContentCountry
The preferred content country (nullable)
NewPipe.setupLocalization(
    new Localization("fr", "FR"),
    new ContentCountry("FR")
);

getPreferredLocalization()

Get the current preferred localization.
return
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.
preferredLocalization
Localization
required
The new preferred localization
NewPipe.setPreferredLocalization(new Localization("es", "ES"));

getPreferredContentCountry()

Get the current preferred content country.
return
ContentCountry
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.
preferredContentCountry
ContentCountry
required
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();
        }
    }
}

Build docs developers (and LLMs) love