add imdb functionality for subs

This commit is contained in:
Athanasios Trispiotis 2022-10-31 01:55:18 +02:00
parent 65b5efb848
commit 77688ceb52
2 changed files with 33 additions and 6 deletions

View file

@ -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) {

View file

@ -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<String> {
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.