Skip to content

Commit

Permalink
Adding /api/serie/infobyfolder;
Browse files Browse the repository at this point in the history
  • Loading branch information
bigretromike committed Jun 29, 2017
1 parent aab30db commit 7ff5b32
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 6 deletions.
11 changes: 9 additions & 2 deletions Shoko.Server/API/v2/Models/common/ObjectList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,26 @@

namespace Shoko.Server.API.v2.Models.common
{
[System.Obsolete]
public class ObjectList
{
public List<object> 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()
{
list = new List<object>();
}

public ObjectList(string _name, ListType _type, long _size)
{
name = _name;
type = _type.ToString().ToLower();
size = _size;
}

public ObjectList(string _name, ListType _type)
{
name = _name;
Expand Down
18 changes: 14 additions & 4 deletions Shoko.Server/API/v2/Models/common/Serie.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,17 @@ 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();
roles = new List<Role>();
tags = new List<Tag>();
}

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();

Expand All @@ -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();

Expand All @@ -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)
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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();
}
Expand Down
5 changes: 5 additions & 0 deletions Shoko.Server/API/v2/Models/core/API_Call_Parameters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,5 +100,10 @@ public class API_Call_Parameters
/// show only given number of pictures related to object
/// </summary>
public int pic = 1;

/// <summary>
/// skip some of the information with supported calls
/// </summary>
public int skip = 0;
}
}
78 changes: 78 additions & 0 deletions Shoko.Server/API/v2/Modules/Common.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -1507,6 +1508,26 @@ private object GetSeriesByFolderId()
}
}

/// <summary>
/// Handle /api/serie/infobyfolder
/// </summary>
/// <returns>List<ObjectList> or APIStatus</returns>
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'");
}
}

/// <summary>
/// Handle /api/serie/recent
/// </summary>
Expand Down Expand Up @@ -1692,6 +1713,7 @@ internal object GetSeriesByFolder(int id, int uid, bool nocast, bool notag, int
List<SVR_VideoLocal> vlpall = RepoFactory.VideoLocalPlace.GetByImportFolder(id)
.Select(a => a.VideoLocal)
.ToList();

if (limit == 0)
{
// hardcoded limit
Expand All @@ -1710,6 +1732,62 @@ internal object GetSeriesByFolder(int id, int uid, bool nocast, bool notag, int
return allseries;
}

/// <summary>
/// Return SeriesInfo inside ObjectList that resine inside folder
/// </summary>
/// <param name="id">import folder id</param>
/// <param name="uid">user id</param>
/// <param name="limit"></param>
/// <returns>List<ObjectList></returns>
internal object GetSeriesInfoByFolder(int id, int uid, int limit)
{
Dictionary<string, long> tmp_list = new Dictionary<string, long>();
List<object> allseries = new List<object>();
List<SVR_VideoLocal> 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;
}

/// <summary>
/// Return Serie for given episode
/// </summary>
Expand Down

0 comments on commit 7ff5b32

Please sign in to comment.