Skip to content
Permalink
Browse files

Download new anime data first. List not completely imported files in …

…Unrecognized for now
  • Loading branch information...
da3dsoul committed Jan 24, 2019
1 parent 2fdecd1 commit 939b132638db434d12bb9e9f4cd5e50b675dab27
@@ -1,123 +1,126 @@
using System;
using System.Xml;
using Shoko.Commons.Queue;
using Shoko.Models.Queue;
using Shoko.Models.Server;
using Shoko.Server.Models;

namespace Shoko.Server.Commands
{
[Serializable]
[Command(CommandRequestType.AniDB_GetAnimeHTTP)]
public class CommandRequest_GetAnimeHTTP : CommandRequestImplementation
{
public int AnimeID { get; set; }
public bool ForceRefresh { get; set; }
public bool DownloadRelations { get; set; }

public override CommandRequestPriority DefaultPriority => CommandRequestPriority.Priority2;

public override QueueStateStruct PrettyDescription => new QueueStateStruct
{
queueState = QueueStateEnum.AnimeInfo,
extraParams = new[] {AnimeID.ToString()}
};

public int RelDepth { get; set; } = 0;

public CommandRequest_GetAnimeHTTP()
{
}

public CommandRequest_GetAnimeHTTP(int animeid, bool forced, bool downloadRelations) : this(animeid, forced, downloadRelations, 0)
{ }


public CommandRequest_GetAnimeHTTP(int animeid, bool forced, bool downloadRelations, int relDepth)
{
AnimeID = animeid;
DownloadRelations = downloadRelations;
ForceRefresh = forced;
Priority = (int) DefaultPriority;
RelDepth = relDepth;

GenerateCommandID();
}

public override void ProcessCommand()
{
logger.Info("Processing CommandRequest_GetAnimeHTTP: {0}", AnimeID);

try
{
SVR_AniDB_Anime anime =
ShokoService.AnidbProcessor.GetAnimeInfoHTTP(AnimeID, ForceRefresh, DownloadRelations, RelDepth);

// NOTE - related anime are downloaded when the relations are created

// download group status info for this anime
// the group status will also help us determine missing episodes for a series


// download reviews
if (ServerSettings.AniDB_DownloadReviews)
{
CommandRequest_GetReviews cmd = new CommandRequest_GetReviews(AnimeID, ForceRefresh);
cmd.Save();
}

// Request an image download
}
catch (Exception ex)
{
logger.Error("Error processing CommandRequest_GetAnimeHTTP: {0} - {1}", AnimeID, ex);
}
}

public override void GenerateCommandID()
{
CommandID = $"CommandRequest_GetAnimeHTTP_{AnimeID}";
}

public override bool LoadFromDBCommand(CommandRequest cq)
{
CommandID = cq.CommandID;
CommandRequestID = cq.CommandRequestID;
Priority = cq.Priority;
CommandDetails = cq.CommandDetails;
DateTimeUpdated = cq.DateTimeUpdated;

// read xml to get parameters
if (CommandDetails.Trim().Length > 0)
{
XmlDocument docCreator = new XmlDocument();
docCreator.LoadXml(CommandDetails);

// populate the fields
AnimeID = int.Parse(TryGetProperty(docCreator, "CommandRequest_GetAnimeHTTP", "AnimeID"));
DownloadRelations =
bool.Parse(TryGetProperty(docCreator, "CommandRequest_GetAnimeHTTP", "DownloadRelations"));
ForceRefresh = bool.Parse(
TryGetProperty(docCreator, "CommandRequest_GetAnimeHTTP", "ForceRefresh"));
RelDepth = int.Parse(TryGetProperty(docCreator, nameof(CommandRequest_GetAnimeHTTP), nameof(RelDepth)));
}

return true;
}

public override CommandRequest ToDatabaseObject()
{
GenerateCommandID();

CommandRequest cq = new CommandRequest
{
CommandID = CommandID,
CommandType = CommandType,
Priority = Priority,
CommandDetails = ToXML(),
DateTimeUpdated = DateTime.Now
};
return cq;
}
}
using System;
using System.Xml;
using Shoko.Commons.Queue;
using Shoko.Models.Queue;
using Shoko.Models.Server;
using Shoko.Server.Models;
using Shoko.Server.Repositories;

namespace Shoko.Server.Commands
{
[Serializable]
[Command(CommandRequestType.AniDB_GetAnimeHTTP)]
public class CommandRequest_GetAnimeHTTP : CommandRequestImplementation
{
public int AnimeID { get; set; }
public bool ForceRefresh { get; set; }
public bool DownloadRelations { get; set; }

public override CommandRequestPriority DefaultPriority => CommandRequestPriority.Priority2;

public override QueueStateStruct PrettyDescription => new QueueStateStruct
{
queueState = QueueStateEnum.AnimeInfo,
extraParams = new[] {AnimeID.ToString()}
};

public int RelDepth { get; set; } = 0;

public CommandRequest_GetAnimeHTTP()
{
}

public CommandRequest_GetAnimeHTTP(int animeid, bool forced, bool downloadRelations) : this(animeid, forced, downloadRelations, 0)
{ }


public CommandRequest_GetAnimeHTTP(int animeid, bool forced, bool downloadRelations, int relDepth)
{
AnimeID = animeid;
DownloadRelations = downloadRelations;
ForceRefresh = forced;
Priority = (int) DefaultPriority;
if (RepoFactory.AniDB_Anime.GetByAnimeID(animeid) == null) Priority = (int) CommandRequestPriority.Priority1;
RelDepth = relDepth;

GenerateCommandID();
}

public override void ProcessCommand()
{
logger.Info("Processing CommandRequest_GetAnimeHTTP: {0}", AnimeID);

try
{
SVR_AniDB_Anime anime =
ShokoService.AnidbProcessor.GetAnimeInfoHTTP(AnimeID, ForceRefresh, DownloadRelations, RelDepth);

// NOTE - related anime are downloaded when the relations are created

// download group status info for this anime
// the group status will also help us determine missing episodes for a series


// download reviews
if (ServerSettings.AniDB_DownloadReviews)
{
CommandRequest_GetReviews cmd = new CommandRequest_GetReviews(AnimeID, ForceRefresh);
cmd.Save();
}

// Request an image download
}
catch (Exception ex)
{
logger.Error("Error processing CommandRequest_GetAnimeHTTP: {0} - {1}", AnimeID, ex);
}
}

public override void GenerateCommandID()
{
CommandID = $"CommandRequest_GetAnimeHTTP_{AnimeID}";
}

public override bool LoadFromDBCommand(CommandRequest cq)
{
CommandID = cq.CommandID;
CommandRequestID = cq.CommandRequestID;
Priority = cq.Priority;
CommandDetails = cq.CommandDetails;
DateTimeUpdated = cq.DateTimeUpdated;

// read xml to get parameters
if (CommandDetails.Trim().Length > 0)
{
XmlDocument docCreator = new XmlDocument();
docCreator.LoadXml(CommandDetails);

// populate the fields
AnimeID = int.Parse(TryGetProperty(docCreator, "CommandRequest_GetAnimeHTTP", "AnimeID"));
if (RepoFactory.AniDB_Anime.GetByAnimeID(AnimeID) == null) Priority = (int) CommandRequestPriority.Priority1;
DownloadRelations =
bool.Parse(TryGetProperty(docCreator, "CommandRequest_GetAnimeHTTP", "DownloadRelations"));
ForceRefresh = bool.Parse(
TryGetProperty(docCreator, "CommandRequest_GetAnimeHTTP", "ForceRefresh"));
RelDepth = int.Parse(TryGetProperty(docCreator, nameof(CommandRequest_GetAnimeHTTP), nameof(RelDepth)));
}

return true;
}

public override CommandRequest ToDatabaseObject()
{
GenerateCommandID();

CommandRequest cq = new CommandRequest
{
CommandID = CommandID,
CommandType = CommandType,
Priority = Priority,
CommandDetails = ToXML(),
DateTimeUpdated = DateTime.Now
};
return cq;
}
}
}
@@ -432,7 +432,13 @@ public List<SVR_VideoLocal> GetVideosWithoutEpisode()
lock (Cache)
{
return Cache.Values
.Where(a => a.IsIgnored == 0 && !RepoFactory.CrossRef_File_Episode.GetByHash(a.Hash).Any())
.Where(a =>
{
if (a.IsIgnored != 0) return false;
var xrefs = RepoFactory.CrossRef_File_Episode.GetByHash(a.Hash);
if (!xrefs.Any()) return true;
return RepoFactory.AniDB_Anime.GetByAnimeID(xrefs.FirstOrDefault().AnimeID) == null;
})
.OrderByNatural(local => local?.GetBestVideoLocalPlace()?.FilePath)
.ThenBy(local => local?.VideoLocalID ?? 0)
.ToList();

0 comments on commit 939b132

Please sign in to comment.
You can’t perform that action at this time.