Skip to content

Commit

Permalink
Merge pull request #1052 from Mik1ll/fix-language-update
Browse files Browse the repository at this point in the history
Fix AniDB languages not being updated properly
  • Loading branch information
revam authored Apr 1, 2023
2 parents eea3a9b + 4d1a12b commit 0760ec4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
24 changes: 13 additions & 11 deletions Shoko.Server/Commands/AniDB/CommandRequest_GetFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -138,34 +138,36 @@ protected override void Process()
public void CreateLanguages(ResponseGetFile response)
{
using var session = DatabaseFactory.SessionFactory.OpenSession();
if ((response?.AudioLanguages?.Count ?? 0) >
0) //Only create relations if the origin of the data if from Raw (WebService/AniDB)
using var trans = session.BeginTransaction();
// Only update languages if we got a response
if (response?.AudioLanguages is not null)
{
// Delete old if changed
var fileLanguages = RepoFactory.CrossRef_Languages_AniDB_File.GetByFileID(response.FileID);
RepoFactory.CrossRef_Languages_AniDB_File.DeleteWithOpenTransaction(session, fileLanguages);
// Delete old
var toDelete = RepoFactory.CrossRef_Languages_AniDB_File.GetByFileID(response.FileID);
RepoFactory.CrossRef_Languages_AniDB_File.DeleteWithOpenTransaction(session, toDelete);

// Save new
var toSave = response.AudioLanguages.Select(language => language.Trim().ToLower())
.Where(lang => lang.Length > 0)
.Select(lang => new CrossRef_Languages_AniDB_File { LanguageName = lang, FileID = response.FileID })
.ToList();

RepoFactory.CrossRef_Languages_AniDB_File.SaveWithOpenTransaction(session, toSave);
}

if ((response?.SubtitleLanguages?.Count ?? 0) > 0)
if (response?.SubtitleLanguages is not null)
{
// Delete old if changed
var fileLanguages = RepoFactory.CrossRef_Subtitles_AniDB_File.GetByFileID(response.FileID);
RepoFactory.CrossRef_Subtitles_AniDB_File.DeleteWithOpenTransaction(session, fileLanguages);
// Delete old
var toDelete = RepoFactory.CrossRef_Subtitles_AniDB_File.GetByFileID(response.FileID);
RepoFactory.CrossRef_Subtitles_AniDB_File.DeleteWithOpenTransaction(session, toDelete);

// Save new
var toSave = response.SubtitleLanguages.Select(language => language.Trim().ToLower())
.Where(lang => lang.Length > 0)
.Select(lang => new CrossRef_Subtitles_AniDB_File { LanguageName = lang, FileID = response.FileID })
.ToList();

RepoFactory.CrossRef_Subtitles_AniDB_File.SaveWithOpenTransaction(session, toSave);
}
trans.Commit();
}

public void CreateEpisodes(string filename, ResponseGetFile response)
Expand Down
4 changes: 2 additions & 2 deletions Shoko.Server/Providers/AniDB/UDP/Info/RequestGetFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -222,10 +222,10 @@ protected override UDPResponse<ResponseGetFile> ParseResponse(UDPResponse<string
}

// audio languages
var alangs = parts[10].Split(new[] { '\'' }, StringSplitOptions.RemoveEmptyEntries).ToList();
var alangs = parts[10].Split(new[] { '\'' }, StringSplitOptions.RemoveEmptyEntries).Where(lang => lang != "none").ToList();

// sub languages
var slangs = parts[11].Split(new[] { '\'' }, StringSplitOptions.RemoveEmptyEntries).ToList();
var slangs = parts[11].Split(new[] { '\'' }, StringSplitOptions.RemoveEmptyEntries).Where(lang => lang != "none").ToList();

// mylist
var myList = ParseMyList(parts);
Expand Down

0 comments on commit 0760ec4

Please sign in to comment.