Skip to content

Commit

Permalink
123.1
Browse files Browse the repository at this point in the history
  • Loading branch information
immisterio committed Nov 10, 2024
1 parent 69f7b26 commit a93b687
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 31 deletions.
102 changes: 73 additions & 29 deletions Online/OnlineApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,23 +70,15 @@ public ActionResult Lite()


#region externalids
/// <summary>
/// imdb_id, kinopoisk_id
/// </summary>
static Dictionary<string, string> externalids = null;

[Route("externalids")]
async public Task<ActionResult> Externalids(string id, string imdb_id, long kinopoisk_id, int serial)
{
if (id == null || id == "0")
return Content("{}");

if (id.StartsWith("KP_"))
{
string json = await HttpClient.Get($"{AppInit.conf.VCDN.corsHost()}/api/short?api_token={AppInit.conf.VCDN.token}&kinopoisk_id=" + id.Replace("KP_", ""), timeoutSeconds: 5);
return Json(new { imdb_id = Regex.Match(json ?? "", "\"imdb_id\":\"(tt[^\"]+)\"").Groups[1].Value, kinopoisk_id = id.Replace("KP_", "") });
}

if (!long.TryParse(id, out _))
return Content("{}");

#region load externalids
if (externalids == null && IO.File.Exists("cache/externalids/master.json"))
{
try
Expand All @@ -98,6 +90,39 @@ async public Task<ActionResult> Externalids(string id, string imdb_id, long kino

if (externalids == null)
externalids = new Dictionary<string, string>();
#endregion

#region KP_
if (id != null && id.StartsWith("KP_"))
{
string _kp = id.Replace("KP_", "");
foreach (var eid in externalids)
{
if (eid.Value == _kp && !string.IsNullOrEmpty(eid.Key))
{
imdb_id = eid.Key;
break;
}
}

if (!string.IsNullOrEmpty(imdb_id))
{
return Json(new { imdb_id, kinopoisk_id = _kp });
}
else
{
string mkey = $"externalids:KP_:{_kp}";
if (!memoryCache.TryGetValue(mkey, out string _imdbid))
{
string json = await HttpClient.Get($"{AppInit.conf.VCDN.corsHost()}/api/short?api_token={AppInit.conf.VCDN.token}&kinopoisk_id=" + id.Replace("KP_", ""), timeoutSeconds: 5);
_imdbid = Regex.Match(json ?? "", "\"imdb_id\":\"(tt[^\"]+)\"").Groups[1].Value;
memoryCache.Set(mkey, _imdbid, DateTime.Now.AddHours(8));
}

return Json(new { imdb_id = _imdbid, kinopoisk_id = id.Replace("KP_", "") });
}
}
#endregion

#region getAlloha / getVSDN / getTabus
async Task<string> getAlloha(string imdb)
Expand Down Expand Up @@ -147,25 +172,40 @@ async Task<string> getTabus(string imdb)
#region get imdb_id
if (string.IsNullOrWhiteSpace(imdb_id))
{
string path = $"cache/externalids/{id}";
if (IO.File.Exists(path))
if (kinopoisk_id > 0)
{
imdb_id = IO.File.ReadAllText(path);
foreach (var eid in externalids)
{
if (eid.Value == kinopoisk_id.ToString() && !string.IsNullOrEmpty(eid.Key))
{
imdb_id = eid.Key;
break;
}
}
}
else

if (string.IsNullOrWhiteSpace(imdb_id) && long.TryParse(id, out _))
{
string mkey = $"externalids:locktmdb:{serial}:{id}";
if (!memoryCache.TryGetValue(mkey, out _))
string path = $"cache/externalids/{id}_{serial}";
if (IO.File.Exists(path))
{
memoryCache.Set(mkey, 0 , DateTime.Now.AddHours(1));

string cat = serial == 1 ? "tv" : "movie";
string json = await HttpClient.Get($"https://api.themoviedb.org/3/{cat}/{id}?api_key=4ef0d7355d9ffb5151e987764708ce96&append_to_response=external_ids", timeoutSeconds: 6);
if (!string.IsNullOrWhiteSpace(json))
imdb_id = IO.File.ReadAllText(path);
}
else
{
string mkey = $"externalids:locktmdb:{serial}:{id}";
if (!memoryCache.TryGetValue(mkey, out _))
{
imdb_id = Regex.Match(json, "\"imdb_id\":\"(tt[0-9]+)\"").Groups[1].Value;
if (!string.IsNullOrWhiteSpace(imdb_id))
IO.File.WriteAllText(path, imdb_id);
memoryCache.Set(mkey, 0, DateTime.Now.AddHours(1));

string cat = serial == 1 ? "tv" : "movie";
string json = await HttpClient.Get($"https://api.themoviedb.org/3/{cat}/{id}?api_key=4ef0d7355d9ffb5151e987764708ce96&append_to_response=external_ids", timeoutSeconds: 6);
if (!string.IsNullOrWhiteSpace(json))
{
imdb_id = Regex.Match(json, "\"imdb_id\":\"(tt[0-9]+)\"").Groups[1].Value;
if (!string.IsNullOrWhiteSpace(imdb_id))
IO.File.WriteAllText(path, imdb_id);
}
}
}
}
Expand All @@ -179,7 +219,7 @@ async Task<string> getTabus(string imdb)
{
externalids.TryGetValue(imdb_id, out kpid);

if (string.IsNullOrEmpty(kpid))
if (string.IsNullOrEmpty(kpid) || kpid == "0")
{
string path = $"cache/externalids/{imdb_id}";
if (IO.File.Exists(path))
Expand Down Expand Up @@ -215,9 +255,13 @@ async Task<string> getTabus(string imdb)
}
}

if (!string.IsNullOrEmpty(kpid))
if (!string.IsNullOrEmpty(kpid) && kpid != "0")
{
externalids.TryAdd(imdb_id, kpid);
if (externalids.ContainsKey(imdb_id))
externalids[imdb_id] = kpid;
else
externalids.TryAdd(imdb_id, kpid);

IO.File.WriteAllText(path, kpid);
}
}
Expand Down
4 changes: 2 additions & 2 deletions Shared/Engine/BaseController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ public class BaseController : Controller, IDisposable
{
IServiceScope serviceScope;

public static string appversion => "122";
public static string appversion => "123";

public static string minorversion => "16";
public static string minorversion => "1";

public HybridCache hybridCache { get; private set; }

Expand Down

0 comments on commit a93b687

Please sign in to comment.