Esempio n. 1
0
        private static void WriteStructValue(XmlWriter XMLwrt, XmlRpcValueStruct val)
        {
            XMLwrt.WriteStartElement("value");  //value
            XMLwrt.WriteStartElement("struct"); //struct
            foreach (XmlRpcStructMember member in val.Members)
            {
                XMLwrt.WriteStartElement("member"); //member

                XMLwrt.WriteStartElement("name");   //name
                XMLwrt.WriteString(member.Name);
                XMLwrt.WriteEndElement();           //name

                if (member.Data is XmlRpcValueBasic)
                {
                    WriteBasicValue(XMLwrt, (XmlRpcValueBasic)member.Data);
                }
                else if (member.Data is XmlRpcValueStruct)
                {
                    WriteStructValue(XMLwrt, (XmlRpcValueStruct)member.Data);
                }
                else if (member.Data is XmlRpcValueArray)
                {
                    WriteArrayValue(XMLwrt, (XmlRpcValueArray)member.Data);
                }

                XMLwrt.WriteEndElement(); //member
            }
            XMLwrt.WriteEndElement();     //struct
            XMLwrt.WriteEndElement();     //value
        }
Esempio n. 2
0
        private static IXmlRpcValue ReadValue(XmlReader xmlReader)
        {
            while (xmlReader.Read())
            {
                if (xmlReader.Name == "value" && xmlReader.IsStartElement())
                {
                    xmlReader.Read();
                    if (xmlReader.Name == "string" && xmlReader.IsStartElement())
                    {
                        return(new XmlRpcValueBasic(xmlReader.ReadString(), XmlRpcBasicValueType.String));
                    }
                    else if (xmlReader.Name == "int" && xmlReader.IsStartElement())
                    {
                        return(new XmlRpcValueBasic(int.Parse(xmlReader.ReadString(), UsCulture), XmlRpcBasicValueType.Int));
                    }
                    else if (xmlReader.Name == "boolean" && xmlReader.IsStartElement())
                    {
                        return(new XmlRpcValueBasic(xmlReader.ReadString() == "1", XmlRpcBasicValueType.Boolean));
                    }
                    else if (xmlReader.Name == "double" && xmlReader.IsStartElement())
                    {
                        return(new XmlRpcValueBasic(double.Parse(xmlReader.ReadString(), UsCulture), XmlRpcBasicValueType.Double));
                    }
                    else if (xmlReader.Name == "dateTime.iso8601" && xmlReader.IsStartElement())
                    {
                        string   date   = xmlReader.ReadString();
                        int      year   = int.Parse(date.Substring(0, 4), UsCulture);
                        int      month  = int.Parse(date.Substring(4, 2), UsCulture);
                        int      day    = int.Parse(date.Substring(6, 2), UsCulture);
                        int      hour   = int.Parse(date.Substring(9, 2), UsCulture);
                        int      minute = int.Parse(date.Substring(12, 2), UsCulture);//19980717T14:08:55
                        int      sec    = int.Parse(date.Substring(15, 2), UsCulture);
                        DateTime time   = new DateTime(year, month, day, hour, minute, sec);
                        return(new XmlRpcValueBasic(time, XmlRpcBasicValueType.dateTime_iso8601));
                    }
                    else if (xmlReader.Name == "base64" && xmlReader.IsStartElement())
                    {
                        return(new XmlRpcValueBasic(BitConverter.ToInt64(Convert.FromBase64String(xmlReader.ReadString()), 0)
                                                    , XmlRpcBasicValueType.Double));
                    }
                    else if (xmlReader.Name == "struct" && xmlReader.IsStartElement())
                    {
                        XmlRpcValueStruct strct = new XmlRpcValueStruct(new List <XmlRpcStructMember>());
                        // Read members...
                        while (xmlReader.Read())
                        {
                            if (xmlReader.Name == "member" && xmlReader.IsStartElement())
                            {
                                XmlRpcStructMember member = new XmlRpcStructMember("", null);
                                xmlReader.Read();// read name
                                member.Name = xmlReader.ReadString();

                                IXmlRpcValue val = ReadValue(xmlReader);
                                if (val != null)
                                {
                                    member.Data = val;
                                    strct.Members.Add(member);
                                }
                            }
                            else if (xmlReader.Name == "struct" && !xmlReader.IsStartElement())
                            {
                                return(strct);
                            }
                        }
                        return(strct);
                    }
                    else if (xmlReader.Name == "array" && xmlReader.IsStartElement())
                    {
                        XmlRpcValueArray array = new XmlRpcValueArray();
                        // Read members...
                        while (xmlReader.Read())
                        {
                            if (xmlReader.Name == "array" && !xmlReader.IsStartElement())
                            {
                                return(array);
                            }
                            else
                            {
                                IXmlRpcValue val = ReadValue(xmlReader);
                                if (val != null)
                                {
                                    array.Values.Add(val);
                                }
                            }
                        }
                        return(array);
                    }
                }
                else
                {
                    break;
                }
            }
            return(null);
        }
Esempio n. 3
0
        private static IXmlRpcValue ReadValue(XmlReader xmlReader)
        {
            while (xmlReader.Read())
            {
                if (xmlReader.Name == "value" && xmlReader.IsStartElement())
                {
                    xmlReader.Read();
                    if (xmlReader.Name == "string" && xmlReader.IsStartElement())
                    {
                        return new XmlRpcValueBasic(xmlReader.ReadString(), XmlRpcBasicValueType.String);
                    }
                    else if (xmlReader.Name == "int" && xmlReader.IsStartElement())
                    {
                        return new XmlRpcValueBasic(int.Parse(xmlReader.ReadString(), UsCulture), XmlRpcBasicValueType.Int);
                    }
                    else if (xmlReader.Name == "boolean" && xmlReader.IsStartElement())
                    {
                        return new XmlRpcValueBasic(xmlReader.ReadString() == "1", XmlRpcBasicValueType.Boolean);
                    }
                    else if (xmlReader.Name == "double" && xmlReader.IsStartElement())
                    {
                        return new XmlRpcValueBasic(double.Parse(xmlReader.ReadString(), UsCulture), XmlRpcBasicValueType.Double);
                    }
                    else if (xmlReader.Name == "dateTime.iso8601" && xmlReader.IsStartElement())
                    {
                        string date = xmlReader.ReadString();
                        int year = int.Parse(date.Substring(0, 4), UsCulture);
                        int month = int.Parse(date.Substring(4, 2), UsCulture);
                        int day = int.Parse(date.Substring(6, 2), UsCulture);
                        int hour = int.Parse(date.Substring(9, 2), UsCulture);
                        int minute = int.Parse(date.Substring(12, 2), UsCulture);//19980717T14:08:55
                        int sec = int.Parse(date.Substring(15, 2), UsCulture);
                        DateTime time = new DateTime(year, month, day, hour, minute, sec);
                        return new XmlRpcValueBasic(time, XmlRpcBasicValueType.dateTime_iso8601);
                    }
                    else if (xmlReader.Name == "base64" && xmlReader.IsStartElement())
                    {
                        return new XmlRpcValueBasic(BitConverter.ToInt64(Convert.FromBase64String(xmlReader.ReadString()), 0)
                            , XmlRpcBasicValueType.Double);
                    }
                    else if (xmlReader.Name == "struct" && xmlReader.IsStartElement())
                    {
                        XmlRpcValueStruct strct = new XmlRpcValueStruct(new List<XmlRpcStructMember>());
                        // Read members...
                        while (xmlReader.Read())
                        {
                            if (xmlReader.Name == "member" && xmlReader.IsStartElement())
                            {
                                XmlRpcStructMember member = new XmlRpcStructMember("", null);
                                xmlReader.Read();// read name
                                member.Name = xmlReader.ReadString();

                                IXmlRpcValue val = ReadValue(xmlReader);
                                if (val != null)
                                {
                                    member.Data = val;
                                    strct.Members.Add(member);
                                }
                            }
                            else if (xmlReader.Name == "struct" && !xmlReader.IsStartElement())
                            {
                                return strct;
                            }
                        }
                        return strct;
                    }
                    else if (xmlReader.Name == "array" && xmlReader.IsStartElement())
                    {
                        XmlRpcValueArray array = new XmlRpcValueArray();
                        // Read members...
                        while (xmlReader.Read())
                        {
                            if (xmlReader.Name == "array" && !xmlReader.IsStartElement())
                            {
                                return array;
                            }
                            else
                            {
                                IXmlRpcValue val = ReadValue(xmlReader);
                                if (val != null)
                                    array.Values.Add(val);
                            }
                        }
                        return array;
                    }
                }
                else break;
            }
            return null;
        }
Esempio n. 4
0
 public XmlRpcValueArray(XmlRpcValueStruct[] structs) :
     base()
 {
     values = new List<IXmlRpcValue>();
     foreach (XmlRpcValueStruct val in structs)
     {
         values.Add(val);
     }
 }
Esempio n. 5
0
        private static void WriteStructValue(XmlWriter XMLwrt, XmlRpcValueStruct val)
        {
            XMLwrt.WriteStartElement("value");//value
            XMLwrt.WriteStartElement("struct");//struct
            foreach (XmlRpcStructMember member in val.Members)
            {
                XMLwrt.WriteStartElement("member");//member

                XMLwrt.WriteStartElement("name");//name
                XMLwrt.WriteString(member.Name);
                XMLwrt.WriteEndElement();//name

                if (member.Data is XmlRpcValueBasic)
                {
                    WriteBasicValue(XMLwrt, (XmlRpcValueBasic)member.Data);
                }
                else if (member.Data is XmlRpcValueStruct)
                {
                    WriteStructValue(XMLwrt, (XmlRpcValueStruct)member.Data);
                }
                else if (member.Data is XmlRpcValueArray)
                {
                    WriteArrayValue(XMLwrt, (XmlRpcValueArray)member.Data);
                }

                XMLwrt.WriteEndElement();//member
            }
            XMLwrt.WriteEndElement();//struct
            XMLwrt.WriteEndElement();//value
        }
Esempio n. 6
0
        public static async Task<IMethodResponse> SearchSubtitlesAsync(SubtitleSearchParameters[] parameters, CancellationToken cancellationToken)
        {
            if (TOKEN == "")
            {
                OSHConsole.WriteLine("Can't do this call, 'token' value not set. Please use Log In method first.", DebugCode.Error);
                return new MethodResponseError("Fail", "Can't do this call, 'token' value not set. Please use Log In method first.");
            }
            if (parameters == null)
            {
                OSHConsole.UpdateLine("No subtitle search parameter passed !!", DebugCode.Error);
                return new MethodResponseError("Fail", "No subtitle search parameter passed"); ;
            }
            if (parameters.Length == 0)
            {
                OSHConsole.UpdateLine("No subtitle search parameter passed !!", DebugCode.Error);
                return new MethodResponseError("Fail", "No subtitle search parameter passed"); ;
            }
            // Method call ..
            List<IXmlRpcValue> parms = new List<IXmlRpcValue>();
            // Add token param
            parms.Add(new XmlRpcValueBasic(TOKEN, XmlRpcBasicValueType.String));
            // Add subtitle search parameters. Each one will be like 'array' of structs.
            XmlRpcValueArray array = new XmlRpcValueArray();
            foreach (SubtitleSearchParameters param in parameters)
            {
                XmlRpcValueStruct strct = new XmlRpcValueStruct(new List<XmlRpcStructMember>());
                // sublanguageid member
                XmlRpcStructMember member = new XmlRpcStructMember("sublanguageid",
                    new XmlRpcValueBasic(param.SubLangaugeID, XmlRpcBasicValueType.String));
                strct.Members.Add(member);
                // moviehash member
                if (param.MovieHash.Length > 0 && param.MovieByteSize > 0)
                {
                    member = new XmlRpcStructMember("moviehash",
                        new XmlRpcValueBasic(param.MovieHash, XmlRpcBasicValueType.String));
                    strct.Members.Add(member);
                    // moviehash member
                    member = new XmlRpcStructMember("moviebytesize",
                        new XmlRpcValueBasic(param.MovieByteSize, XmlRpcBasicValueType.Int));
                    strct.Members.Add(member);
                }
                if (param.Query.Length > 0)
                {
                    member = new XmlRpcStructMember("query",
                        new XmlRpcValueBasic(param.Query, XmlRpcBasicValueType.String));
                    strct.Members.Add(member);
                }

                if (param.Episode.Length > 0 && param.Season.Length > 0)
                {
                    member = new XmlRpcStructMember("season",
                        new XmlRpcValueBasic(param.Season, XmlRpcBasicValueType.String));
                    strct.Members.Add(member);
                    member = new XmlRpcStructMember("episode",
                      new XmlRpcValueBasic(param.Episode, XmlRpcBasicValueType.String));
                    strct.Members.Add(member);
                }

                // imdbid member
                if (param.IMDbID.Length > 0)
                {
                    member = new XmlRpcStructMember("imdbid",
                        new XmlRpcValueBasic(param.IMDbID, XmlRpcBasicValueType.String));
                    strct.Members.Add(member);
                }
                // Add the struct to the array
                array.Values.Add(strct);
            }
            // Add the array to the parameters
            parms.Add(array);
            // Call !
            XmlRpcMethodCall call = new XmlRpcMethodCall("SearchSubtitles", parms);
            OSHConsole.WriteLine("Sending SearchSubtitles request to the server ...", DebugCode.Good);
            // Send the request to the server
            string response = Utilities.GetStreamString(await Utilities.SendRequestAsync(XmlRpcGenerator.Generate(call), XML_PRC_USERAGENT, cancellationToken).ConfigureAwait(false));

            if (!response.Contains("ERROR:"))
            {
                // No error occur, get and decode the response. 
                XmlRpcMethodCall[] calls = XmlRpcGenerator.DecodeMethodResponse(response);
                if (calls.Length > 0)
                {
                    if (calls[0].Parameters.Count > 0)
                    {
                        // We expect Struct of 3 members:
                        //* the first is status
                        //* the second is [array of structs, each one includes subtitle file].
                        //* the third is [double basic value] represent seconds token by server.
                        XmlRpcValueStruct mainStruct = (XmlRpcValueStruct)calls[0].Parameters[0];
                        // Create the response, we'll need it later
                        MethodResponseSubtitleSearch R = new MethodResponseSubtitleSearch();
                        // To make sure response is not currepted by server, do it in loop
                        foreach (XmlRpcStructMember MEMBER in mainStruct.Members)
                        {
                            if (MEMBER.Name == "status")
                            {
                                R.Status = (string)MEMBER.Data.Data;
                                OSHConsole.WriteLine("Status= " + R.Status);
                            }
                            else if (MEMBER.Name == "seconds")
                            {
                                R.Seconds = (double)MEMBER.Data.Data;
                                OSHConsole.WriteLine("Seconds= " + R.Seconds);
                            }
                            else if (MEMBER.Name == "data")
                            {
                                if (MEMBER.Data is XmlRpcValueArray)
                                {
                                    OSHConsole.WriteLine("Search results: ");

                                    XmlRpcValueArray rarray = (XmlRpcValueArray)MEMBER.Data;
                                    foreach (IXmlRpcValue subStruct in rarray.Values)
                                    {
                                        if (subStruct == null) continue;
                                        if (!(subStruct is XmlRpcValueStruct)) continue;

                                        SubtitleSearchResult result = new SubtitleSearchResult();
                                        foreach (XmlRpcStructMember submember in ((XmlRpcValueStruct)subStruct).Members)
                                        {
                                            // To avoid errors of arranged info or missing ones, let's do it with switch..
                                            switch (submember.Name)
                                            {
                                                case "IDMovie": result.IDMovie = submember.Data.Data.ToString(); break;
                                                case "IDMovieImdb": result.IDMovieImdb = submember.Data.Data.ToString(); break;
                                                case "IDSubMovieFile": result.IDSubMovieFile = submember.Data.Data.ToString(); break;
                                                case "IDSubtitle": result.IDSubtitle = submember.Data.Data.ToString(); break;
                                                case "IDSubtitleFile": result.IDSubtitleFile = submember.Data.Data.ToString(); break;
                                                case "ISO639": result.ISO639 = submember.Data.Data.ToString(); break;
                                                case "LanguageName": result.LanguageName = submember.Data.Data.ToString(); break;
                                                case "MovieByteSize": result.MovieByteSize = submember.Data.Data.ToString(); break;
                                                case "MovieHash": result.MovieHash = submember.Data.Data.ToString(); break;
                                                case "MovieImdbRating": result.MovieImdbRating = submember.Data.Data.ToString(); break;
                                                case "MovieName": result.MovieName = submember.Data.Data.ToString(); break;
                                                case "MovieNameEng": result.MovieNameEng = submember.Data.Data.ToString(); break;
                                                case "MovieReleaseName": result.MovieReleaseName = submember.Data.Data.ToString(); break;
                                                case "MovieTimeMS": result.MovieTimeMS = submember.Data.Data.ToString(); break;
                                                case "MovieYear": result.MovieYear = submember.Data.Data.ToString(); break;
                                                case "SubActualCD": result.SubActualCD = submember.Data.Data.ToString(); break;
                                                case "SubAddDate": result.SubAddDate = submember.Data.Data.ToString(); break;
                                                case "SubAuthorComment": result.SubAuthorComment = submember.Data.Data.ToString(); break;
                                                case "SubBad": result.SubBad = submember.Data.Data.ToString(); break;
                                                case "SubDownloadLink": result.SubDownloadLink = submember.Data.Data.ToString(); break;
                                                case "SubDownloadsCnt": result.SubDownloadsCnt = submember.Data.Data.ToString(); break;
                                                case "SeriesEpisode": result.SeriesEpisode = submember.Data.Data.ToString(); break;
                                                case "SeriesSeason": result.SeriesSeason = submember.Data.Data.ToString(); break;
                                                case "SubFileName": result.SubFileName = submember.Data.Data.ToString(); break;
                                                case "SubFormat": result.SubFormat = submember.Data.Data.ToString(); break;
                                                case "SubHash": result.SubHash = submember.Data.Data.ToString(); break;
                                                case "SubLanguageID": result.SubLanguageID = submember.Data.Data.ToString(); break;
                                                case "SubRating": result.SubRating = submember.Data.Data.ToString(); break;
                                                case "SubSize": result.SubSize = submember.Data.Data.ToString(); break;
                                                case "SubSumCD": result.SubSumCD = submember.Data.Data.ToString(); break;
                                                case "UserID": result.UserID = submember.Data.Data.ToString(); break;
                                                case "UserNickName": result.UserNickName = submember.Data.Data.ToString(); break;
                                                case "ZipDownloadLink": result.ZipDownloadLink = submember.Data.Data.ToString(); break;
                                            }
                                        }
                                        R.Results.Add(result);
                                        OSHConsole.WriteLine(">" + result.ToString());
                                    }
                                }
                                else// Unknown data ?
                                {
                                    OSHConsole.WriteLine("Data= " + MEMBER.Data.Data.ToString(), DebugCode.Warning);
                                }
                            }
                        }
                        // Return the response to user !!
                        return R;
                    }
                }
            }
            else
            {
                OSHConsole.WriteLine(response, DebugCode.Error);
                return new MethodResponseError("Fail", response);
            }
            return new MethodResponseError("Fail", "Search Subtitles call failed !");
        }
Esempio n. 7
0
        /// <summary>
        /// Schedule a periodical search for subtitles matching given video files, send results to user's e-mail address.
        /// </summary>
        /// <param name="languageIDS">The language 3 lenght ids array</param>
        /// <param name="movies">The movies parameters</param>
        /// <returns>Status of the call operation. If the call success the response will be 'MethodResponseSearchToMail'</returns>
        public static IMethodResponse SearchToMail(string[] languageIDS, SearchToMailMovieParameter[] movies)
        {
            if (TOKEN == "")
            {
                OSHConsole.WriteLine("Can't do this call, 'token' value not set. Please use Log In method first.", DebugCode.Error);
                return new MethodResponseError("Fail", "Can't do this call, 'token' value not set. Please use Log In method first.");
            }
            // Method call ..
            List<IXmlRpcValue> parms = new List<IXmlRpcValue>();
            parms.Add(new XmlRpcValueBasic(TOKEN, XmlRpcBasicValueType.String));
            // Array of sub langs
            XmlRpcValueArray a = new XmlRpcValueArray(languageIDS);
            parms.Add(a);
            // Array of video parameters
            a = new XmlRpcValueArray();
            foreach (SearchToMailMovieParameter p in movies)
            {
                XmlRpcValueStruct str = new XmlRpcValueStruct(new List<XmlRpcStructMember>());
                str.Members.Add(new XmlRpcStructMember("moviehash", new XmlRpcValueBasic(p.moviehash)));
                str.Members.Add(new XmlRpcStructMember("moviesize", new XmlRpcValueBasic(p.moviesize)));
                a.Values.Add(str);
            }
            parms.Add(a);
            XmlRpcMethodCall call = new XmlRpcMethodCall("SearchToMail", parms);

            OSHConsole.WriteLine("Sending SearchToMail request to the server ...", DebugCode.Good);
            // Send the request to the server
            string response = Utilities.GetStreamString(Utilities.SendRequest(XmlRpcGenerator.Generate(call), XML_PRC_USERAGENT));
            if (!response.Contains("ERROR:"))
            {
                // No error occur, get and decode the response. 
                XmlRpcMethodCall[] calls = XmlRpcGenerator.DecodeMethodResponse(response);
                if (calls.Length > 0)
                {
                    if (calls[0].Parameters.Count > 0)
                    {
                        XmlRpcValueStruct mainStruct = (XmlRpcValueStruct)calls[0].Parameters[0];
                        // Create the response, we'll need it later
                        MethodResponseSearchToMail R = new MethodResponseSearchToMail();

                        // To make sure response is not currepted by server, do it in loop
                        foreach (XmlRpcStructMember MEMBER in mainStruct.Members)
                        {
                            switch (MEMBER.Name)
                            {
                                case "status": R.Status = (string)MEMBER.Data.Data; OSHConsole.WriteLine(">" + MEMBER.Name + "= " + MEMBER.Data.Data.ToString()); break;
                                case "seconds": R.Seconds = (double)MEMBER.Data.Data; OSHConsole.WriteLine(">" + MEMBER.Name + "= " + MEMBER.Data.Data.ToString()); break;
                            }
                        }
                        // Return the response to user !!
                        return R;
                    }
                }
            }
            else
            {
                OSHConsole.WriteLine(response, DebugCode.Error);
                return new MethodResponseError("Fail", response);
            }
            return new MethodResponseError("Fail", "SearchToMail call failed !");
        }
Esempio n. 8
0
        /// <summary>
        /// Upload given subtitles to OSDb server 
        /// </summary>
        /// <param name="info">The pamaters of upload method</param>
        /// <returns>Status of the call operation. If the call success the response will be 'MethodResponseUploadSubtitles'</returns>
        public static IMethodResponse UploadSubtitles(UploadSubtitleInfoParameters info)
        {
            if (TOKEN == "")
            {
                OSHConsole.WriteLine("Can't do this call, 'token' value not set. Please use Log In method first.", DebugCode.Error);
                return new MethodResponseError("Fail", "Can't do this call, 'token' value not set. Please use Log In method first.");
            }
            // Method call ..
            List<IXmlRpcValue> parms = new List<IXmlRpcValue>();
            parms.Add(new XmlRpcValueBasic(TOKEN));
            // Main struct
            XmlRpcValueStruct s = new XmlRpcValueStruct(new List<XmlRpcStructMember>());

            // Base info member as struct
            XmlRpcStructMember member = new XmlRpcStructMember("baseinfo", null);
            XmlRpcValueStruct memberStruct = new XmlRpcValueStruct(new List<XmlRpcStructMember>());
            memberStruct.Members.Add(new XmlRpcStructMember("idmovieimdb", new XmlRpcValueBasic(info.idmovieimdb)));
            memberStruct.Members.Add(new XmlRpcStructMember("sublanguageid", new XmlRpcValueBasic(info.sublanguageid))); 
            memberStruct.Members.Add(new XmlRpcStructMember("moviereleasename", new XmlRpcValueBasic(info.moviereleasename)));
            memberStruct.Members.Add(new XmlRpcStructMember("movieaka", new XmlRpcValueBasic(info.movieaka)));
            memberStruct.Members.Add(new XmlRpcStructMember("subauthorcomment", new XmlRpcValueBasic(info.subauthorcomment)));
            // memberStruct.Members.Add(new XmlRpcStructMember("hearingimpaired", new XmlRpcValueBasic(info.hearingimpaired)));
            // memberStruct.Members.Add(new XmlRpcStructMember("highdefinition", new XmlRpcValueBasic(info.highdefinition)));
            // memberStruct.Members.Add(new XmlRpcStructMember("automatictranslation", new XmlRpcValueBasic(info.automatictranslation)));
            member.Data = memberStruct;
            s.Members.Add(member);

            // CDS members
            int i = 1;
            foreach (UploadSubtitleParameters cd in info.CDS)
            {
                XmlRpcStructMember member2 = new XmlRpcStructMember("cd" + i, null);
                XmlRpcValueStruct memberStruct2 = new XmlRpcValueStruct(new List<XmlRpcStructMember>());
                memberStruct2.Members.Add(new XmlRpcStructMember("subhash", new XmlRpcValueBasic(cd.subhash)));
                memberStruct2.Members.Add(new XmlRpcStructMember("subfilename", new XmlRpcValueBasic(cd.subfilename)));
                memberStruct2.Members.Add(new XmlRpcStructMember("moviehash", new XmlRpcValueBasic(cd.moviehash)));
                memberStruct2.Members.Add(new XmlRpcStructMember("moviebytesize", new XmlRpcValueBasic(cd.moviebytesize)));
                memberStruct2.Members.Add(new XmlRpcStructMember("moviefps", new XmlRpcValueBasic(cd.moviefps)));
                memberStruct2.Members.Add(new XmlRpcStructMember("movietimems", new XmlRpcValueBasic(cd.movietimems)));
                memberStruct2.Members.Add(new XmlRpcStructMember("movieframes", new XmlRpcValueBasic(cd.movieframes)));
                memberStruct2.Members.Add(new XmlRpcStructMember("moviefilename", new XmlRpcValueBasic(cd.moviefilename)));
                memberStruct2.Members.Add(new XmlRpcStructMember("subcontent", new XmlRpcValueBasic(cd.subcontent)));
                member2.Data = memberStruct2;
                s.Members.Add(member2);
                i++;
            }

            // add main struct to parameters
            parms.Add(s);
            // add user agent
            //parms.Add(new XmlRpcValueBasic(XML_PRC_USERAGENT));
            XmlRpcMethodCall call = new XmlRpcMethodCall("UploadSubtitles", parms);
            OSHConsole.WriteLine("Sending UploadSubtitles request to the server ...", DebugCode.Good);
            // Send the request to the server
            string response = Utilities.GetStreamString(Utilities.SendRequest(XmlRpcGenerator.Generate(call), XML_PRC_USERAGENT));
            if (!response.Contains("ERROR:"))
            {
                // No error occur, get and decode the response. 
                XmlRpcMethodCall[] calls = XmlRpcGenerator.DecodeMethodResponse(response);
                if (calls.Length > 0)
                {
                    if (calls[0].Parameters.Count > 0)
                    {
                        XmlRpcValueStruct mainStruct = (XmlRpcValueStruct)calls[0].Parameters[0];
                        // Create the response, we'll need it later
                        MethodResponseUploadSubtitles R = new MethodResponseUploadSubtitles();

                        // To make sure response is not currepted by server, do it in loop
                        foreach (XmlRpcStructMember MEMBER in mainStruct.Members)
                        {
                            switch (MEMBER.Name)
                            {
                                case "status": R.Status = (string)MEMBER.Data.Data; OSHConsole.WriteLine(">" + MEMBER.Name + "= " + MEMBER.Data.Data.ToString()); break;
                                case "seconds": R.Seconds = (double)MEMBER.Data.Data; OSHConsole.WriteLine(">" + MEMBER.Name + "= " + MEMBER.Data.Data.ToString()); break;
                                case "data": R.Data = (string)MEMBER.Data.Data; OSHConsole.WriteLine(">" + MEMBER.Name + "= " + MEMBER.Data.Data.ToString()); break;
                                case "subtitles": R.SubTitles = (bool)MEMBER.Data.Data; OSHConsole.WriteLine(">" + MEMBER.Name + "= " + MEMBER.Data.Data.ToString()); break;
                            }
                        }
                        // Return the response to user !!
                        return R;
                    }
                }
            }
            else
            {
                OSHConsole.WriteLine(response, DebugCode.Error);
                return new MethodResponseError("Fail", response);
            }
            return new MethodResponseError("Fail", "UploadSubtitles call failed !");
        }
Esempio n. 9
0
        /*Upload*/
        /// <summary>
        /// Try to upload subtitles, perform pre-upload checking (i.e. check if subtitles already exist on server) 
        /// </summary>
        /// <param name="subs">The subtitle parameters collection to try to upload</param>
        /// <returns>Status of the call operation. If the call success the response will be 'MethodResponseTryUploadSubtitles'</returns>
        public static IMethodResponse TryUploadSubtitles(TryUploadSubtitlesParameters[] subs)
        {
            if (TOKEN == "")
            {
                OSHConsole.WriteLine("Can't do this call, 'token' value not set. Please use Log In method first.", DebugCode.Error);
                return new MethodResponseError("Fail", "Can't do this call, 'token' value not set. Please use Log In method first.");
            }
            // Method call ..
            List<IXmlRpcValue> parms = new List<IXmlRpcValue>();
            parms.Add(new XmlRpcValueBasic(TOKEN, XmlRpcBasicValueType.String));
            XmlRpcValueStruct s = new XmlRpcValueStruct(new List<XmlRpcStructMember>());
            int i = 1;
            foreach (TryUploadSubtitlesParameters cd in subs)
            {
                XmlRpcStructMember member = new XmlRpcStructMember("cd" + i, null);
                XmlRpcValueStruct memberStruct = new XmlRpcValueStruct(new List<XmlRpcStructMember>());
                memberStruct.Members.Add(new XmlRpcStructMember("subhash", new XmlRpcValueBasic(cd.subhash)));
                memberStruct.Members.Add(new XmlRpcStructMember("subfilename", new XmlRpcValueBasic(cd.subfilename)));
                memberStruct.Members.Add(new XmlRpcStructMember("moviehash", new XmlRpcValueBasic(cd.moviehash)));
                memberStruct.Members.Add(new XmlRpcStructMember("moviebytesize", new XmlRpcValueBasic(cd.moviebytesize)));
                memberStruct.Members.Add(new XmlRpcStructMember("moviefps", new XmlRpcValueBasic(cd.moviefps)));
                memberStruct.Members.Add(new XmlRpcStructMember("movietimems", new XmlRpcValueBasic(cd.movietimems)));
                memberStruct.Members.Add(new XmlRpcStructMember("movieframes", new XmlRpcValueBasic(cd.movieframes)));
                memberStruct.Members.Add(new XmlRpcStructMember("moviefilename", new XmlRpcValueBasic(cd.moviefilename)));
                member.Data = memberStruct;
                s.Members.Add(member);
                i++;
            }
            parms.Add(s);
            XmlRpcMethodCall call = new XmlRpcMethodCall("TryUploadSubtitles", parms);

            OSHConsole.WriteLine("Sending TryUploadSubtitles request to the server ...", DebugCode.Good);
            // Send the request to the server
            string response = Utilities.GetStreamString(Utilities.SendRequest(XmlRpcGenerator.Generate(call), XML_PRC_USERAGENT));
            if (!response.Contains("ERROR:"))
            {
                // No error occur, get and decode the response. 
                XmlRpcMethodCall[] calls = XmlRpcGenerator.DecodeMethodResponse(response);
                if (calls.Length > 0)
                {
                    if (calls[0].Parameters.Count > 0)
                    {
                        XmlRpcValueStruct mainStruct = (XmlRpcValueStruct)calls[0].Parameters[0];
                        // Create the response, we'll need it later
                        MethodResponseTryUploadSubtitles R = new MethodResponseTryUploadSubtitles();

                        // To make sure response is not currepted by server, do it in loop
                        foreach (XmlRpcStructMember MEMBER in mainStruct.Members)
                        {
                            switch (MEMBER.Name)
                            {
                                case "status": R.Status = (string)MEMBER.Data.Data; OSHConsole.WriteLine(">" + MEMBER.Name + "= " + MEMBER.Data.Data.ToString()); break;
                                case "seconds": R.Seconds = (double)MEMBER.Data.Data; OSHConsole.WriteLine(">" + MEMBER.Name + "= " + MEMBER.Data.Data.ToString()); break;
                                case "alreadyindb": R.AlreadyInDB = (int)MEMBER.Data.Data; OSHConsole.WriteLine(">" + MEMBER.Name + "= " + MEMBER.Data.Data.ToString()); break;
                                case "data":
                                    if (MEMBER.Data is XmlRpcValueArray)
                                    {
                                        OSHConsole.WriteLine("Results: ");

                                        XmlRpcValueArray rarray = (XmlRpcValueArray)MEMBER.Data;
                                        foreach (IXmlRpcValue subStruct in rarray.Values)
                                        {
                                            if (subStruct == null) continue;
                                            if (!(subStruct is XmlRpcValueStruct)) continue;

                                            SubtitleSearchResult result = new SubtitleSearchResult();
                                            foreach (XmlRpcStructMember submember in ((XmlRpcValueStruct)subStruct).Members)
                                            {
                                                // To avoid errors of arranged info or missing ones, let's do it with switch..
                                                switch (submember.Name)
                                                {
                                                    case "IDMovie": result.IDMovie = submember.Data.Data.ToString(); break;
                                                    case "IDMovieImdb": result.IDMovieImdb = submember.Data.Data.ToString(); break;
                                                    case "IDSubMovieFile": result.IDSubMovieFile = submember.Data.Data.ToString(); break;
                                                    case "IDSubtitle": result.IDSubtitle = submember.Data.Data.ToString(); break;
                                                    case "IDSubtitleFile": result.IDSubtitleFile = submember.Data.Data.ToString(); break;
                                                    case "ISO639": result.ISO639 = submember.Data.Data.ToString(); break;
                                                    case "LanguageName": result.LanguageName = submember.Data.Data.ToString(); break;
                                                    case "MovieByteSize": result.MovieByteSize = submember.Data.Data.ToString(); break;
                                                    case "MovieHash": result.MovieHash = submember.Data.Data.ToString(); break;
                                                    case "MovieImdbRating": result.MovieImdbRating = submember.Data.Data.ToString(); break;
                                                    case "MovieName": result.MovieName = submember.Data.Data.ToString(); break;
                                                    case "MovieNameEng": result.MovieNameEng = submember.Data.Data.ToString(); break;
                                                    case "MovieReleaseName": result.MovieReleaseName = submember.Data.Data.ToString(); break;
                                                    case "MovieTimeMS": result.MovieTimeMS = submember.Data.Data.ToString(); break;
                                                    case "MovieYear": result.MovieYear = submember.Data.Data.ToString(); break;
                                                    case "SubActualCD": result.SubActualCD = submember.Data.Data.ToString(); break;
                                                    case "SubAddDate": result.SubAddDate = submember.Data.Data.ToString(); break;
                                                    case "SubAuthorComment": result.SubAuthorComment = submember.Data.Data.ToString(); break;
                                                    case "SubBad": result.SubBad = submember.Data.Data.ToString(); break;
                                                    case "SubDownloadLink": result.SubDownloadLink = submember.Data.Data.ToString(); break;
                                                    case "SubDownloadsCnt": result.SubDownloadsCnt = submember.Data.Data.ToString(); break;
                                                    case "SubFileName": result.SubFileName = submember.Data.Data.ToString(); break;
                                                    case "SubFormat": result.SubFormat = submember.Data.Data.ToString(); break;
                                                    case "SubHash": result.SubHash = submember.Data.Data.ToString(); break;
                                                    case "SubLanguageID": result.SubLanguageID = submember.Data.Data.ToString(); break;
                                                    case "SubRating": result.SubRating = submember.Data.Data.ToString(); break;
                                                    case "SubSize": result.SubSize = submember.Data.Data.ToString(); break;
                                                    case "SubSumCD": result.SubSumCD = submember.Data.Data.ToString(); break;
                                                    case "UserID": result.UserID = submember.Data.Data.ToString(); break;
                                                    case "UserNickName": result.UserNickName = submember.Data.Data.ToString(); break;
                                                    case "ZipDownloadLink": result.ZipDownloadLink = submember.Data.Data.ToString(); break;
                                                }
                                            }
                                            R.Results.Add(result);
                                            OSHConsole.WriteLine(">" + result.ToString());
                                        }
                                    }
                                    else// Unknown data ?
                                    {
                                        OSHConsole.WriteLine("Data= " + MEMBER.Data.Data.ToString(), DebugCode.Warning);
                                    }
                                    break;
                            }
                        }
                        // Return the response to user !!
                        return R;
                    }
                }
            }
            else
            {
                OSHConsole.WriteLine(response, DebugCode.Error);
                return new MethodResponseError("Fail", response);
            }
            return new MethodResponseError("Fail", "TryUploadSubtitles call failed !");
        }
Esempio n. 10
0
        /// <summary>
        /// Add new request for subtitles, user must be logged in
        /// </summary>
        /// <param name="sublanguageid">The subtitle language id 3 length</param>
        /// <param name="idmovieimdb">http://www.imdb.com/</param>
        /// <param name="comment">The comment</param>
        /// <returns>Status of the call operation. If the call success the response will be 'MethodResponseAddRequest'</returns>
        public static IMethodResponse AddRequest(string sublanguageid, string idmovieimdb, string comment)
        {
            if (TOKEN == "")
            {
                OSHConsole.WriteLine("Can't do this call, 'token' value not set. Please use Log In method first.", DebugCode.Error);
                return new MethodResponseError("Fail", "Can't do this call, 'token' value not set. Please use Log In method first.");
            }
            // Method call ..
            List<IXmlRpcValue> parms = new List<IXmlRpcValue>();
            parms.Add(new XmlRpcValueBasic(TOKEN, XmlRpcBasicValueType.String));
            XmlRpcValueStruct s = new XmlRpcValueStruct(new List<XmlRpcStructMember>());
            s.Members.Add(new XmlRpcStructMember("sublanguageid", new XmlRpcValueBasic(sublanguageid)));
            s.Members.Add(new XmlRpcStructMember("idmovieimdb", new XmlRpcValueBasic(idmovieimdb)));
            s.Members.Add(new XmlRpcStructMember("comment", new XmlRpcValueBasic(comment)));
            parms.Add(s);
            XmlRpcMethodCall call = new XmlRpcMethodCall("AddRequest", parms);

            OSHConsole.WriteLine("Sending AddRequest request to the server ...", DebugCode.Good);
            // Send the request to the server
            string response = Utilities.GetStreamString(Utilities.SendRequest(XmlRpcGenerator.Generate(call), XML_PRC_USERAGENT));
            if (!response.Contains("ERROR:"))
            {
                // No error occur, get and decode the response. 
                XmlRpcMethodCall[] calls = XmlRpcGenerator.DecodeMethodResponse(response);
                if (calls.Length > 0)
                {
                    if (calls[0].Parameters.Count > 0)
                    {
                        XmlRpcValueStruct mainStruct = (XmlRpcValueStruct)calls[0].Parameters[0];
                        // Create the response, we'll need it later
                        MethodResponseAddRequest R = new MethodResponseAddRequest();

                        // To make sure response is not currepted by server, do it in loop
                        foreach (XmlRpcStructMember MEMBER in mainStruct.Members)
                        {
                            switch (MEMBER.Name)
                            {
                                case "status": R.Status = (string)MEMBER.Data.Data; OSHConsole.WriteLine(">" + MEMBER.Name + "= " + MEMBER.Data.Data.ToString()); break;
                                case "seconds": R.Seconds = (double)MEMBER.Data.Data; OSHConsole.WriteLine(">" + MEMBER.Name + "= " + MEMBER.Data.Data.ToString()); break;
                                case "data":
                                    XmlRpcValueStruct dataStruct = (XmlRpcValueStruct)MEMBER.Data;
                                    foreach (XmlRpcStructMember dataMemeber in dataStruct.Members)
                                    {
                                        switch (dataMemeber.Name)
                                        {
                                            case "request_url": R.request_url = dataMemeber.Data.Data.ToString(); OSHConsole.WriteLine(">" + dataMemeber.Name + "= " + dataMemeber.Data.Data.ToString()); break;
                                        }
                                    }
                                    break;
                            }
                        }
                        // Return the response to user !!
                        return R;
                    }
                }
            }
            else
            {
                OSHConsole.WriteLine(response, DebugCode.Error);
                return new MethodResponseError("Fail", response);
            }
            return new MethodResponseError("Fail", "AddRequest call failed !");
        }
Esempio n. 11
0
        /// <summary>
        /// Inserts or updates data to tables, which are used for CheckMovieHash() and !CheckMovieHash2().
        /// </summary>
        /// <param name="parameters">The parameters</param>
        /// <returns>Status of the call operation. If the call success the response will be 'MethodResponseInsertMovieHash'</returns>
        public static IMethodResponse InsertMovieHash(InsertMovieHashParameters[] parameters)
        {
            if (TOKEN == "")
            {
                OSHConsole.WriteLine("Can't do this call, 'token' value not set. Please use Log In method first.", DebugCode.Error);
                return new MethodResponseError("Fail", "Can't do this call, 'token' value not set. Please use Log In method first.");
            }
            // Method call ..
            List<IXmlRpcValue> parms = new List<IXmlRpcValue>();
            parms.Add(new XmlRpcValueBasic(TOKEN, XmlRpcBasicValueType.String));
            foreach (InsertMovieHashParameters p in parameters)
            {
                XmlRpcValueStruct pstruct = new XmlRpcValueStruct(new List<XmlRpcStructMember>());
                pstruct.Members.Add(new XmlRpcStructMember("moviehash", new XmlRpcValueBasic(p.moviehash)));
                pstruct.Members.Add(new XmlRpcStructMember("moviebytesize", new XmlRpcValueBasic(p.moviebytesize)));
                pstruct.Members.Add(new XmlRpcStructMember("imdbid", new XmlRpcValueBasic(p.imdbid)));
                pstruct.Members.Add(new XmlRpcStructMember("movietimems", new XmlRpcValueBasic(p.movietimems)));
                pstruct.Members.Add(new XmlRpcStructMember("moviefps", new XmlRpcValueBasic(p.moviefps)));
                pstruct.Members.Add(new XmlRpcStructMember("moviefilename", new XmlRpcValueBasic(p.moviefilename)));
                parms.Add(pstruct);
            }
            XmlRpcMethodCall call = new XmlRpcMethodCall("InsertMovieHash", parms);

            OSHConsole.WriteLine("Sending InsertMovieHash request to the server ...", DebugCode.Good);
            // Send the request to the server
            string response = Utilities.GetStreamString(Utilities.SendRequest(XmlRpcGenerator.Generate(call), XML_PRC_USERAGENT));
            if (!response.Contains("ERROR:"))
            {
                // No error occur, get and decode the response. 
                XmlRpcMethodCall[] calls = XmlRpcGenerator.DecodeMethodResponse(response);
                if (calls.Length > 0)
                {
                    if (calls[0].Parameters.Count > 0)
                    {
                        XmlRpcValueStruct mainStruct = (XmlRpcValueStruct)calls[0].Parameters[0];
                        // Create the response, we'll need it later
                        MethodResponseInsertMovieHash R = new MethodResponseInsertMovieHash();

                        // To make sure response is not currepted by server, do it in loop
                        foreach (XmlRpcStructMember MEMBER in mainStruct.Members)
                        {
                            switch (MEMBER.Name)
                            {
                                case "status":
                                    R.Status = (string)MEMBER.Data.Data;
                                    OSHConsole.WriteLine(">" + MEMBER.Name + "= " + MEMBER.Data.Data.ToString());
                                    break;
                                case "seconds":
                                    R.Seconds = (double)MEMBER.Data.Data;
                                    OSHConsole.WriteLine(">" + MEMBER.Name + "= " + MEMBER.Data.Data.ToString());
                                    break;
                                case "data":
                                    XmlRpcValueStruct dataStruct = (XmlRpcValueStruct)MEMBER.Data;
                                    foreach (XmlRpcStructMember dataMember in dataStruct.Members)
                                    {
                                        switch (dataMember.Name)
                                        {
                                            case "accepted_moviehashes":
                                                XmlRpcValueArray mh = (XmlRpcValueArray)dataMember.Data;
                                                foreach (IXmlRpcValue val in mh.Values)
                                                {
                                                    if (val is XmlRpcValueBasic)
                                                    {
                                                        R.accepted_moviehashes.Add(val.Data.ToString());
                                                    }
                                                }
                                                break;
                                            case "new_imdbs":
                                                XmlRpcValueArray mi = (XmlRpcValueArray)dataMember.Data;
                                                foreach (IXmlRpcValue val in mi.Values)
                                                {
                                                    if (val is XmlRpcValueBasic)
                                                    {
                                                        R.new_imdbs.Add(val.Data.ToString());
                                                    }
                                                }
                                                break;
                                        }
                                    }
                                    break;
                            }
                        }
                        // Return the response to user !!
                        return R;
                    }
                }
            }
            else
            {
                OSHConsole.WriteLine(response, DebugCode.Error);
                return new MethodResponseError("Fail", response);
            }
            return new MethodResponseError("Fail", "InsertMovieHash call failed !");
        }
Esempio n. 12
0
        /// <summary>
        /// Allows registered users to insert new movies (not stored in IMDb) to the database. 
        /// </summary>
        /// <param name="movieName">Movie title </param>
        /// <param name="movieyear">Release year </param>
        /// <returns>Status of the call operation. If the call success the response will be 'MethodResponseInsertMovie'</returns>
        public static IMethodResponse InsertMovie(string movieName, string movieyear)
        {
            if (TOKEN == "")
            {
                OSHConsole.WriteLine("Can't do this call, 'token' value not set. Please use Log In method first.", DebugCode.Error);
                return new MethodResponseError("Fail", "Can't do this call, 'token' value not set. Please use Log In method first.");
            }
            // Method call ..
            List<IXmlRpcValue> parms = new List<IXmlRpcValue>();
            // Add token param
            parms.Add(new XmlRpcValueBasic(TOKEN, XmlRpcBasicValueType.String));
            // Add movieinfo struct
            XmlRpcValueStruct movieinfo = new XmlRpcValueStruct(new List<XmlRpcStructMember>());
            movieinfo.Members.Add(new XmlRpcStructMember("moviename", new XmlRpcValueBasic(movieName)));
            movieinfo.Members.Add(new XmlRpcStructMember("movieyear", new XmlRpcValueBasic(movieyear)));
            parms.Add(movieinfo);
            // Call !
            XmlRpcMethodCall call = new XmlRpcMethodCall("InsertMovie", parms);
            OSHConsole.WriteLine("Sending InsertMovie request to the server ...", DebugCode.Good);
            // Send the request to the server
            string response = Utilities.GetStreamString(Utilities.SendRequest(XmlRpcGenerator.Generate(call), XML_PRC_USERAGENT));
            if (!response.Contains("ERROR:"))
            {
                // No error occur, get and decode the response. 
                XmlRpcMethodCall[] calls = XmlRpcGenerator.DecodeMethodResponse(response);
                if (calls.Length > 0)
                {
                    if (calls[0].Parameters.Count > 0)
                    {
                        XmlRpcValueStruct mainStruct = (XmlRpcValueStruct)calls[0].Parameters[0];
                        // Create the response, we'll need it later
                        MethodResponseInsertMovie R = new MethodResponseInsertMovie();

                        // To make sure response is not currepted by server, do it in loop
                        foreach (XmlRpcStructMember MEMBER in mainStruct.Members)
                        {
                            if (MEMBER.Name == "status")
                            {
                                R.Status = (string)MEMBER.Data.Data;
                                OSHConsole.WriteLine("Status= " + R.Status);
                            }
                            else if (MEMBER.Name == "seconds")
                            {
                                R.Seconds = (double)MEMBER.Data.Data;
                                OSHConsole.WriteLine("Seconds= " + R.Seconds);
                            }
                            else if (MEMBER.Name == "id")
                            {
                                R.ID = (string)MEMBER.Data.Data;
                                OSHConsole.WriteLine("ID= " + R.Seconds);
                            }
                        }
                        // Return the response to user !!
                        return R;
                    }
                }
            }
            else
            {
                OSHConsole.WriteLine(response, DebugCode.Error);
                return new MethodResponseError("Fail", response);
            }
            return new MethodResponseError("Fail", "InsertMovie call failed !");
        }