Skip to content

Commit 0f9be7d

Browse files
authored
Merge pull request ShokoAnime#4 from hidden4003/nancy
Added GetSeriesFileStatsByFolderId
2 parents 6ebee6f + 7bb1797 commit 0f9be7d

File tree

4 files changed

+69
-1
lines changed

4 files changed

+69
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using System.Collections.Generic;
2+
3+
namespace JMMContracts
4+
{
5+
public class Contract_AnimeSeriesFileStats
6+
{
7+
public int AnimeSeriesID { get; set; }
8+
public string AnimeSeriesName { get; set; }
9+
public List<string> Folders { get; set; }
10+
public int FileCount { get; set; }
11+
public long FileSize { get; set; }
12+
}
13+
}

JMMContracts/JMMContracts.csproj

+1
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@
9393
<Compile Include="Contract_AnimeGroup_SaveResponse.cs" />
9494
<Compile Include="Contract_AnimeRating.cs" />
9595
<Compile Include="Contract_AnimeSearch.cs" />
96+
<Compile Include="Contract_AnimeSeriesFileStats.cs" />
9697
<Compile Include="Contract_AnimeSeries.cs" />
9798
<Compile Include="Contract_AniDB_AnimeDetailed.cs" />
9899
<Compile Include="Contract_AnimeSeries_Save.cs" />

JMMServer/API/APIv2_core_Module.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1209,7 +1209,7 @@ private object GetSerieByFolderId(int folder_id, int max)
12091209
Request request = this.Request;
12101210
Entities.JMMUser user = (Entities.JMMUser)this.Context.CurrentUser;
12111211
JMMServiceImplementation _impl = new JMMServiceImplementation();
1212-
return _impl.GetSeriesByFolderID(folder_id, user.JMMUserID, max);
1212+
return _impl.GetSeriesFileStatsByFolderID(folder_id, user.JMMUserID, max);
12131213
}
12141214

12151215
/// <summary>

JMMServer/JMMServiceImplementation.cs

+54
Original file line numberDiff line numberDiff line change
@@ -2436,6 +2436,60 @@ public List<Contract_AnimeSeries> GetSeriesByFolderID(int FolderID, int userID,
24362436
return null;
24372437
}
24382438

2439+
public List<Contract_AnimeSeriesFileStats> GetSeriesFileStatsByFolderID(int FolderID, int userID, int max)
2440+
{
2441+
try
2442+
{
2443+
int limit = 0;
2444+
Dictionary<int,Contract_AnimeSeriesFileStats> list = new Dictionary<int, Contract_AnimeSeriesFileStats>();
2445+
VideoLocalRepository reVideo = new VideoLocalRepository();
2446+
ImportFolderRepository repFolders = new ImportFolderRepository();
2447+
ImportFolder fldr = repFolders.GetByID(FolderID);
2448+
if (fldr == null) return list.Values.ToList();
2449+
string importLocation = fldr.ImportFolderLocation.TrimEnd('\\');
2450+
2451+
foreach (VideoLocal vi in reVideo.GetByImportFolder(FolderID))
2452+
{
2453+
foreach (Contract_AnimeEpisode ae in GetEpisodesForFile(vi.VideoLocalID, userID))
2454+
{
2455+
Contract_AnimeSeries ase = GetSeries(ae.AnimeSeriesID, userID);
2456+
Contract_AnimeSeriesFileStats asfs = null;
2457+
if (list.TryGetValue(ase.AnimeSeriesID, out asfs) == false)
2458+
{
2459+
limit++;
2460+
if (limit >= max)
2461+
{
2462+
continue;
2463+
}
2464+
asfs = new Contract_AnimeSeriesFileStats();
2465+
asfs.AnimeSeriesName = ase.AniDBAnime.AniDBAnime.MainTitle;
2466+
asfs.FileCount = 0;
2467+
asfs.FileSize = 0;
2468+
asfs.Folders = new List<string>();
2469+
asfs.AnimeSeriesID = ase.AnimeSeriesID;
2470+
list.Add(ase.AnimeSeriesID, asfs);
2471+
}
2472+
asfs.FileCount++;
2473+
asfs.FileSize += vi.FileSize;
2474+
2475+
string filePath = Pri.LongPath.Path.GetDirectoryName(vi.FullServerPath).Replace(importLocation, "");
2476+
filePath = filePath.TrimStart('\\');
2477+
if (!asfs.Folders.Contains(filePath)) {
2478+
asfs.Folders.Add(filePath);
2479+
}
2480+
2481+
}
2482+
}
2483+
2484+
return list.Values.ToList();
2485+
}
2486+
catch (Exception ex)
2487+
{
2488+
logger.ErrorException(ex.ToString(), ex);
2489+
}
2490+
return null;
2491+
}
2492+
24392493
public Contract_AnimeSeries GetSeriesForAnime(int animeID, int userID)
24402494
{
24412495
AnimeSeriesRepository repAnimeSer = new AnimeSeriesRepository();

0 commit comments

Comments
 (0)