Ejemplo n.º 1
0
        public void Init(int animeID, int episodeNumber, AniDBFile_State fileState)
        {
            // MYLISTADD aid={int4 aid}&generic=1&epno={int4 episode number}

            commandText  = "MYLISTADD aid=" + animeID;
            commandText += "&generic=1";
            commandText += "&epno=" + episodeNumber;
            commandText += "&viewed=0";
            commandText += "&state=" + (int)fileState;
        }
Ejemplo n.º 2
0
        public void Init(IHash fileData, AniDBFile_State fileState)
        {
            FileData = fileData;

            commandID = fileData.Info;

            commandText  = "MYLISTADD size=" + fileData.FileSize;
            commandText += "&ed2k=" + fileData.ED2KHash;
            commandText += "&viewed=0";
            commandText += "&state=" + (int)fileState;
        }
Ejemplo n.º 3
0
        public void Init(int animeID, string episodeData, AniDBFile_State fileState, DateTime?watchedDate = null)
        {
            // MYLISTADD aid={int4 aid}&generic=1&epno={int4 episode number}

            commandText  = "MYLISTADD aid=" + animeID;
            commandText += "&generic=1";
            commandText += "&epno=" + episodeData;
            if (watchedDate == null)
            {
                commandText += "&viewed=0";
            }
            else
            {
                commandText += "&viewed=1";
                commandText += "&viewdate=" + Commons.Utils.AniDB.GetAniDBDateAsSeconds(watchedDate.Value);
            }
            commandText += "&state=" + (int)fileState;
        }
Ejemplo n.º 4
0
        public void Init(IHash fileData, AniDBFile_State fileState, DateTime?watchedDate = null)
        {
            FileData = fileData;

            commandID = fileData.Info;

            commandText  = "MYLISTADD size=" + fileData.FileSize;
            commandText += "&ed2k=" + fileData.ED2KHash;
            if (watchedDate == null)
            {
                commandText += "&viewed=0";
            }
            else
            {
                commandText += "&viewed=1";
                commandText += "&viewdate=" + Commons.Utils.AniDB.GetAniDBDateAsSeconds(watchedDate.Value);
            }
            commandText += "&state=" + (int)fileState;
        }
Ejemplo n.º 5
0
        protected override UDPBaseResponse <ResponseAddFile> ParseResponse(AniDBUDPReturnCode code, string receivedData)
        {
            switch (code)
            {
            case AniDBUDPReturnCode.MYLIST_ENTRY_ADDED:
            {
                /* Response Format
                 * {int4 mylist id of new entry}
                 */
                // parse the MyList ID
                string[] arrResult = receivedData.Split('\n');
                if (arrResult.Length >= 2)
                {
                    int.TryParse(arrResult[1], out int myListID);
                    return(new UDPBaseResponse <ResponseAddFile>
                        {
                            Code = code,
                            Response = new ResponseAddFile
                            {
                                MyListID = myListID,
                                State = State,
                                IsWatched = IsWatched,
                                WatchedDate = WatchedDate
                            }
                        });
                }
                break;
            }

            case AniDBUDPReturnCode.FILE_ALREADY_IN_MYLIST:
            {
                /* Response Format
                 * {int4 lid}|{int4 fid}|{int4 eid}|{int4 aid}|{int4 gid}|{int4 date}|{int2 state}|{int4 viewdate}|{str storage}|{str source}|{str other}|{int2 filestate}
                 */
                //file already exists: read 'watched' status
                string[] arrResult = receivedData.Split('\n');
                if (arrResult.Length >= 2)
                {
                    string[] arrStatus   = arrResult[1].Split('|');
                    bool     hasMyListID = int.TryParse(arrStatus[0], out int myListID);
                    if (!hasMyListID)
                    {
                        throw new UnexpectedAniDBResponseException
                              {
                                  Message    = "MyListID was not provided. Use AniDBMyList_RequestAddEpisode for generic files.",
                                  Response   = receivedData,
                                  ReturnCode = code
                              }
                    }
                    ;


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

                    int  viewdate = int.Parse(arrStatus[7]);
                    bool watched  = viewdate > 0;

                    DateTime?watchedDate = null;
                    if (watched)
                    {
                        DateTime utcDate = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
                        utcDate = utcDate.AddSeconds(viewdate);

                        watchedDate = utcDate.ToLocalTime();
                    }

                    return(new UDPBaseResponse <ResponseAddFile>
                        {
                            Code = code,
                            Response = new ResponseAddFile
                            {
                                MyListID = myListID,
                                State = state,
                                IsWatched = watched,
                                WatchedDate = watchedDate
                            }
                        });
                }
                break;
            }
            }
            throw new UnexpectedAniDBResponseException(code, receivedData);
        }
    }