diff --git a/Shoko.Server/API/v2/Models/common/ObjectList.cs b/Shoko.Server/API/v2/Models/common/ObjectList.cs index f0225f3b5..0d63d1849 100644 --- a/Shoko.Server/API/v2/Models/common/ObjectList.cs +++ b/Shoko.Server/API/v2/Models/common/ObjectList.cs @@ -2,12 +2,12 @@ namespace Shoko.Server.API.v2.Models.common { - [System.Obsolete] public class ObjectList { public List list { get; private set; } + public string name { get; set; } - public int size { get; private set; } + public long size { get; set; } public string type { get; set; } public ObjectList() @@ -15,6 +15,13 @@ public ObjectList() list = new List(); } + public ObjectList(string _name, ListType _type, long _size) + { + name = _name; + type = _type.ToString().ToLower(); + size = _size; + } + public ObjectList(string _name, ListType _type) { name = _name; diff --git a/Shoko.Server/API/v2/Models/common/Serie.cs b/Shoko.Server/API/v2/Models/common/Serie.cs index 61f256bc5..198547659 100644 --- a/Shoko.Server/API/v2/Models/common/Serie.cs +++ b/Shoko.Server/API/v2/Models/common/Serie.cs @@ -28,6 +28,9 @@ public override string type [DataMember(IsRequired = true, EmitDefaultValue = true)] public int ismovie { get; set; } + [DataMember(IsRequired = false, EmitDefaultValue = false)] + public long filesize { get; set; } + public Serie() { art = new ArtCollection(); @@ -35,8 +38,7 @@ public Serie() tags = new List(); } - public static Serie GenerateFromVideoLocal(NancyContext ctx, SVR_VideoLocal vl, int uid, bool nocast, bool notag, int level, - bool all, bool allpic, int pic) + public static Serie GenerateFromVideoLocal(NancyContext ctx, SVR_VideoLocal vl, int uid, bool nocast, bool notag, int level, bool all, bool allpic, int pic) { Serie sr = new Serie(); @@ -51,8 +53,7 @@ public static Serie GenerateFromVideoLocal(NancyContext ctx, SVR_VideoLocal vl, return sr; } - public static Serie GenerateFromAnimeSeries(NancyContext ctx, SVR_AnimeSeries ser, int uid, bool nocast, bool notag, int level, - bool all, bool allpic, int pic) + public static Serie GenerateFromAnimeSeries(NancyContext ctx, SVR_AnimeSeries ser, int uid, bool nocast, bool notag, int level, bool all, bool allpic, int pic) { Serie sr = new Serie(); @@ -77,6 +78,7 @@ public static Serie GenerateFromAnimeSeries(NancyContext ctx, SVR_AnimeSeries se sr.ismovie = 1; } + #region Images Random rand = new Random(); Contract_ImageDetails art; if (nv.Fanarts != null && nv.Fanarts.Count > 0) @@ -149,6 +151,7 @@ public static Serie GenerateFromAnimeSeries(NancyContext ctx, SVR_AnimeSeries se { sr.art.thumb.Add(new Art() {url = APIHelper.ConstructImageLinkFromRest(ctx, nv.Thumb), index = 0}); } + #endregion if (!nocast) { @@ -230,6 +233,13 @@ public static Serie GenerateFromAnimeSeries(NancyContext ctx, SVR_AnimeSeries se { sr.eps.Add(new_ep); } + if (level - 1 > 0) + { + foreach (RawFile file in new_ep.files) + { + sr.filesize += file.size; + } + } } sr.eps = sr.eps.OrderBy(a => a.epnumber).ToList(); } diff --git a/Shoko.Server/API/v2/Models/core/API_Call_Parameters.cs b/Shoko.Server/API/v2/Models/core/API_Call_Parameters.cs index 289a78218..2bd5bd276 100644 --- a/Shoko.Server/API/v2/Models/core/API_Call_Parameters.cs +++ b/Shoko.Server/API/v2/Models/core/API_Call_Parameters.cs @@ -100,5 +100,10 @@ public class API_Call_Parameters /// show only given number of pictures related to object /// public int pic = 1; + + /// + /// skip some of the information with supported calls + /// + public int skip = 0; } } \ No newline at end of file diff --git a/Shoko.Server/API/v2/Modules/Common.cs b/Shoko.Server/API/v2/Modules/Common.cs index d963671cb..a5586d79f 100644 --- a/Shoko.Server/API/v2/Modules/Common.cs +++ b/Shoko.Server/API/v2/Modules/Common.cs @@ -129,6 +129,7 @@ public Common() : base("/api") Get["/serie/search", true] = async (x,ct) => await Task.Factory.StartNew(SearchForSerie, ct); Get["/serie/tag", true] = async (x,ct) => await Task.Factory.StartNew(SearchForTag, ct); Get["/serie/byfolder", true] = async (x,ct) => await Task.Factory.StartNew(GetSeriesByFolderId, ct); + Get["/serie/infobyfolder", true] = async (x,ct) => await Task.Factory.StartNew(GetSeriesInfoByFolderId, ct); Get["/serie/watch", true] = async (x,ct) => await Task.Factory.StartNew(MarkSerieAsWatched, ct); Get["/serie/unwatch", true] = async (x,ct) => await Task.Factory.StartNew(MarkSerieAsUnwatched, ct); Get["/serie/vote", true] = async (x,ct) => await Task.Factory.StartNew(VoteOnSerie, ct); @@ -1507,6 +1508,26 @@ private object GetSeriesByFolderId() } } + /// + /// Handle /api/serie/infobyfolder + /// + /// List or APIStatus + private object GetSeriesInfoByFolderId() + { + Request request = this.Request; + JMMUser user = (JMMUser)this.Context.CurrentUser; + API_Call_Parameters para = this.Bind(); + + if (para.id != 0) + { + return GetSeriesInfoByFolder(para.id, user.JMMUserID, para.limit); + } + else + { + return APIStatus.internalError("missing 'id'"); + } + } + /// /// Handle /api/serie/recent /// @@ -1692,6 +1713,7 @@ internal object GetSeriesByFolder(int id, int uid, bool nocast, bool notag, int List vlpall = RepoFactory.VideoLocalPlace.GetByImportFolder(id) .Select(a => a.VideoLocal) .ToList(); + if (limit == 0) { // hardcoded limit @@ -1710,6 +1732,62 @@ internal object GetSeriesByFolder(int id, int uid, bool nocast, bool notag, int return allseries; } + /// + /// Return SeriesInfo inside ObjectList that resine inside folder + /// + /// import folder id + /// user id + /// + /// List + internal object GetSeriesInfoByFolder(int id, int uid, int limit) + { + Dictionary tmp_list = new Dictionary(); + List allseries = new List(); + List vlpall = RepoFactory.VideoLocalPlace.GetByImportFolder(id) + .Select(a => a.VideoLocal) + .ToList(); + + if (limit == 0) + { + // hardcoded limit + limit = 100; + } + + foreach (SVR_VideoLocal vl in vlpall) + { + Serie ser = Serie.GenerateFromVideoLocal(Context, vl, uid, true, true, 2, false, false, 0); + + ObjectList objl = new ObjectList(ser.name, ObjectList.ListType.SERIE, ser.filesize); + if (ser.name != null) + { + if (!tmp_list.ContainsKey(ser.name)) + { + tmp_list.Add(ser.name, ser.filesize); + allseries.Add(objl); + } + else + { + if (tmp_list[ser.name] != ser.filesize) + { + while (tmp_list.ContainsKey(objl.name)) + { + objl.name = objl.name + "*"; + } + tmp_list.Add(objl.name, ser.filesize); + allseries.Add(objl); + } + } + } + + if (allseries.Count >= limit) + { + break; + } + } + + return allseries; + } + /// /// Return Serie for given episode ///