[Android] Add multiLanguage download api

Habib Kazemi git at videolan.org
Mon Oct 22 15:13:56 CEST 2018


vlc-android | branch: master | Habib Kazemi <kazemihabib1996 at gmail.com> | Sat Oct 20 12:14:11 2018 +0330| [dc29abf4dcbc3912d427c54db64966e6b0ebf566] | committer: Geoffrey Métais

Add multiLanguage download api

OpenSubtitle doesn't have any api for that so
we have to send a request for each one.
I considered this new api atomic so if one of
them failed it will fail

Signed-off-by: Geoffrey Métais <geoffrey.metais at gmail.com>

> https://code.videolan.org/videolan/vlc-android/commit/dc29abf4dcbc3912d427c54db64966e6b0ebf566
---

 .../vlc/repository/OpenSubtitleRepository.kt       | 42 ++++++++++++++++++++++
 1 file changed, 42 insertions(+)

diff --git a/vlc-android/src/org/videolan/vlc/repository/OpenSubtitleRepository.kt b/vlc-android/src/org/videolan/vlc/repository/OpenSubtitleRepository.kt
index 847a910ed..b45396727 100644
--- a/vlc-android/src/org/videolan/vlc/repository/OpenSubtitleRepository.kt
+++ b/vlc-android/src/org/videolan/vlc/repository/OpenSubtitleRepository.kt
@@ -49,6 +49,48 @@ class OpenSubtitleRepository(private val openSubtitleService: IOpenSubtitleServi
                 languageId = actualLanguageId) }
     }
 
+    suspend fun queryWithImdbid(imdbId: Int, tag: String?, episode: Int? , season: Int?, languageIds: List<String> ): List<OpenSubtitle> {
+        val actualEpisode = episode ?: 0
+        val actualSeason = season ?: 0
+        val actualLanguageIds = languageIds.toSet().run { if (contains("")) setOf("") else this }
+        val actualTag = tag ?: ""
+        return actualLanguageIds.flatMap {
+            retrofitResponseCall { openSubtitleService.query(
+                    imdbId = String.format("%07d", imdbId),
+                    tag = actualTag,
+                    episode = actualEpisode,
+                    season = actualSeason,
+                    languageId = it) }
+        }
+    }
+
+    suspend fun queryWithHash(movieByteSize: Long, movieHash: String, languageIds: List<String>): List<OpenSubtitle> {
+        val actualLanguageIds = languageIds.toSet().run { if (contains("")) setOf("") else this }
+        return actualLanguageIds.flatMap {
+            retrofitResponseCall {
+                openSubtitleService.query(
+                        movieByteSize = movieByteSize.toString(),
+                        movieHash = movieHash,
+                        languageId = it)
+            }
+        }
+    }
+
+    suspend fun queryWithName(name: String, episode: Int?, season: Int?, languageIds: List<String>): List<OpenSubtitle> {
+        val actualEpisode = episode ?: 0
+        val actualSeason = season ?: 0
+        val actualLanguageIds = languageIds.toSet().run { if (contains("")) setOf("") else this }
+        return actualLanguageIds.flatMap {
+            retrofitResponseCall {
+                openSubtitleService.query(
+                        name = name,
+                        episode = actualEpisode,
+                        season = actualSeason,
+                        languageId = it)
+            }
+        }
+    }
+
     companion object { fun getInstance() = OpenSubtitleRepository(OpenSubtitleClient.instance)}
 
     private suspend inline fun <reified T> retrofitResponseCall(crossinline call: () -> Call<T>) : T {



More information about the Android mailing list