Skip to content

A Kotlin Multiplatform-compatible library adapted from NewPipeExtractor for extracting YouTube videos and comments in Compose Multiplatform projects.

License

Notifications You must be signed in to change notification settings

yushosei/NewPipeExtractor-KMP

Repository files navigation

NewPipeExtractor-KMP

This repository is a Compose Multiplatform-compatible adaptation of the NewPipeExtractor, forked from version v0.24.5. It is intended for extracting YouTube videos and comments within Kotlin Multiplatform projects.


πŸ“Œ Overview

  • Migrated to Kotlin (Multiplatform).
  • Based on NewPipeExtractor v0.24.5.
  • Internal modules have been refactored and improved for better readability, structure, and platform compatibility.
  • Replaced nanojson with a pure Kotlin implementation.
  • Public APIs and function call patterns remain unchanged to ensure compatibility with the original usage.
  • This project aims to serve as a foundation for integrating content extraction logic into Compose Multiplatform applications.

πŸš€ Usage

1. Add Dependency

implementation("io.github.yushosei:newpipe-extractor-kmp:1.0")

2. Initialization

NewPipe.init(DefaultDownloaderImpl.initDefault())

3. Search

ExtractorHelper.searchFor(
    SERVICE_ID, searchText, listOf("videos"),
    "",
)

4. Get More Search Items

ExtractorHelper.getMoreSearchItems(
    SERVICE_ID, searchText, listOf("videos"), "", page
)

5. Search Suggestions

ExtractorHelper.suggestionsFor(SERVICE_ID, searchText)

6. Stream Extraction

ExtractorHelper.getStreamInfo(SERVICE_ID, item.url)

For more details, refer to the sampleApp.

πŸŽ₯ Demo Video

Android & iOS

recording.mp4

Web

2025-08-13.181218.mp4

Desktop

2025-08-13.184911.mp4

βœ… This demo showcases successful audio stream extraction and search suggestions retrieval on both Android and iOS using Kotlin Multiplatform code.
Although the test focused on audio streams for simplicity, the extractor is also capable of handling video streams. (TODO) All core logic is written in pure Kotlin, making it platform-independent and theoretically usable across desktop and web environments too.

The current implementation has been verified on Android and iOS targets using Compose Multiplatform UI.

πŸ“¦ We plan to release a cleaned-up and library-ready version of the module in the near future to facilitate reuse and integration !

⚠️ Note on nanojson Replacement

This project includes a reimplementation of nanojson in pure Kotlin, rewritten from scratch to work within the Kotlin Multiplatform (NewPipeExtractor).

  • βœ… The implementation has been tested in conjunction with NewPipe and verified to extract data correctly.
  • ⚠ However, this Kotlin version of nanojson is an interim solution. It was built for functional compatibility and does not guarantee performance parity with the original Java version.
  • It exists only to enable current operation and may be replaced in the future with a more robust or performant JSON parser tailored for KMP.

βœ… Migration Themes & Checklist

Java Dependency Removal

  • Remove core Java-only APIs (e.g. Serializable, Optional, Pattern, URL, Objects)
  • Replace Java collections, streams, and IO with Kotlin equivalents

Rhino JavaScript Handling

  • Decide on Rhino integration approach (e.g. maintain, isolate, or replace)

Custom Kotlin Object Replacement

  • Convert Java utility classes (Pair, ManifestCache, etc.) to idiomatic Kotlin

Serialization Strategy Change

  • Replace Serializable with @Serializable and kotlinx.serialization

Lightweight JSON Optimization

  • Remove nanojson dependency
  • Reimplement nanojson using pure Kotlin logic
  • Evaluate long-term direction for JSON handling:
    • Convert to a pure Kotlin @Serializable-based structure
    • More faithfully replicate original nanojson behavior for performance and features

Feature Migration Status (NewPipeExtractor Modules)

Core functionality has been migrated but not yet fully cleaned or published.

  • Search functionality migrated to Kotlin
  • Search suggestion handling migrated to Kotlin
  • Stream extraction (YouTube video info) migrated to Kotlin
  • Audio stream extraction migrated to Kotlin
  • Code cleanup and module publishing pending

πŸ§ͺ Testing & Integration

  • Add shared commonTest cases
  • Use runBlocking and mock data for multiplatform testability
  • (Optional) Include Compose-based demo or preview usage

πŸ“¦ Module Info

  • Forked by: @yushosei
  • Base version: NewPipeExtractor v0.24.5

πŸ“„ License & Copyright

This project is licensed under the GNU General Public License v3 or (at your option) any later version.

  • New files and contributions in this repository are Β© 2025 @yushosei.
  • All original content from the forked NewPipeExtractor remains Β© the NewPipe Team.

About

A Kotlin Multiplatform-compatible library adapted from NewPipeExtractor for extracting YouTube videos and comments in Compose Multiplatform projects.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages