Skip to content

Commit c009113

Browse files
authored
Merge pull request #827 from EraYaN/anidb-imageserver
Make the AniDB image server url dynamic from the login call.
2 parents fc73136 + 2a80f40 commit c009113

9 files changed

+50
-14
lines changed

Shoko.CLI/Shoko.CLI.csproj

-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
<ProjectReference Include="..\Shoko.Commons\Shoko.Commons.csproj" />
2525
<ProjectReference Include="..\Shoko.Commons\Shoko.Models\Shoko.Models.csproj" />
2626
<ProjectReference Include="..\Shoko.Server\Shoko.Server.csproj" />
27-
<ProjectReference Include="..\MediaInfoWrapper\MediaInfoWrapper.csproj" />
2827
</ItemGroup>
2928
<ItemGroup>
3029
<WCFMetadata Include="Connected Services\" />

Shoko.Server/AniDBHelper.cs

+27
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
using AniDBAPI.Commands;
1212
using NHibernate;
1313
using NLog;
14+
using NutzCode.CloudFileSystem;
1415
using Shoko.Commons.Properties;
1516
using Shoko.Models.Enums;
1617
using Shoko.Models.Interfaces;
@@ -19,6 +20,7 @@
1920
using Shoko.Server.Databases;
2021
using Shoko.Server.Extensions;
2122
using Shoko.Server.Models;
23+
using Shoko.Server.Providers.AniDB;
2224
using Shoko.Server.Repositories;
2325
using Shoko.Server.Repositories.NHibernate;
2426
using Shoko.Server.Settings;
@@ -41,6 +43,7 @@ public class AniDBHelper
4143
private IPEndPoint remoteIpEndPoint;
4244
private Socket soUdp;
4345
private string curSessionID = string.Empty;
46+
private string curImageServerUrl;
4447

4548
private string userName = string.Empty;
4649
private string password = string.Empty;
@@ -56,6 +59,29 @@ public class AniDBHelper
5659
public DateTime? HttpBanTime { get; set; }
5760
public DateTime? UdpBanTime { get; set; }
5861

62+
public string ImageServerUrl {
63+
get {
64+
if (string.IsNullOrWhiteSpace(curImageServerUrl))
65+
{
66+
if (!Login())
67+
{
68+
//Don't keep trying after a failed login set to constant
69+
curImageServerUrl = Constants.URLS.AniDB_Images_Domain;
70+
}
71+
else
72+
{
73+
if (string.IsNullOrWhiteSpace(curImageServerUrl))
74+
{
75+
//The API call did not return anything useful, don't try again.
76+
curImageServerUrl = Constants.URLS.AniDB_Images_Domain;
77+
}
78+
}
79+
}
80+
var url = string.Format(Constants.URLS.AniDB_Images, curImageServerUrl);
81+
return url;
82+
}
83+
}
84+
5985
private bool _isHttpBanned;
6086
private bool _isUdpBanned;
6187

@@ -394,6 +420,7 @@ public bool Login()
394420
break;
395421
case AniDBUDPResponseCode.LoggedIn:
396422
curSessionID = login.SessionID;
423+
curImageServerUrl = login.ImageServerUrl;
397424
isLoggedOn = true;
398425
IsInvalidSession = false;
399426
return true;

Shoko.Server/AniDB_API/Commands/AniDBCommand_Login.cs

+5-3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ public class AniDBCommand_Login : AniDBUDPCommand, IAniDBUDPCommand
88
{
99
public string SessionID = string.Empty;
1010

11+
public string ImageServerUrl;
12+
1113
public virtual AniDBUDPResponseCode GetStartEventType()
1214
{
1315
return AniDBUDPResponseCode.LoggingIn;
@@ -36,7 +38,7 @@ public virtual AniDBUDPResponseCode Process(ref Socket soUDP,
3638
string sMsgType = socketResponse.Substring(0, 3);
3739
//BaseConfig.MyAnimeLog.Write("AniDBCommand_Login.Process: Response: {0}", socketResponse);
3840

39-
// 200 {str session_key} LOGIN ACCEPTED
41+
// 200 {str session_key} LOGIN ACCEPTED\n{imgserver url}
4042
// 203 LOGGED OUT
4143
// 500 LOGIN FAILED
4244
if (sMsgType.Equals("500"))
@@ -50,7 +52,7 @@ public virtual AniDBUDPResponseCode Process(ref Socket soUDP,
5052
SessionID = sMessage.Trim();
5153
int i = sMessage.IndexOf("LOGIN");
5254
SessionID = sMessage.Substring(0, i - 1).Trim();
53-
55+
ImageServerUrl = sMessage.Substring(sMessage.IndexOf('\n')).Trim();
5456
return AniDBUDPResponseCode.LoggedIn;
5557
}
5658

@@ -67,7 +69,7 @@ public void Init(string userName, string password)
6769
commandText += "&protover=3";
6870
commandText += "&client=ommserver";
6971
//commandText += "&client=vmcanidb";
70-
commandText += "&clientver=2&comp=1";
72+
commandText += "&clientver=2&comp=1&imgserver=1";
7173
//BaseConfig.MyAnimeLog.Write("commandText: {0}", commandText);
7274
}
7375
}

Shoko.Server/Commands/Import/CommandRequest_DownloadAniDBImages.cs

+4-3
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
using Shoko.Server.Extensions;
1818
using Shoko.Server.ImageDownload;
1919
using Shoko.Server.Models;
20+
using Shoko.Server.Providers.AniDB;
2021
using Shoko.Server.Repositories;
2122
using Shoko.Server.Settings;
2223

@@ -89,7 +90,7 @@ public override void ProcessCommand()
8990
return;
9091
}
9192

92-
downloadURLs.Add(string.Format(Constants.URLS.AniDB_Images, anime.Picname));
93+
downloadURLs.Add(string.Format(ShokoService.AnidbProcessor.ImageServerUrl, anime.Picname));
9394
fileNames.Add(anime.PosterPath);
9495
break;
9596

@@ -109,7 +110,7 @@ select RepoFactory.AniDB_Character.GetByCharID(xref1.CharID))
109110

110111
foreach (var chr in chrs)
111112
{
112-
downloadURLs.Add(string.Format(Constants.URLS.AniDB_Images, chr.PicName));
113+
downloadURLs.Add(string.Format(ShokoService.AnidbProcessor.ImageServerUrl, chr.PicName));
113114
fileNames.Add(chr.GetPosterPath());
114115
}
115116

@@ -134,7 +135,7 @@ select RepoFactory.AniDB_Seiyuu.GetBySeiyuuID(xref2.SeiyuuID))
134135

135136
foreach (var creator in creators)
136137
{
137-
downloadURLs.Add(string.Format(Constants.URLS.AniDB_Images, creator.PicName));
138+
downloadURLs.Add(string.Format(ShokoService.AnidbProcessor.ImageServerUrl, creator.PicName));
138139
fileNames.Add(creator.GetPosterPath());
139140
}
140141

Shoko.Server/Commands/Import/CommandRequest_DownloadImage.cs

+4-3
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
using Shoko.Server.Extensions;
1616
using Shoko.Server.ImageDownload;
1717
using Shoko.Server.Models;
18+
using Shoko.Server.Providers.AniDB;
1819
using Shoko.Server.Repositories;
1920
using Shoko.Server.Settings;
2021

@@ -403,15 +404,15 @@ public static string GetFileURL(ImageDownloadRequest req)
403404

404405
case ImageEntityType.AniDB_Cover:
405406
SVR_AniDB_Anime anime = req.ImageData as SVR_AniDB_Anime;
406-
return string.Format(Constants.URLS.AniDB_Images, anime.Picname);
407+
return string.Format(ShokoService.AnidbProcessor.ImageServerUrl, anime.Picname);
407408

408409
case ImageEntityType.AniDB_Character:
409410
AniDB_Character chr = req.ImageData as AniDB_Character;
410-
return string.Format(Constants.URLS.AniDB_Images, chr.PicName);
411+
return string.Format(ShokoService.AnidbProcessor.ImageServerUrl, chr.PicName);
411412

412413
case ImageEntityType.AniDB_Creator:
413414
AniDB_Seiyuu creator = req.ImageData as AniDB_Seiyuu;
414-
return string.Format(Constants.URLS.AniDB_Images, creator.PicName);
415+
return string.Format(ShokoService.AnidbProcessor.ImageServerUrl, creator.PicName);
415416

416417
default:
417418
return string.Empty;

Shoko.Server/Constants.cs

+4-1
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,10 @@ public struct URLS
157157
public static readonly string AniDB_ReleaseGroup =
158158
@"https://anidb.net/perl-bin/animedb.pl?show=group&gid={0}";
159159

160-
public static readonly string AniDB_Images = @"https://img7.anidb.net/pics/anime/{0}";
160+
public static readonly string AniDB_Images = @"https://{0}/images/main/{{0}}";
161+
162+
// This is the fallback if the API response does not work.
163+
public static readonly string AniDB_Images_Domain = @"cdn.anidb.net";
161164

162165
public static readonly string TvDB_Series = @"https://thetvdb.com/?tab=series&id={0}";
163166

Shoko.Server/Extensions/ModelProviders.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -651,14 +651,14 @@ public static Azure_AnimeCharacter ToContractAzure(this AniDB_Character characte
651651
CharKanjiName = character.CharKanjiName,
652652
CharDescription = character.CharDescription,
653653
CharType = charRel.CharType,
654-
CharImageURL = string.Format(Constants.URLS.AniDB_Images, character.PicName)
654+
CharImageURL = string.Format(ShokoService.AnidbProcessor.ImageServerUrl, character.PicName)
655655
};
656656
AniDB_Seiyuu seiyuu = character.GetSeiyuu();
657657
if (seiyuu != null)
658658
{
659659
contract.SeiyuuID = seiyuu.AniDB_SeiyuuID;
660660
contract.SeiyuuName = seiyuu.SeiyuuName;
661-
contract.SeiyuuImageURL = string.Format(Constants.URLS.AniDB_Images, seiyuu.PicName);
661+
contract.SeiyuuImageURL = string.Format(ShokoService.AnidbProcessor.ImageServerUrl, seiyuu.PicName);
662662
}
663663

664664
return contract;

Shoko.Server/LZ4/LZ4Codec.Safe.cs

+3
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2828
// ReSharper disable CheckNamespace
2929
// ReSharper disable InconsistentNaming
3030

31+
using System;
32+
using System.Diagnostics;
33+
3134
namespace LZ4ps
3235
{
3336
#if !UNSAFE

Shoko.Server/Models/SVR_AniDB_Anime.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1824,7 +1824,7 @@ public Azure_AnimeFull ToAzure(ISessionWrapper session)
18241824
contract.Detail.EpisodeCountSpecial = EpisodeCountSpecial;
18251825
contract.Detail.FanartURL = GetDefaultFanartOnlineURL();
18261826
contract.Detail.OverallRating = this.GetAniDBRating();
1827-
contract.Detail.PosterURL = string.Format(Constants.URLS.AniDB_Images, Picname);
1827+
contract.Detail.PosterURL = string.Format(ShokoService.AnidbProcessor.ImageServerUrl, Picname);
18281828
contract.Detail.TotalVotes = this.GetAniDBTotalVotes();
18291829

18301830

0 commit comments

Comments
 (0)