Permalink
Browse files

Fix lots of stuff with MyList

  • Loading branch information...
da3dsoul committed Mar 5, 2018
1 parent faa6aac commit bde8518d3629d8d0340942ee6300bae1ac2adbc4
Submodule Shoko.Commons updated 1 files
+1 −1 Shoko.Models
@@ -523,42 +523,13 @@ public void GetUpdated(ref List<int> updatedAnimeIDs, ref long startTime)
}
}

public void UpdateMyListFileStatus(IHash fileDataLocal, bool watched, DateTime? watchedDate)
{
if (!ServerSettings.AniDB_MyList_AddFiles) return;

if (!Login()) return;

lock (lockAniDBConnections)
{
AniDBCommand_UpdateFile cmdUpdateFile = new AniDBCommand_UpdateFile();
cmdUpdateFile.Init(fileDataLocal, watched, watchedDate, true, ServerSettings.AniDB_MyList_StorageState);
SetWaitingOnResponse(true);
enHelperActivityType ev = cmdUpdateFile.Process(ref soUdp, ref remoteIpEndPoint, curSessionID,
new UnicodeEncoding(true, false));
SetWaitingOnResponse(false);
if (ev == enHelperActivityType.NoSuchMyListFile && watched)
{
// the file is not actually on the user list, so let's add it
// we do this by issueing the same command without the edit flag
cmdUpdateFile = new AniDBCommand_UpdateFile();
cmdUpdateFile.Init(fileDataLocal, watched, watchedDate, false,
ServerSettings.AniDB_MyList_StorageState);
SetWaitingOnResponse(true);
cmdUpdateFile.Process(ref soUdp, ref remoteIpEndPoint, curSessionID,
new UnicodeEncoding(true, false));
SetWaitingOnResponse(false);
}
}
}

/// <summary>
/// This is for generic files (manually linked)
/// </summary>
/// <param name="animeID"></param>
/// <param name="episodeNumber"></param>
/// <param name="watched"></param>
public void UpdateMyListFileStatus(int animeID, int episodeNumber, bool watched)
public void UpdateMyListFileStatus(IHash hash, bool watched, DateTime? watchedDate = null)
{
if (!ServerSettings.AniDB_MyList_AddFiles) return;

@@ -567,17 +538,17 @@ public void UpdateMyListFileStatus(int animeID, int episodeNumber, bool watched)
lock (lockAniDBConnections)
{
AniDBCommand_UpdateFile cmdUpdateFile = new AniDBCommand_UpdateFile();
cmdUpdateFile.Init(animeID, episodeNumber, watched, true);
if (watched && watchedDate == null) watchedDate = DateTime.Now;

cmdUpdateFile.Init(hash, watched, watchedDate);
SetWaitingOnResponse(true);
enHelperActivityType ev = cmdUpdateFile.Process(ref soUdp, ref remoteIpEndPoint, curSessionID,
new UnicodeEncoding(true, false));
SetWaitingOnResponse(false);
if (ev == enHelperActivityType.NoSuchMyListFile && watched)
{
// the file is not actually on the user list, so let's add it
// we do this by issueing the same command without the edit flag
cmdUpdateFile = new AniDBCommand_UpdateFile();
cmdUpdateFile.Init(animeID, episodeNumber, watched, false);
AniDBFile_State? state = null;
AddFileToMyList(hash, ref watchedDate, ref state);
SetWaitingOnResponse(true);
cmdUpdateFile.Process(ref soUdp, ref remoteIpEndPoint, curSessionID,
new UnicodeEncoding(true, false));
@@ -586,11 +557,11 @@ public void UpdateMyListFileStatus(int animeID, int episodeNumber, bool watched)
}
}

public bool AddFileToMyList(IHash fileDataLocal, ref DateTime? watchedDate, ref AniDBFile_State? state)
public (int?, bool?) AddFileToMyList(IHash fileDataLocal, ref DateTime? watchedDate, ref AniDBFile_State? state)
{
if (!ServerSettings.AniDB_MyList_AddFiles) return false;
if (!ServerSettings.AniDB_MyList_AddFiles) return (null, false);

if (!Login()) return false;
if (!Login()) return (null, false);

enHelperActivityType ev;
AniDBCommand_AddFile cmdAddFile;
@@ -610,15 +581,17 @@ public bool AddFileToMyList(IHash fileDataLocal, ref DateTime? watchedDate, ref
{
watchedDate = cmdAddFile.WatchedDate;
state = cmdAddFile.State;
return cmdAddFile.ReturnIsWatched;
return (cmdAddFile.MyListID, cmdAddFile.ReturnIsWatched);
}

return false;
if (cmdAddFile.MyListID > 0) return (cmdAddFile.MyListID, false);

return (null, false);
}

public bool? AddFileToMyList(int animeID, int episodeNumber, ref DateTime? watchedDate)
public (int?, bool?) AddFileToMyList(int animeID, int episodeNumber, ref DateTime? watchedDate)
{
if (!Login()) return null;
if (!Login()) return (null, null);

enHelperActivityType ev;
AniDBCommand_AddFile cmdAddFile;
@@ -637,126 +610,114 @@ public bool AddFileToMyList(IHash fileDataLocal, ref DateTime? watchedDate, ref
if (ev == enHelperActivityType.FileAlreadyExists && cmdAddFile.FileData != null && ServerSettings.AniDB_MyList_ReadWatched)
{
watchedDate = cmdAddFile.WatchedDate;
return cmdAddFile.ReturnIsWatched;
return (cmdAddFile.MyListID, cmdAddFile.ReturnIsWatched);
}
if (ServerSettings.AniDB_MyList_ReadUnwatched) return false;
if (ServerSettings.AniDB_MyList_ReadUnwatched) return (cmdAddFile.MyListID, false);

return null;
}

internal void MarkFileAsExternalStorage(string Hash, long FileSize)
{
if (!Login()) return;
if (cmdAddFile.MyListID > 0)
return (cmdAddFile.MyListID, null);

lock (lockAniDBConnections)
{
var cmdMarkFileExternal = new AniDBCommand_MarkFileAsExternal();
cmdMarkFileExternal.Init(Hash, FileSize);
SetWaitingOnResponse(true);
cmdMarkFileExternal.Process(ref soUdp, ref remoteIpEndPoint, curSessionID,
new UnicodeEncoding(true, false));
SetWaitingOnResponse(false);
}
return (null, null);
}

internal void MarkFileAsExternalStorage(int fileID)
internal void MarkFileAsRemote(int myListID)
{
if (!Login()) return;

lock (lockAniDBConnections)
{
var cmdMarkFileExternal = new AniDBCommand_MarkFileAsExternal();
cmdMarkFileExternal.Init(fileID);
var cmdMarkFileExternal = new AniDBCommand_MarkFileAsRemote();
cmdMarkFileExternal.Init(myListID);
SetWaitingOnResponse(true);
cmdMarkFileExternal.Process(ref soUdp, ref remoteIpEndPoint, curSessionID,
new UnicodeEncoding(true, false));
SetWaitingOnResponse(false);
}
}

internal void MarkFileAsOnDisk(string Hash, long FileSize)
internal void MarkFileAsOnDisk(IHash hash)
{
if (!Login()) return;

lock (lockAniDBConnections)
{
var cmdMarkFileDisk = new AniDBCommand_MarkFileAsDisk();
cmdMarkFileDisk.Init(Hash, FileSize);
cmdMarkFileDisk.Init(hash.MyListID);
SetWaitingOnResponse(true);
cmdMarkFileDisk.Process(ref soUdp, ref remoteIpEndPoint, curSessionID,
new UnicodeEncoding(true, false));
SetWaitingOnResponse(false);
}
}

internal void MarkFileAsOnDisk(int fileID)
internal void MarkFileAsOnDisk(int myListID)
{
if (!Login()) return;

lock (lockAniDBConnections)
{
var cmdMarkFileDisk = new AniDBCommand_MarkFileAsDisk();
cmdMarkFileDisk.Init(fileID);
cmdMarkFileDisk.Init(myListID);
SetWaitingOnResponse(true);
cmdMarkFileDisk.Process(ref soUdp, ref remoteIpEndPoint, curSessionID,
new UnicodeEncoding(true, false));
SetWaitingOnResponse(false);
}
}

public void MarkFileAsUnknown(string Hash, long FileSize)
public void MarkFileAsUnknown(IHash hash)
{
if (!Login()) return;

lock (lockAniDBConnections)
{
var cmdMarkFileUnknown = new AniDBCommand_MarkFileAsUnknown();
cmdMarkFileUnknown.Init(Hash, FileSize);
cmdMarkFileUnknown.Init(hash.MyListID);
SetWaitingOnResponse(true);
cmdMarkFileUnknown.Process(ref soUdp, ref remoteIpEndPoint, curSessionID,
new UnicodeEncoding(true, false));
SetWaitingOnResponse(false);
}
}

public void MarkFileAsUnknown(int fileID)
public void MarkFileAsUnknown(int myListID)
{
if (!Login()) return;

lock (lockAniDBConnections)
{
var cmdMarkFileUnknown = new AniDBCommand_MarkFileAsUnknown();
cmdMarkFileUnknown.Init(fileID);
cmdMarkFileUnknown.Init(myListID);
SetWaitingOnResponse(true);
cmdMarkFileUnknown.Process(ref soUdp, ref remoteIpEndPoint, curSessionID,
new UnicodeEncoding(true, false));
SetWaitingOnResponse(false);
}
}

public void MarkFileAsDeleted(string hash, long fileSize)
public void MarkFileAsDeleted(IHash hash)
{
if (!Login()) return;

lock (lockAniDBConnections)
{
var cmdDelFile = new AniDBCommand_MarkFileAsDeleted();
cmdDelFile.Init(hash, fileSize);
cmdDelFile.Init(hash.MyListID);
SetWaitingOnResponse(true);
cmdDelFile.Process(ref soUdp, ref remoteIpEndPoint, curSessionID,
new UnicodeEncoding(true, false));
SetWaitingOnResponse(false);
}
}

public void MarkFileAsDeleted(int fileID)
public void MarkFileAsDeleted(int myListID)
{
if (!Login()) return;

lock (lockAniDBConnections)
{
var cmdDelFile = new AniDBCommand_MarkFileAsDeleted();
cmdDelFile.Init(fileID);
cmdDelFile.Init(myListID);
SetWaitingOnResponse(true);
cmdDelFile.Process(ref soUdp, ref remoteIpEndPoint, curSessionID,
new UnicodeEncoding(true, false));
@@ -2,6 +2,7 @@
using System.Net;
using System.Net.Sockets;
using System.Text;
using Shoko.Models.Enums;
using Shoko.Models.Interfaces;

namespace AniDBAPI.Commands
@@ -12,6 +13,7 @@ public class AniDBCommand_AddFile : AniDBUDPCommand, IAniDBUDPCommand
public bool ReturnIsWatched = false;
public DateTime? WatchedDate = null;
public AniDBFile_State? State = null;
public int MyListID;

public string GetKey()
{
@@ -47,6 +49,8 @@ public virtual enHelperActivityType GetStartEventType()
if (arrResult.Length >= 2)
{
string[] arrStatus = arrResult[1].Split('|');
int.TryParse(arrStatus[0], out MyListID);

int state = int.Parse(arrStatus[6]);
State = (AniDBFile_State) state;

@@ -65,8 +69,8 @@ public virtual enHelperActivityType GetStartEventType()
WatchedDate = null;
}
}
}
return enHelperActivityType.FileAlreadyExists;
}
case "311": return enHelperActivityType.UpdatingFile;
case "320": return enHelperActivityType.NoSuchFile;
case "411": return enHelperActivityType.NoSuchFile;
@@ -93,45 +93,12 @@ public void Init(IHash fileData, bool force)
commandID = fileData.Info;
// 220 FILE572794|6107|99294|2723|c646d82a184a33f4e4f98af39f29a044|8452c4bf|high|HDTV|Vorbis (Ogg Vorbis)|148|H264/AVC|1773|1280x720|mkv|1470||1239494400|2|The Day It Began|Hajimari no Hi|712|14|Eclipse Productions|Eclipse


commandText = "FILE size=" + fileData.FileSize.ToString();
commandText += "&ed2k=" + fileData.ED2KHash;
commandText += string.Format("&fmask={0}{1}{2}{3}{4}", fByte1.ToString("X").PadLeft(2, '0'),
fByte2.ToString("X").PadLeft(2, '0'), fByte3.ToString("X").PadLeft(2, '0'),
fByte4.ToString("X").PadLeft(2, '0'),
fByte5.ToString("X").PadLeft(2, '0'));
commandText += string.Format("&amask={0}{1}{2}{3}", aByte1.ToString("X").PadLeft(2, '0'),
aByte2.ToString("X").PadLeft(2, '0'), aByte3.ToString("X").PadLeft(2, '0'),
aByte4.ToString("X").PadLeft(2, '0'));
commandText +=
$"&fmask={fByte1.ToString("X").PadLeft(2, '0')}{fByte2.ToString("X").PadLeft(2, '0')}{fByte3.ToString("X").PadLeft(2, '0')}{fByte4.ToString("X").PadLeft(2, '0')}{fByte5.ToString("X").PadLeft(2, '0')}";
commandText +=
$"&amask={aByte1.ToString("X").PadLeft(2, '0')}{aByte2.ToString("X").PadLeft(2, '0')}{aByte3.ToString("X").PadLeft(2, '0')}{aByte4.ToString("X").PadLeft(2, '0')}";
}

/*public void Init(IHash fileData, bool force)
{
int fByte1 = 124; // fmask - byte1 (old 120 Added other episodes)
int fByte2 = 248; // old 72 fmask - byte2 (Added FileSize, SHA1, MD5)
int fByte3 = 255; // fmask - byte3
int fByte4 = 249; // fmask - byte4
int aByte1 = 0; // amask - byte1
int aByte2 = 0; // amask - byte2
int aByte3 = 252; // amask - byte3 old 236 Added Kanji name
int aByte4 = 192; // amask - byte4
this.fileData = fileData;
this.forceRefresh = force;
commandID = fileData.Info;
// 220 FILE572794|6107|99294|2723|c646d82a184a33f4e4f98af39f29a044|8452c4bf|high|HDTV|Vorbis (Ogg Vorbis)|148|H264/AVC|1773|1280x720|mkv|1470||1239494400|2|The Day It Began|Hajimari no Hi|712|14|Eclipse Productions|Eclipse
commandText = "FILE size=" + fileData.FileSize.ToString();
commandText += "&ed2k=" + fileData.ED2KHash;
commandText += string.Format("&fmask={0}{1}{2}{3}", fByte1.ToString("X").PadLeft(2, '0'),
fByte2.ToString("X").PadLeft(2, '0'), fByte3.ToString("X").PadLeft(2, '0'), fByte4.ToString("X").PadLeft(2, '0'));
commandText += string.Format("&amask={0}{1}{2}{3}", aByte1.ToString("X").PadLeft(2, '0'),
aByte2.ToString("X").PadLeft(2, '0'), aByte3.ToString("X").PadLeft(2, '0'), aByte4.ToString("X").PadLeft(2, '0'));
}*/
}
}
@@ -1,17 +1,17 @@
using System.Net;
using System.Net.Sockets;
using System.Text;
using Shoko.Models.Enums;

namespace AniDBAPI.Commands
{
public class AniDBCommand_MarkFileAsDeleted : AniDBUDPCommand, IAniDBUDPCommand
{
public string Hash = string.Empty;
public int FileID = 0;
public int MyListID;

public string GetKey()
{
return "AniDBCommand_MarkFileAsDeleted" + (FileID != 0 ? "F" + FileID : Hash);
return "AniDBCommand_MarkFileAsDeleted_" + MyListID;
}

public virtual enHelperActivityType GetStartEventType()
@@ -54,23 +54,12 @@ public AniDBCommand_MarkFileAsDeleted()
commandType = enAniDBCommandType.MarkFileDeleted;
}

public void Init(string hash, long fileSize)
public void Init(int lid)
{
Hash = hash;
commandID = "Deleting File: " + hash;
MyListID = lid;
commandID = "Deleting File: " + lid;

commandText = "MYLISTADD size=" + fileSize;
commandText += "&ed2k=" + hash;
commandText += "&state=" + (int) AniDBFile_State.Deleted;
commandText += "&edit=1";
}

public void Init(int fileID)
{
FileID = fileID;
commandID = "Deleting File: F" + fileID;

commandText = "MYLISTADD fid=" + fileID;
commandText = "MYLISTADD lid=" + lid;
commandText += "&state=" + (int) AniDBFile_State.Deleted;
commandText += "&edit=1";
}
Oops, something went wrong.

0 comments on commit bde8518

Please sign in to comment.