From 77688ceb528ef160e3b831d63590372e8bf7268b Mon Sep 17 00:00:00 2001 From: Athanasios Trispiotis Date: Mon, 31 Oct 2022 01:55:18 +0200 Subject: [PATCH] add imdb functionality for subs --- app/build.gradle.kts | 10 ++++++- .../providers/OpenSubtitlesApi.kt | 29 +++++++++++++++---- 2 files changed, 33 insertions(+), 6 deletions(-) diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 42ca93fd..34a0e756 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -113,6 +113,11 @@ android { checkReleaseBuilds = false } namespace = "com.lagradost.cloudstream3" + packagingOptions { + resources { + excludes += "META-INF/DEPENDENCIES" + } + } } repositories { @@ -217,6 +222,9 @@ dependencies { // Library/extensions searching with Levenshtein distance implementation("me.xdrop:fuzzywuzzy:1.4.0") + implementation("com.github.holgerbrandl:themoviedbapi:1.12") { + exclude(group = "commons-logging", module = "commons-logging") + } } tasks.register("androidSourcesJar", Jar::class) { @@ -247,4 +255,4 @@ tasks.withType().configureEach { } } } -} \ No newline at end of file +} diff --git a/app/src/main/java/com/lagradost/cloudstream3/syncproviders/providers/OpenSubtitlesApi.kt b/app/src/main/java/com/lagradost/cloudstream3/syncproviders/providers/OpenSubtitlesApi.kt index bfa65f62..0fbe851f 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/syncproviders/providers/OpenSubtitlesApi.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/syncproviders/providers/OpenSubtitlesApi.kt @@ -2,8 +2,6 @@ package com.lagradost.cloudstream3.syncproviders.providers import android.util.Log import com.fasterxml.jackson.annotation.JsonProperty -import com.google.common.collect.BiMap -import com.google.common.collect.HashBiMap import com.lagradost.cloudstream3.* import com.lagradost.cloudstream3.AcraApplication.Companion.getKey import com.lagradost.cloudstream3.AcraApplication.Companion.removeKey @@ -15,6 +13,8 @@ import com.lagradost.cloudstream3.syncproviders.AuthAPI import com.lagradost.cloudstream3.syncproviders.InAppAuthAPI import com.lagradost.cloudstream3.syncproviders.InAppAuthAPIManager import com.lagradost.cloudstream3.utils.AppUtils +import info.movito.themoviedbapi.TmdbApi + class OpenSubtitlesApi(index: Int) : InAppAuthAPIManager(index), AbstractSubApi { override val idPrefix = "opensubtitles" @@ -163,16 +163,21 @@ class OpenSubtitlesApi(index: Int) : InAppAuthAPIManager(index), AbstractSubApi throwIfCantDoRequest() val fixedLang = fixLanguage(query.lang) - val imdbId = query.imdb ?: 0 val queryText = query.query.replace(" ", "+") val epNum = query.epNumber ?: 0 val seasonNum = query.seasonNumber ?: 0 - val yearNum = query.year ?: 0 + val ans = getImdb(queryText) + var imdbId = "" + var yearNum = 0 + if (ans[0] != "" && ans[1] != "" && seasonNum == 0 && epNum == 0) { + imdbId = ans[0] + yearNum = ans[1].toInt() + } val epQuery = if (epNum > 0) "&episode_number=$epNum" else "" val seasonQuery = if (seasonNum > 0) "&season_number=$seasonNum" else "" val yearQuery = if (yearNum > 0) "&year=$yearNum" else "" - val searchQueryUrl = when (imdbId > 0) { + val searchQueryUrl = when (imdbId != "") { //Use imdb_id to search if its valid true -> "$host/subtitles?imdb_id=$imdbId&languages=${fixedLang}$yearQuery$epQuery$seasonQuery" false -> "$host/subtitles?query=$queryText&languages=${fixedLang}$yearQuery$epQuery$seasonQuery" @@ -231,6 +236,20 @@ class OpenSubtitlesApi(index: Int) : InAppAuthAPIManager(index), AbstractSubApi return results } + private fun getImdb(s: String): Array { + val searches = TmdbApi("b2960a64f51310954666c97170072562").search + val search = searches.searchMovie(s,0,null,true,0) + val movie_id = search.results[0].id + val movies = TmdbApi("b2960a64f51310954666c97170072562").movies + val movie = movies.getMovie(movie_id, null) + if (movie == null) { + return arrayOf("", "") + } + else { + return arrayOf(movie.imdbID, movie.releaseDate.substring(0,4)) + } + } + /* Process data returned from search. Returns string url for the subtitle file.