Giter Site home page Giter Site logo

masterwok / simple-torrent-android Goto Github PK

View Code? Open in Web Editor NEW
94.0 5.0 30.0 1.16 MB

A torrent client library for Android that utilizes frostwire-jlibtorrent. It supports sequential and simultaneous downloads.

License: MIT License

Kotlin 100.00%
android android-library torrent torrent-client bittorrent p2p

simple-torrent-android's Introduction

Release

[deprecated] simple-torrent-android

I'm no longer maintaining this project due to time constraints.

An Android torrent client library powered by frostwire-jlibtorrent. It supports sequential and simultaneous downloads.

Usage

A single torrent download session is represented as the TorrentSession class. An instance of this class can be used to start, stop, pause, and resume a torrent download. When creating a new session, a TorrentSessionOptions instance is a required constructor parameter used to configure the session. The TorrentSessionListener interface can be implemented and set on the session to receive TorrentSessionStatus updates tied to the lifecycle of the torrent. The TorrentSessionBufferState is one of the properties of the status and represents the current state of the torrent piece buffer.

For example, the following code snippet sequentially downloads the largest file of the provided torrent to the downloads directory:

// http, https, magnet, file, and content Uri types are all supported.
val torrentUri = Uri.parse("http://www.frostclick.com/torrents/video/animation/Big_Buck_Bunny_1080p_surround_frostclick.com_frostwire.com.torrent")

val torrentSessionOptions = TorrentSessionOptions(
        downloadLocation = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS)
        , onlyDownloadLargestFile = true
        , enableLogging = false
        , shouldStream = true
)

val torrentSession = TorrentSession(torrentSessionOptions)

torrentSession.listener = object : TorrentSessionListener {
    
    // Omitted for brevity
    
    override fun onPieceFinished(
        torrentHandle: TorrentHandle
        , torrentSessionStatus: TorrentSessionStatus
    ) { ... }
}

torrentSession.start(context, torrentUri) // Invoke on background thread.
// OR torrentSession.start(bencodeByteArray)

For a more detailed example, please see the demo application alongside this library (screenshot below). Please note, that the demo application does not properly show how to keep sessions alive after the activity is killed. This was a quick and dirty way of showing/testing downloads. A more real-world solution, would be to have the torrent sessions exist within a service that enters the foreground while downloading. By doing this, the sessions will retain network connectivity and will not be murdered by Android the destroyer.

Configuration

Add this in your root build.gradle at the end of repositories:

allprojects {
    repositories {
        maven { url "https://jitpack.io" }
    }
}

and add the following in the dependent module:

dependencies {
    implementation 'com.github.masterwok:simple-torrent-android:0.5.0'
}

Projects using simple-torrent-android

Demo Screenshots

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.