forked from aniyomiorg/aniyomi
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #122 from Diegopyl1209/master
torrent changes from aniyomi
- Loading branch information
Showing
62 changed files
with
35 additions
and
5,749 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,5 +22,3 @@ | |
*.woff binary | ||
*.pyc binary | ||
*.swp binary | ||
|
||
*.aar binary |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 18 additions & 18 deletions
36
app/src/main/java/eu/kanade/tachiyomi/torrentutils/TorrentUtils.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,34 @@ | ||
package eu.kanade.tachiyomi.torrentutils | ||
|
||
import eu.kanade.tachiyomi.data.torrentServer.TorrentServerApi | ||
import eu.kanade.tachiyomi.torrentutils.model.DeadTorrentException | ||
import eu.kanade.tachiyomi.torrentutils.model.TorrentFile | ||
import eu.kanade.tachiyomi.torrentutils.model.TorrentInfo | ||
import java.net.SocketTimeoutException | ||
|
||
/** | ||
* Used by extensions. | ||
*/ | ||
@Suppress("UNUSED") | ||
object TorrentUtils { | ||
fun getTorrentInfo( | ||
suspend fun getTorrentInfo( | ||
url: String, | ||
title: String, | ||
): TorrentInfo { | ||
val torrent = TorrentServerApi.addTorrent(url, title, "", "", false) | ||
return TorrentInfo( | ||
torrent.title, | ||
torrent.file_stats?.map { file -> | ||
TorrentFile(file.path, file.id ?: 0, file.length, torrent.hash!!) | ||
} ?: emptyList(), | ||
torrent.hash!!, | ||
torrent.torrent_size!!, | ||
torrent.trackers ?: emptyList(), | ||
) | ||
} | ||
|
||
fun getTorrentPlayUrl( | ||
torrent: TorrentInfo, | ||
indexFile: Int = 0, | ||
): String { | ||
return torrent.files[indexFile].toVideoUrl() | ||
@Suppress("SwallowedException") | ||
try { | ||
val torrent = TorrentServerApi.addTorrent(url, title, "", "", false) | ||
return TorrentInfo( | ||
torrent.title, | ||
torrent.file_stats?.map { file -> | ||
TorrentFile(file.path, file.id ?: 0, file.length, torrent.hash!!, torrent.trackers ?: emptyList()) | ||
} ?: emptyList(), | ||
torrent.hash!!, | ||
torrent.torrent_size!!, | ||
torrent.trackers ?: emptyList(), | ||
) | ||
} catch (e: SocketTimeoutException) { | ||
throw DeadTorrentException() | ||
} | ||
} | ||
} |
17 changes: 4 additions & 13 deletions
17
app/src/main/java/eu/kanade/tachiyomi/torrentutils/model/TorrentFile.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,16 @@ | ||
package eu.kanade.tachiyomi.torrentutils.model | ||
|
||
import eu.kanade.tachiyomi.data.torrentServer.TorrentServerUtils | ||
import java.io.File | ||
import java.net.URLEncoder | ||
|
||
data class TorrentFile( | ||
val path: String, | ||
val indexFile: Int, | ||
val size: Long, | ||
private val torrentHash: String, | ||
private val trackers: List<String> = emptyList(), | ||
) { | ||
override fun toString(): String { | ||
return path | ||
} | ||
|
||
private fun getFileName(): String { | ||
return File(path).name | ||
} | ||
|
||
fun toVideoUrl(): String { | ||
val encodedName = URLEncoder.encode(getFileName(), "utf8") | ||
return "${TorrentServerUtils.hostUrl}/stream/$encodedName?link=$torrentHash&index=$indexFile&play" | ||
fun toMagnetURI(): String { | ||
val trackers = trackers.joinToString("&tr=") { URLEncoder.encode(it, "UTF-8") } | ||
return "magnet:?xt=urn:btih:$torrentHash${if (trackers.isNotEmpty()) "&tr=$trackers" else ""}&index=$indexFile" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.