diff --git a/MediaBrowser.Common.Implementations/HttpClientManager/HttpClientManager.cs b/MediaBrowser.Common.Implementations/HttpClientManager/HttpClientManager.cs index 69533ef9d2..a88f457c5e 100644 --- a/MediaBrowser.Common.Implementations/HttpClientManager/HttpClientManager.cs +++ b/MediaBrowser.Common.Implementations/HttpClientManager/HttpClientManager.cs @@ -230,10 +230,11 @@ namespace MediaBrowser.Common.Implementations.HttpClientManager var httpWebRequest = GetRequest(options, httpMethod, options.EnableHttpCompression); - if (!string.IsNullOrEmpty(options.RequestContent) || string.Equals(httpMethod, "post", StringComparison.OrdinalIgnoreCase)) + if (options.RequestContentBytes != null || + !string.IsNullOrEmpty(options.RequestContent) || + string.Equals(httpMethod, "post", StringComparison.OrdinalIgnoreCase)) { - var content = options.RequestContent ?? string.Empty; - var bytes = Encoding.UTF8.GetBytes(content); + var bytes = options.RequestContentBytes ?? Encoding.UTF8.GetBytes(options.RequestContent ?? string.Empty); httpWebRequest.ContentType = options.RequestContentType ?? "application/x-www-form-urlencoded"; httpWebRequest.ContentLength = bytes.Length; diff --git a/MediaBrowser.Common/Net/HttpRequestOptions.cs b/MediaBrowser.Common/Net/HttpRequestOptions.cs index c7277eba86..11152b30fc 100644 --- a/MediaBrowser.Common/Net/HttpRequestOptions.cs +++ b/MediaBrowser.Common/Net/HttpRequestOptions.cs @@ -69,6 +69,7 @@ namespace MediaBrowser.Common.Net public string RequestContentType { get; set; } public string RequestContent { get; set; } + public byte[] RequestContentBytes { get; set; } public bool BufferContent { get; set; } diff --git a/MediaBrowser.Controller/MediaBrowser.Controller.csproj b/MediaBrowser.Controller/MediaBrowser.Controller.csproj index 830a4829f4..5e259359ff 100644 --- a/MediaBrowser.Controller/MediaBrowser.Controller.csproj +++ b/MediaBrowser.Controller/MediaBrowser.Controller.csproj @@ -191,6 +191,7 @@ + diff --git a/MediaBrowser.Controller/Providers/ISubtitleProvider.cs b/MediaBrowser.Controller/Providers/ISubtitleProvider.cs new file mode 100644 index 0000000000..a3aaaf298e --- /dev/null +++ b/MediaBrowser.Controller/Providers/ISubtitleProvider.cs @@ -0,0 +1,55 @@ +using System.Collections.Generic; +using System.IO; +using System.Threading; +using System.Threading.Tasks; + +namespace MediaBrowser.Controller.Providers +{ + public interface ISubtitleProvider + { + /// + /// Gets the name. + /// + /// The name. + string Name { get; } + + /// + /// Gets the supported media types. + /// + /// The supported media types. + IEnumerable SupportedMediaTypes { get; } + + /// + /// Gets the subtitles. + /// + /// The request. + /// The cancellation token. + /// Task{SubtitleResponse}. + Task GetSubtitles(SubtitleRequest request, CancellationToken cancellationToken); + } + + public enum SubtitleMediaType + { + Episode = 0, + Movie = 1 + } + + public class SubtitleResponse + { + public string Format { get; set; } + public bool HasContent { get; set; } + public Stream Stream { get; set; } + } + + public class SubtitleRequest + { + public string Language { get; set; } + + public SubtitleMediaType ContentType { get; set; } + + public string MediaPath { get; set; } + public string SeriesName { get; set; } + public int? IndexNumber { get; set; } + public int? ParentIndexNumber { get; set; } + } +} diff --git a/MediaBrowser.Model/MediaInfo/Constants.cs b/MediaBrowser.Model/MediaInfo/Constants.cs index bada7bc799..8f2e36b39b 100644 --- a/MediaBrowser.Model/MediaInfo/Constants.cs +++ b/MediaBrowser.Model/MediaInfo/Constants.cs @@ -3,22 +3,27 @@ namespace MediaBrowser.Model.MediaInfo { public class Container { - public string MP4 = "MP4"; + public const string MP4 = "MP4"; } public class AudioCodec { - public string AAC = "AAC"; - public string MP3 = "MP3"; + public const string AAC = "AAC"; + public const string MP3 = "MP3"; } public class VideoCodec { - public string H263 = "H263"; - public string H264 = "H264"; - public string H265 = "H265"; - public string MPEG4 = "MPEG4"; - public string MSMPEG4 = "MSMPEG4"; - public string VC1 = "VC1"; + public const string H263 = "H263"; + public const string H264 = "H264"; + public const string H265 = "H265"; + public const string MPEG4 = "MPEG4"; + public const string MSMPEG4 = "MSMPEG4"; + public const string VC1 = "VC1"; + } + + public class SubtitleFormat + { + public const string SRT = "SRT"; } } diff --git a/MediaBrowser.Providers/MediaBrowser.Providers.csproj b/MediaBrowser.Providers/MediaBrowser.Providers.csproj index 817ecdbb8c..b19966718a 100644 --- a/MediaBrowser.Providers/MediaBrowser.Providers.csproj +++ b/MediaBrowser.Providers/MediaBrowser.Providers.csproj @@ -186,6 +186,7 @@ + @@ -229,6 +230,10 @@ {7EEEB4BB-F3E8-48FC-B4C5-70F0FFF8329B} MediaBrowser.Model + + {4a4402d4-e910-443b-b8fc-2c18286a2ca0} + OpenSubtitlesHandler + diff --git a/MediaBrowser.Providers/Subtitles/OpenSubtitleDownloader.cs b/MediaBrowser.Providers/Subtitles/OpenSubtitleDownloader.cs new file mode 100644 index 0000000000..12d8b8fc65 --- /dev/null +++ b/MediaBrowser.Providers/Subtitles/OpenSubtitleDownloader.cs @@ -0,0 +1,132 @@ +using MediaBrowser.Common.Net; +using MediaBrowser.Controller.Providers; +using MediaBrowser.Model.Logging; +using MediaBrowser.Model.MediaInfo; +using OpenSubtitlesHandler; +using System; +using System.Collections.Generic; +using System.Globalization; +using System.IO; +using System.Linq; +using System.Threading; +using System.Threading.Tasks; + +namespace MediaBrowser.Providers.Subtitles +{ + public class OpenSubtitleDownloader : ISubtitleProvider + { + private readonly ILogger _logger; + private readonly IHttpClient _httpClient; + private readonly CultureInfo _usCulture = new CultureInfo("en-US"); + + public OpenSubtitleDownloader(ILogger logger, IHttpClient httpClient) + { + _logger = logger; + _httpClient = httpClient; + } + + public string Name + { + get { return "Open Subtitles"; } + } + + public IEnumerable SupportedMediaTypes + { + get { return new[] { SubtitleMediaType.Episode, SubtitleMediaType.Movie }; } + } + + public Task GetSubtitles(SubtitleRequest request, CancellationToken cancellationToken) + { + return request.ContentType == SubtitleMediaType.Episode + ? GetEpisodeSubtitles(request, cancellationToken) + : GetMovieSubtitles(request, cancellationToken); + } + + public async Task GetMovieSubtitles(SubtitleRequest request, CancellationToken cancellationToken) + { + throw new NotImplementedException(); + } + + public async Task GetEpisodeSubtitles(SubtitleRequest request, CancellationToken cancellationToken) + { + var response = new SubtitleResponse(); + + if (!request.IndexNumber.HasValue || !request.ParentIndexNumber.HasValue) + { + _logger.Debug("Information Missing"); + return response; + } + if (string.IsNullOrEmpty(request.MediaPath)) + { + _logger.Debug("Path Missing"); + return response; + } + + Utilities.HttpClient = _httpClient; + OpenSubtitles.SetUserAgent("OS Test User Agent"); + var loginResponse = OpenSubtitles.LogIn("", "", "en"); + if (!(loginResponse is MethodResponseLogIn)) + { + _logger.Debug("Login error"); + return response; + } + + var subLanguageId = request.Language; + var hash = Utilities.ComputeHash(request.MediaPath); + var fileInfo = new FileInfo(request.MediaPath); + var movieByteSize = fileInfo.Length; + + var parms = new List { + new SubtitleSearchParameters(subLanguageId, hash, movieByteSize), + new SubtitleSearchParameters(subLanguageId, request.SeriesName, request.ParentIndexNumber.Value.ToString(_usCulture), request.IndexNumber.Value.ToString(_usCulture)), + + }; + + var result = OpenSubtitles.SearchSubtitles(parms.ToArray()); + if (!(result is MethodResponseSubtitleSearch)) + { + _logger.Debug("invalid response type"); + return null; + } + + var results = ((MethodResponseSubtitleSearch)result).Results; + var bestResult = results.Where(x => x.SubBad == "0" && int.Parse(x.SeriesSeason) == request.ParentIndexNumber && int.Parse(x.SeriesEpisode) == request.IndexNumber) + .OrderBy(x => x.MovieHash == hash) + .ThenBy(x => Math.Abs(long.Parse(x.MovieByteSize) - movieByteSize)) + .ThenByDescending(x => int.Parse(x.SubDownloadsCnt)) + .ThenByDescending(x => double.Parse(x.SubRating)) + .ToList(); + + if (!bestResult.Any()) + { + _logger.Debug("No Subtitles"); + return response; + } + + _logger.Debug("Found " + bestResult.Count + " subtitles."); + + var subtitle = bestResult.First(); + var downloadsList = new[] { int.Parse(subtitle.IDSubtitleFile) }; + + var resultDownLoad = OpenSubtitles.DownloadSubtitles(downloadsList); + if (!(resultDownLoad is MethodResponseSubtitleDownload)) + { + _logger.Debug("invalid response type"); + return response; + } + if (!((MethodResponseSubtitleDownload)resultDownLoad).Results.Any()) + { + _logger.Debug("No Subtitle Downloads"); + return response; + } + + var res = ((MethodResponseSubtitleDownload)resultDownLoad).Results.First(); + var data = Convert.FromBase64String(res.Data); + + response.HasContent = true; + response.Format = SubtitleFormat.SRT; + response.Stream = new MemoryStream(Utilities.Decompress(new MemoryStream(data))); + return response; + } + } +} diff --git a/MediaBrowser.ServerApplication/ApplicationHost.cs b/MediaBrowser.ServerApplication/ApplicationHost.cs index befcd701e3..af400f8502 100644 --- a/MediaBrowser.ServerApplication/ApplicationHost.cs +++ b/MediaBrowser.ServerApplication/ApplicationHost.cs @@ -1026,16 +1026,12 @@ namespace MediaBrowser.ServerApplication /// Task{CheckForUpdateResult}. public override async Task CheckForApplicationUpdate(CancellationToken cancellationToken, IProgress progress) { -#if DEBUG - return new CheckForUpdateResult { AvailableVersion = ApplicationVersion, IsUpdateAvailable = false }; -#endif - var availablePackages = await InstallationManager.GetAvailablePackagesWithoutRegistrationInfo(cancellationToken).ConfigureAwait(false); var version = InstallationManager.GetLatestCompatibleVersion(availablePackages, Constants.MbServerPkgName, null, ApplicationVersion, ConfigurationManager.CommonConfiguration.SystemUpdateLevel); - HasUpdateAvailable = version != null; + HasUpdateAvailable = version != null && version.version >= ApplicationVersion; return version != null ? new CheckForUpdateResult { AvailableVersion = version.version, IsUpdateAvailable = version.version > ApplicationVersion, Package = version } : new CheckForUpdateResult { AvailableVersion = ApplicationVersion, IsUpdateAvailable = false }; diff --git a/MediaBrowser.sln b/MediaBrowser.sln index 7dc06fb0ce..4eec81cff4 100644 --- a/MediaBrowser.sln +++ b/MediaBrowser.sln @@ -43,6 +43,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MediaBrowser.Dlna", "MediaB EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MediaBrowser.MediaEncoding", "MediaBrowser.MediaEncoding\MediaBrowser.MediaEncoding.csproj", "{0BD82FA6-EB8A-4452-8AF5-74F9C3849451}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenSubtitlesHandler", "OpenSubtitlesHandler\OpenSubtitlesHandler.csproj", "{4A4402D4-E910-443B-B8FC-2C18286A2CA0}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -263,6 +265,20 @@ Global {0BD82FA6-EB8A-4452-8AF5-74F9C3849451}.Release|Win32.ActiveCfg = Release|Any CPU {0BD82FA6-EB8A-4452-8AF5-74F9C3849451}.Release|x64.ActiveCfg = Release|Any CPU {0BD82FA6-EB8A-4452-8AF5-74F9C3849451}.Release|x86.ActiveCfg = Release|Any CPU + {4A4402D4-E910-443B-B8FC-2C18286A2CA0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {4A4402D4-E910-443B-B8FC-2C18286A2CA0}.Debug|Any CPU.Build.0 = Debug|Any CPU + {4A4402D4-E910-443B-B8FC-2C18286A2CA0}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU + {4A4402D4-E910-443B-B8FC-2C18286A2CA0}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU + {4A4402D4-E910-443B-B8FC-2C18286A2CA0}.Debug|Win32.ActiveCfg = Debug|Any CPU + {4A4402D4-E910-443B-B8FC-2C18286A2CA0}.Debug|x64.ActiveCfg = Debug|Any CPU + {4A4402D4-E910-443B-B8FC-2C18286A2CA0}.Debug|x86.ActiveCfg = Debug|Any CPU + {4A4402D4-E910-443B-B8FC-2C18286A2CA0}.Release|Any CPU.ActiveCfg = Release|Any CPU + {4A4402D4-E910-443B-B8FC-2C18286A2CA0}.Release|Any CPU.Build.0 = Release|Any CPU + {4A4402D4-E910-443B-B8FC-2C18286A2CA0}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU + {4A4402D4-E910-443B-B8FC-2C18286A2CA0}.Release|Mixed Platforms.Build.0 = Release|Any CPU + {4A4402D4-E910-443B-B8FC-2C18286A2CA0}.Release|Win32.ActiveCfg = Release|Any CPU + {4A4402D4-E910-443B-B8FC-2C18286A2CA0}.Release|x64.ActiveCfg = Release|Any CPU + {4A4402D4-E910-443B-B8FC-2C18286A2CA0}.Release|x86.ActiveCfg = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/OpenSubtitlesHandler/Console/OSHConsole.cs b/OpenSubtitlesHandler/Console/OSHConsole.cs new file mode 100644 index 0000000000..04c00bf253 --- /dev/null +++ b/OpenSubtitlesHandler/Console/OSHConsole.cs @@ -0,0 +1,92 @@ +/* This file is part of OpenSubtitles Handler + A library that handle OpenSubtitles.org XML-RPC methods. + + Copyright © Ala Ibrahim Hadid 2013 + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + */ + +using System; + +namespace OpenSubtitlesHandler.Console +{ + public class OSHConsole + { + /// + /// Write line to the console and raise the "LineWritten" event + /// + /// + /// The debug line + /// The status + public static void WriteLine(string text, DebugCode code = DebugCode.None) + { + if (LineWritten != null) + LineWritten(null, new DebugEventArgs(text, code)); + } + /// + /// Update the last written line + /// + /// The debug line + /// The status + public static void UpdateLine(string text, DebugCode code = DebugCode.None) + { + if (UpdateLastLine != null) + UpdateLastLine(null, new DebugEventArgs(text, code)); + } + + public static event EventHandler LineWritten; + public static event EventHandler UpdateLastLine; + } + public enum DebugCode + { + None, + Good, + Warning, + Error + } + /// + /// Console Debug Args + /// + public class DebugEventArgs : System.EventArgs + { + public DebugCode Code { get; private set; } + public string Text { get; private set; } + + /// + /// Console Debug Args + /// + /// The debug line + /// The status + public DebugEventArgs(string text, DebugCode code) + { + this.Text = text; + this.Code = code; + } + } + public struct DebugLine + { + public DebugLine(string debugLine, DebugCode status) + { + this.debugLine = debugLine; + this.status = status; + } + string debugLine; + DebugCode status; + + public string Text + { get { return debugLine; } set { debugLine = value; } } + public DebugCode Code + { get { return status; } set { status = value; } } + } +} diff --git a/OpenSubtitlesHandler/Interfaces/IMethodResponse.cs b/OpenSubtitlesHandler/Interfaces/IMethodResponse.cs new file mode 100644 index 0000000000..b8e24f12bd --- /dev/null +++ b/OpenSubtitlesHandler/Interfaces/IMethodResponse.cs @@ -0,0 +1,62 @@ +/* This file is part of OpenSubtitles Handler + A library that handle OpenSubtitles.org XML-RPC methods. + + Copyright © Ala Ibrahim Hadid 2013 + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + */ +using System; +using System.ComponentModel; + +namespace OpenSubtitlesHandler +{ + /// + /// When you call a method to communicate with OpenSubtitles server, that method should return this response with the reuired information. + /// + public abstract class IMethodResponse + { + public IMethodResponse() { LoadAttributes(); } + public IMethodResponse(string name, string message) + { + this.name = name; + this.message = message; + } + protected string name; + protected string message; + protected double seconds; + protected string status; + + protected virtual void LoadAttributes() + { + foreach (Attribute attr in Attribute.GetCustomAttributes(this.GetType())) + { + if (attr.GetType() == typeof(MethodResponseDescription)) + { + this.name = ((MethodResponseDescription)attr).Name; + this.message = ((MethodResponseDescription)attr).Message; + break; + } + } + } + + [Description("The name of this response"), Category("MethodResponse")] + public virtual string Name { get { return name; } set { name = value; } } + [Description("The message about this response"), Category("MethodResponse")] + public virtual string Message { get { return message; } set { message = value; } } + [Description("Time taken to execute this command on server"), Category("MethodResponse")] + public double Seconds { get { return seconds; } set { seconds = value; } } + [Description("The status"), Category("MethodResponse")] + public string Status { get { return status; } set { status = value; } } + } +} diff --git a/OpenSubtitlesHandler/Interfaces/MethodResponseAttr.cs b/OpenSubtitlesHandler/Interfaces/MethodResponseAttr.cs new file mode 100644 index 0000000000..57f01d4d9b --- /dev/null +++ b/OpenSubtitlesHandler/Interfaces/MethodResponseAttr.cs @@ -0,0 +1,40 @@ +/* This file is part of OpenSubtitles Handler + A library that handle OpenSubtitles.org XML-RPC methods. + + Copyright © Ala Ibrahim Hadid 2013 + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + */ +using System; + +namespace OpenSubtitlesHandler +{ + /// + /// Attributes to describe a method response object. + /// + public class MethodResponseDescription : Attribute + { + public MethodResponseDescription(string name, string message) + { + this.name = name; + this.message = message; + } + + private string name; + private string message; + + public string Name { get { return name; } set { name = value; } } + public string Message { get { return message; } set { message = value; } } + } +} diff --git a/OpenSubtitlesHandler/Languages/DetectLanguageResult.cs b/OpenSubtitlesHandler/Languages/DetectLanguageResult.cs new file mode 100644 index 0000000000..9cc3cb8d83 --- /dev/null +++ b/OpenSubtitlesHandler/Languages/DetectLanguageResult.cs @@ -0,0 +1,31 @@ +/* This file is part of OpenSubtitles Handler + A library that handle OpenSubtitles.org XML-RPC methods. + + Copyright © Ala Ibrahim Hadid 2013 + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + */ +namespace OpenSubtitlesHandler +{ + public struct DetectLanguageResult + { + private string inputSample; + private string languageID; + + public string LanguageID + { get { return languageID; } set { languageID = value; } } + public string InputSample + { get { return inputSample; } set { inputSample = value; } } + } +} diff --git a/OpenSubtitlesHandler/MethodResponses/MethodResponseAddComment.cs b/OpenSubtitlesHandler/MethodResponses/MethodResponseAddComment.cs new file mode 100644 index 0000000000..4cfa11cc9c --- /dev/null +++ b/OpenSubtitlesHandler/MethodResponses/MethodResponseAddComment.cs @@ -0,0 +1,32 @@ +/* This file is part of OpenSubtitles Handler + A library that handle OpenSubtitles.org XML-RPC methods. + + Copyright © Ala Ibrahim Hadid 2013 + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + */ +namespace OpenSubtitlesHandler +{ + [MethodResponseDescription("AddComment method response", + "AddComment method response hold all expected values from server.")] + public class MethodResponseAddComment : IMethodResponse + { + public MethodResponseAddComment() + : base() + { } + public MethodResponseAddComment(string name, string message) + : base(name, message) + { } + } +} diff --git a/OpenSubtitlesHandler/MethodResponses/MethodResponseAddRequest.cs b/OpenSubtitlesHandler/MethodResponses/MethodResponseAddRequest.cs new file mode 100644 index 0000000000..8ea1c387c8 --- /dev/null +++ b/OpenSubtitlesHandler/MethodResponses/MethodResponseAddRequest.cs @@ -0,0 +1,35 @@ +/* This file is part of OpenSubtitles Handler + A library that handle OpenSubtitles.org XML-RPC methods. + + Copyright © Ala Ibrahim Hadid 2013 + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + */ +namespace OpenSubtitlesHandler +{ + [MethodResponseDescription("AddRequest method response", + "AddRequest method response hold all expected values from server.")] + public class MethodResponseAddRequest : IMethodResponse + { + public MethodResponseAddRequest() + : base() + { } + public MethodResponseAddRequest(string name, string message) + : base(name, message) + { } + private string _request_url; + + public string request_url { get { return _request_url; } set { _request_url = value; } } + } +} diff --git a/OpenSubtitlesHandler/MethodResponses/MethodResponseAutoUpdate.cs b/OpenSubtitlesHandler/MethodResponses/MethodResponseAutoUpdate.cs new file mode 100644 index 0000000000..26edf8b0ea --- /dev/null +++ b/OpenSubtitlesHandler/MethodResponses/MethodResponseAutoUpdate.cs @@ -0,0 +1,60 @@ +/* This file is part of OpenSubtitles Handler + A library that handle OpenSubtitles.org XML-RPC methods. + + Copyright © Ala Ibrahim Hadid 2013 + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + */ +using System; +using System.ComponentModel; + +namespace OpenSubtitlesHandler +{ + [MethodResponseDescription("AutoUpdate method response", + "AutoUpdate method response hold all expected values from server.")] + public class MethodResponseAutoUpdate : IMethodResponse + { + public MethodResponseAutoUpdate() + : base() + { } + public MethodResponseAutoUpdate(string name, string message) + : base(name, message) + { } + + private string _version; + private string _url_windows; + private string _comments; + private string _url_linux; + /// + /// Latest application version + /// + [Description("Latest application version"), Category("AutoUpdate")] + public string version { get { return _version; } set { _version = value; } } + /// + /// Download URL for Windows version + /// + [Description("Download URL for Windows version"), Category("AutoUpdate")] + public string url_windows { get { return _url_windows; } set { _url_windows = value; } } + /// + /// Application changelog and other comments + /// + [Description("Application changelog and other comments"), Category("AutoUpdate")] + public string comments { get { return _comments; } set { _comments = value; } } + /// + /// Download URL for Linux version + /// + [Description("Download URL for Linux version"), Category("AutoUpdate")] + public string url_linux { get { return _url_linux; } set { _url_linux = value; } } + } +} diff --git a/OpenSubtitlesHandler/MethodResponses/MethodResponseCheckMovieHash.cs b/OpenSubtitlesHandler/MethodResponses/MethodResponseCheckMovieHash.cs new file mode 100644 index 0000000000..30ef075b97 --- /dev/null +++ b/OpenSubtitlesHandler/MethodResponses/MethodResponseCheckMovieHash.cs @@ -0,0 +1,37 @@ +/* This file is part of OpenSubtitles Handler + A library that handle OpenSubtitles.org XML-RPC methods. + + Copyright © Ala Ibrahim Hadid 2013 + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + */ +using System; +using System.Collections.Generic; +namespace OpenSubtitlesHandler +{ + [MethodResponseDescription("CheckMovieHash method response", + "CheckMovieHash method response hold all expected values from server.")] + public class MethodResponseCheckMovieHash : IMethodResponse + { + public MethodResponseCheckMovieHash() + : base() + { } + public MethodResponseCheckMovieHash(string name, string message) + : base(name, message) + { } + private List results = new List(); + public List Results + { get { return results; } set { results = value; } } + } +} diff --git a/OpenSubtitlesHandler/MethodResponses/MethodResponseCheckMovieHash2.cs b/OpenSubtitlesHandler/MethodResponses/MethodResponseCheckMovieHash2.cs new file mode 100644 index 0000000000..78cdef0c4b --- /dev/null +++ b/OpenSubtitlesHandler/MethodResponses/MethodResponseCheckMovieHash2.cs @@ -0,0 +1,37 @@ +/* This file is part of OpenSubtitles Handler + A library that handle OpenSubtitles.org XML-RPC methods. + + Copyright © Ala Ibrahim Hadid 2013 + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + */ +using System; +using System.Collections.Generic; +namespace OpenSubtitlesHandler +{ + [MethodResponseDescription("CheckMovieHash2 method response", + "CheckMovieHash2 method response hold all expected values from server.")] + public class MethodResponseCheckMovieHash2 : IMethodResponse + { + public MethodResponseCheckMovieHash2() + : base() + { } + public MethodResponseCheckMovieHash2(string name, string message) + : base(name, message) + { } + private List results = new List(); + public List Results + { get { return results; } set { results = value; } } + } +} diff --git a/OpenSubtitlesHandler/MethodResponses/MethodResponseCheckSubHash.cs b/OpenSubtitlesHandler/MethodResponses/MethodResponseCheckSubHash.cs new file mode 100644 index 0000000000..45c73631cf --- /dev/null +++ b/OpenSubtitlesHandler/MethodResponses/MethodResponseCheckSubHash.cs @@ -0,0 +1,38 @@ +/* This file is part of OpenSubtitles Handler + A library that handle OpenSubtitles.org XML-RPC methods. + + Copyright © Ala Ibrahim Hadid 2013 + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + */ +using System; +using System.Collections.Generic; + +namespace OpenSubtitlesHandler +{ + [MethodResponseDescription("CheckSubHash method response", + "CheckSubHash method response hold all expected values from server.")] + public class MethodResponseCheckSubHash : IMethodResponse + { + public MethodResponseCheckSubHash() + : base() + { } + public MethodResponseCheckSubHash(string name, string message) + : base(name, message) + { } + private List results = new List(); + + public List Results { get { return results; } set { results = value; } } + } +} diff --git a/OpenSubtitlesHandler/MethodResponses/MethodResponseDetectLanguage.cs b/OpenSubtitlesHandler/MethodResponses/MethodResponseDetectLanguage.cs new file mode 100644 index 0000000000..20b4d30f3e --- /dev/null +++ b/OpenSubtitlesHandler/MethodResponses/MethodResponseDetectLanguage.cs @@ -0,0 +1,37 @@ +/* This file is part of OpenSubtitles Handler + A library that handle OpenSubtitles.org XML-RPC methods. + + Copyright © Ala Ibrahim Hadid 2013 + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + */ +using System.Collections.Generic; +namespace OpenSubtitlesHandler +{ + [MethodResponseDescription("DetectLanguage method response", + "DetectLanguage method response hold all expected values from server.")] + public class MethodResponseDetectLanguage : IMethodResponse + { + public MethodResponseDetectLanguage() + : base() + { } + public MethodResponseDetectLanguage(string name, string message) + : base(name, message) + { } + private List results = new List(); + + public List Results + { get { return results; } set { results = value; } } + } +} diff --git a/OpenSubtitlesHandler/MethodResponses/MethodResponseError.cs b/OpenSubtitlesHandler/MethodResponses/MethodResponseError.cs new file mode 100644 index 0000000000..273dfb1ad5 --- /dev/null +++ b/OpenSubtitlesHandler/MethodResponses/MethodResponseError.cs @@ -0,0 +1,36 @@ +/* This file is part of OpenSubtitles Handler + A library that handle OpenSubtitles.org XML-RPC methods. + + Copyright © Ala Ibrahim Hadid 2013 + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + */ +using System; +namespace OpenSubtitlesHandler +{ + /// + /// Response that can be used for general error like internet connection fail. + /// + [MethodResponseDescription("Error method response", + "Error method response that describes error that occured")] + public class MethodResponseError : IMethodResponse + { + public MethodResponseError() + : base() + { } + public MethodResponseError(string name, string message) + : base(name, message) + { } + } +} diff --git a/OpenSubtitlesHandler/MethodResponses/MethodResponseGetAvailableTranslations.cs b/OpenSubtitlesHandler/MethodResponses/MethodResponseGetAvailableTranslations.cs new file mode 100644 index 0000000000..1ee4ea6c06 --- /dev/null +++ b/OpenSubtitlesHandler/MethodResponses/MethodResponseGetAvailableTranslations.cs @@ -0,0 +1,37 @@ +/* This file is part of OpenSubtitles Handler + A library that handle OpenSubtitles.org XML-RPC methods. + + Copyright © Ala Ibrahim Hadid 2013 + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + */ +using System; +using System.Collections.Generic; + +namespace OpenSubtitlesHandler +{ + [MethodResponseDescription("GetAvailableTranslations method response", + "GetAvailableTranslations method response hold all expected values from server.")] + public class MethodResponseGetAvailableTranslations : IMethodResponse + { + public MethodResponseGetAvailableTranslations() + : base() + { } + public MethodResponseGetAvailableTranslations(string name, string message) + : base(name, message) + { } + private List results = new List(); + public List Results { get { return results; } set { results = value; } } + } +} diff --git a/OpenSubtitlesHandler/MethodResponses/MethodResponseGetComments.cs b/OpenSubtitlesHandler/MethodResponses/MethodResponseGetComments.cs new file mode 100644 index 0000000000..6a586d5ced --- /dev/null +++ b/OpenSubtitlesHandler/MethodResponses/MethodResponseGetComments.cs @@ -0,0 +1,41 @@ +/* This file is part of OpenSubtitles Handler + A library that handle OpenSubtitles.org XML-RPC methods. + + Copyright © Ala Ibrahim Hadid 2013 + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + */ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace OpenSubtitlesHandler +{ + [MethodResponseDescription("GetComments method response", + "GetComments method response hold all expected values from server.")] + public class MethodResponseGetComments : IMethodResponse + { + public MethodResponseGetComments() + : base() + { } + public MethodResponseGetComments(string name, string message) + : base(name, message) + { } + private List results = new List(); + + public List Results + { get { return results; } set { results = value; } } + } +} diff --git a/OpenSubtitlesHandler/MethodResponses/MethodResponseGetSubLanguages.cs b/OpenSubtitlesHandler/MethodResponses/MethodResponseGetSubLanguages.cs new file mode 100644 index 0000000000..dc8100c92e --- /dev/null +++ b/OpenSubtitlesHandler/MethodResponses/MethodResponseGetSubLanguages.cs @@ -0,0 +1,39 @@ +/* This file is part of OpenSubtitles Handler + A library that handle OpenSubtitles.org XML-RPC methods. + + Copyright © Ala Ibrahim Hadid 2013 + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + */ +using System; +using System.Collections.Generic; + +namespace OpenSubtitlesHandler +{ + [MethodResponseDescription("GetSubLanguages method response", + "GetSubLanguages method response hold all expected values from server.")] + public class MethodResponseGetSubLanguages : IMethodResponse + { + public MethodResponseGetSubLanguages() + : base() + { } + public MethodResponseGetSubLanguages(string name, string message) + : base(name, message) + { } + private List languages = new List(); + + public List Languages + { get { return languages; } set { languages = value; } } + } +} diff --git a/OpenSubtitlesHandler/MethodResponses/MethodResponseGetTranslation.cs b/OpenSubtitlesHandler/MethodResponses/MethodResponseGetTranslation.cs new file mode 100644 index 0000000000..5482468873 --- /dev/null +++ b/OpenSubtitlesHandler/MethodResponses/MethodResponseGetTranslation.cs @@ -0,0 +1,37 @@ +/* This file is part of OpenSubtitles Handler + A library that handle OpenSubtitles.org XML-RPC methods. + + Copyright © Ala Ibrahim Hadid 2013 + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + */ +using System; + +namespace OpenSubtitlesHandler +{ + [MethodResponseDescription("GetTranslation method response", + "GetTranslation method response hold all expected values from server.")] + public class MethodResponseGetTranslation : IMethodResponse + { + public MethodResponseGetTranslation() + : base() + { } + public MethodResponseGetTranslation(string name, string message) + : base(name, message) + { } + private string data; + + public string ContentData { get { return data; } set { data = value; } } + } +} diff --git a/OpenSubtitlesHandler/MethodResponses/MethodResponseInsertMovie.cs b/OpenSubtitlesHandler/MethodResponses/MethodResponseInsertMovie.cs new file mode 100644 index 0000000000..b53aad5a9d --- /dev/null +++ b/OpenSubtitlesHandler/MethodResponses/MethodResponseInsertMovie.cs @@ -0,0 +1,37 @@ +/* This file is part of OpenSubtitles Handler + A library that handle OpenSubtitles.org XML-RPC methods. + + Copyright © Ala Ibrahim Hadid 2013 + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + */ +using System; + +namespace OpenSubtitlesHandler +{ + [MethodResponseDescription("InsertMovie method response", + "InsertMovie method response hold all expected values from server.")] + public class MethodResponseInsertMovie : IMethodResponse + { + public MethodResponseInsertMovie() + : base() + { } + public MethodResponseInsertMovie(string name, string message) + : base(name, message) + { } + private string _ID; + public string ID + { get { return _ID; } set { _ID = value; } } + } +} diff --git a/OpenSubtitlesHandler/MethodResponses/MethodResponseInsertMovieHash.cs b/OpenSubtitlesHandler/MethodResponses/MethodResponseInsertMovieHash.cs new file mode 100644 index 0000000000..fe9196de87 --- /dev/null +++ b/OpenSubtitlesHandler/MethodResponses/MethodResponseInsertMovieHash.cs @@ -0,0 +1,38 @@ +/* This file is part of OpenSubtitles Handler + A library that handle OpenSubtitles.org XML-RPC methods. + + Copyright © Ala Ibrahim Hadid 2013 + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + */ +using System.Collections.Generic; +namespace OpenSubtitlesHandler +{ + [MethodResponseDescription("InsertMovieHash method response", + "InsertMovieHash method response hold all expected values from server.")] + public class MethodResponseInsertMovieHash : IMethodResponse + { + public MethodResponseInsertMovieHash() + : base() + { } + public MethodResponseInsertMovieHash(string name, string message) + : base(name, message) + { } + private List _accepted_moviehashes = new List(); + private List _new_imdbs = new List(); + + public List accepted_moviehashes { get { return _accepted_moviehashes; } set { _accepted_moviehashes = value; } } + public List new_imdbs { get { return _new_imdbs; } set { _new_imdbs = value; } } + } +} diff --git a/OpenSubtitlesHandler/MethodResponses/MethodResponseLogIn.cs b/OpenSubtitlesHandler/MethodResponses/MethodResponseLogIn.cs new file mode 100644 index 0000000000..e7c23f61ca --- /dev/null +++ b/OpenSubtitlesHandler/MethodResponses/MethodResponseLogIn.cs @@ -0,0 +1,40 @@ +/* This file is part of OpenSubtitles Handler + A library that handle OpenSubtitles.org XML-RPC methods. + + Copyright © Ala Ibrahim Hadid 2013 + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + */ +using System; + +namespace OpenSubtitlesHandler +{ + /// + /// Response can be used for log in/out operation. + /// + [MethodResponseDescription("LogIn method response", + "LogIn method response hold all expected values from server.")] + public class MethodResponseLogIn : IMethodResponse + { + public MethodResponseLogIn() + : base() + { } + public MethodResponseLogIn(string name, string message) + : base(name, message) + { } + private string token; + + public string Token { get { return token; } set { token = value; } } + } +} diff --git a/OpenSubtitlesHandler/MethodResponses/MethodResponseMovieDetails.cs b/OpenSubtitlesHandler/MethodResponses/MethodResponseMovieDetails.cs new file mode 100644 index 0000000000..29e19245c1 --- /dev/null +++ b/OpenSubtitlesHandler/MethodResponses/MethodResponseMovieDetails.cs @@ -0,0 +1,73 @@ +/* This file is part of OpenSubtitles Handler + A library that handle OpenSubtitles.org XML-RPC methods. + + Copyright © Ala Ibrahim Hadid 2013 + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + */ +using System; +using System.Collections.Generic; + +namespace OpenSubtitlesHandler +{ + [MethodResponseDescription("MovieDetails method response", + "MovieDetails method response hold all expected values from server.")] + public class MethodResponseMovieDetails : IMethodResponse + { + public MethodResponseMovieDetails() + : base() + { } + public MethodResponseMovieDetails(string name, string message) + : base(name, message) + { } + // Details + private string id; + private string title; + private string year; + private string coverLink; + + private string duration; + private string tagline; + private string plot; + private string goofs; + private string trivia; + private List cast = new List(); + private List directors = new List(); + private List writers = new List(); + private List awards = new List(); + private List genres = new List(); + private List country = new List(); + private List language = new List(); + private List certification = new List(); + + // Details + public string ID { get { return id; } set { id = value; } } + public string Title { get { return title; } set { title = value; } } + public string Year { get { return year; } set { year = value; } } + public string CoverLink { get { return coverLink; } set { coverLink = value; } } + public string Duration { get { return duration; } set { duration = value; } } + public string Tagline { get { return tagline; } set { tagline = value; } } + public string Plot { get { return plot; } set { plot = value; } } + public string Goofs { get { return goofs; } set { goofs = value; } } + public string Trivia { get { return trivia; } set { trivia = value; } } + public List Cast { get { return cast; } set { cast = value; } } + public List Directors { get { return directors; } set { directors = value; } } + public List Writers { get { return writers; } set { writers = value; } } + public List Genres { get { return genres; } set { genres = value; } } + public List Awards { get { return awards; } set { awards = value; } } + public List Country { get { return country; } set { country = value; } } + public List Language { get { return language; } set { language = value; } } + public List Certification { get { return certification; } set { certification = value; } } + } +} diff --git a/OpenSubtitlesHandler/MethodResponses/MethodResponseMovieSearch.cs b/OpenSubtitlesHandler/MethodResponses/MethodResponseMovieSearch.cs new file mode 100644 index 0000000000..c1beeeeeae --- /dev/null +++ b/OpenSubtitlesHandler/MethodResponses/MethodResponseMovieSearch.cs @@ -0,0 +1,43 @@ +/* This file is part of OpenSubtitles Handler + A library that handle OpenSubtitles.org XML-RPC methods. + + Copyright © Ala Ibrahim Hadid 2013 + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + */ +using System; +using System.Collections.Generic; + +namespace OpenSubtitlesHandler +{ + [MethodResponseDescription("MovieSearch method response", + "MovieSearch method response hold all expected values from server.")] + public class MethodResponseMovieSearch : IMethodResponse + { + public MethodResponseMovieSearch() + : base() + { + results = new List(); + } + public MethodResponseMovieSearch(string name, string message) + : base(name, message) + { + results = new List(); + } + private List results; + + public List Results + { get { return results; } set { results = value; } } + } +} diff --git a/OpenSubtitlesHandler/MethodResponses/MethodResponseNoOperation.cs b/OpenSubtitlesHandler/MethodResponses/MethodResponseNoOperation.cs new file mode 100644 index 0000000000..0b5b2f1aab --- /dev/null +++ b/OpenSubtitlesHandler/MethodResponses/MethodResponseNoOperation.cs @@ -0,0 +1,53 @@ +/* This file is part of OpenSubtitles Handler + A library that handle OpenSubtitles.org XML-RPC methods. + + Copyright © Ala Ibrahim Hadid 2013 + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + */ +using System; + +namespace OpenSubtitlesHandler +{ + [MethodResponseDescription("NoOperation method response", + "NoOperation method response hold all expected values from server.")] + public class MethodResponseNoOperation : IMethodResponse + { + public MethodResponseNoOperation() + : base() { } + public MethodResponseNoOperation(string name, string message) + : base(name, message) + { } + + private string _global_wrh_download_limit; + private string _client_ip; + private string _limit_check_by; + private string _client_24h_download_count; + private string _client_downlaod_quota; + private string _client_24h_download_limit; + + public string global_wrh_download_limit + { get { return _global_wrh_download_limit; } set { _global_wrh_download_limit = value; } } + public string client_ip + { get { return _client_ip; } set { _client_ip = value; } } + public string limit_check_by + { get { return _limit_check_by; } set { _limit_check_by = value; } } + public string client_24h_download_count + { get { return _client_24h_download_count; } set { _client_24h_download_count = value; } } + public string client_downlaod_quota + { get { return _client_downlaod_quota; } set { _client_downlaod_quota = value; } } + public string client_24h_download_limit + { get { return _client_24h_download_limit; } set { _client_24h_download_limit = value; } } + } +} diff --git a/OpenSubtitlesHandler/MethodResponses/MethodResponseReportWrongImdbMovie.cs b/OpenSubtitlesHandler/MethodResponses/MethodResponseReportWrongImdbMovie.cs new file mode 100644 index 0000000000..3c19fcf6e5 --- /dev/null +++ b/OpenSubtitlesHandler/MethodResponses/MethodResponseReportWrongImdbMovie.cs @@ -0,0 +1,33 @@ +/* This file is part of OpenSubtitles Handler + A library that handle OpenSubtitles.org XML-RPC methods. + + Copyright © Ala Ibrahim Hadid 2013 + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + */ + +namespace OpenSubtitlesHandler +{ + [MethodResponseDescription("ReportWrongImdbMovie method response", + "ReportWrongImdbMovie method response hold all expected values from server.")] + public class MethodResponseReportWrongImdbMovie : IMethodResponse + { + public MethodResponseReportWrongImdbMovie() + : base() + { } + public MethodResponseReportWrongImdbMovie(string name, string message) + : base(name, message) + { } + } +} diff --git a/OpenSubtitlesHandler/MethodResponses/MethodResponseReportWrongMovieHash.cs b/OpenSubtitlesHandler/MethodResponses/MethodResponseReportWrongMovieHash.cs new file mode 100644 index 0000000000..94788b2c68 --- /dev/null +++ b/OpenSubtitlesHandler/MethodResponses/MethodResponseReportWrongMovieHash.cs @@ -0,0 +1,34 @@ +/* This file is part of OpenSubtitles Handler + A library that handle OpenSubtitles.org XML-RPC methods. + + Copyright © Ala Ibrahim Hadid 2013 + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + */ +using System; + +namespace OpenSubtitlesHandler +{ + [MethodResponseDescription("ReportWrongMovieHash method response", + "ReportWrongMovieHash method response hold all expected values from server.")] + public class MethodResponseReportWrongMovieHash : IMethodResponse + { + public MethodResponseReportWrongMovieHash() + : base() + { } + public MethodResponseReportWrongMovieHash(string name, string message) + : base(name, message) + { } + } +} diff --git a/OpenSubtitlesHandler/MethodResponses/MethodResponseSearchToMail.cs b/OpenSubtitlesHandler/MethodResponses/MethodResponseSearchToMail.cs new file mode 100644 index 0000000000..9f195dea05 --- /dev/null +++ b/OpenSubtitlesHandler/MethodResponses/MethodResponseSearchToMail.cs @@ -0,0 +1,32 @@ +/* This file is part of OpenSubtitles Handler + A library that handle OpenSubtitles.org XML-RPC methods. + + Copyright © Ala Ibrahim Hadid 2013 + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + */ +namespace OpenSubtitlesHandler +{ + [MethodResponseDescription("SearchToMail method response", + "SearchToMail method response hold all expected values from server.")] + public class MethodResponseSearchToMail : IMethodResponse + { + public MethodResponseSearchToMail() + : base() + { } + public MethodResponseSearchToMail(string name, string message) + : base(name, message) + { } + } +} diff --git a/OpenSubtitlesHandler/MethodResponses/MethodResponseServerInfo.cs b/OpenSubtitlesHandler/MethodResponses/MethodResponseServerInfo.cs new file mode 100644 index 0000000000..fce5b42450 --- /dev/null +++ b/OpenSubtitlesHandler/MethodResponses/MethodResponseServerInfo.cs @@ -0,0 +1,132 @@ +/* This file is part of OpenSubtitles Handler + A library that handle OpenSubtitles.org XML-RPC methods. + + Copyright © Ala Ibrahim Hadid 2013 + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + */ +using System; +using System.Collections.Generic; +using System.ComponentModel; +namespace OpenSubtitlesHandler +{ + [MethodResponseDescription("ServerInfo method response", + "ServerInfo method response hold all expected values from server.")] + public class MethodResponseServerInfo : IMethodResponse + { + public MethodResponseServerInfo() + : base() + { } + public MethodResponseServerInfo(string name, string message) + : base(name, message) + { } + private string _xmlrpc_version; + private string _xmlrpc_url; + private string _application; + private string _contact; + private string _website_url; + private int _users_online_total; + private int _users_online_program; + private int _users_loggedin; + private string _users_max_alltime; + private string _users_registered; + private string _subs_downloads; + private string _subs_subtitle_files; + private string _movies_total; + private string _movies_aka; + private string _total_subtitles_languages; + private List _last_update_strings = new List(); + + /// + /// Version of server's XML-RPC API implementation + /// + [Description("Version of server's XML-RPC API implementation"), Category("OS")] + public string xmlrpc_version { get { return _xmlrpc_version; } set { _xmlrpc_version = value; } } + /// + /// XML-RPC interface URL + /// + [Description("XML-RPC interface URL"), Category("OS")] + public string xmlrpc_url { get { return _xmlrpc_url; } set { _xmlrpc_url = value; } } + /// + /// Server's application name and version + /// + [Description("Server's application name and version"), Category("OS")] + public string application { get { return _application; } set { _application = value; } } + /// + /// Contact e-mail address for server related quuestions and problems + /// + [Description("Contact e-mail address for server related quuestions and problems"), Category("OS")] + public string contact { get { return _contact; } set { _contact = value; } } + /// + /// Main server URL + /// + [Description("Main server URL"), Category("OS")] + public string website_url { get { return _website_url; } set { _website_url = value; } } + /// + /// Number of users currently online + /// + [Description("Number of users currently online"), Category("OS")] + public int users_online_total { get { return _users_online_total; } set { _users_online_total = value; } } + /// + /// Number of users currently online using a client application (XML-RPC API) + /// + [Description("Number of users currently online using a client application (XML-RPC API)"), Category("OS")] + public int users_online_program { get { return _users_online_program; } set { _users_online_program = value; } } + /// + /// Number of currently logged-in users + /// + [Description("Number of currently logged-in users"), Category("OS")] + public int users_loggedin { get { return _users_loggedin; } set { _users_loggedin = value; } } + /// + /// Maximum number of users throughout the history + /// + [Description("Maximum number of users throughout the history"), Category("OS")] + public string users_max_alltime { get { return _users_max_alltime; } set { _users_max_alltime = value; } } + /// + /// Number of registered users + /// + [Description("Number of registered users"), Category("OS")] + public string users_registered { get { return _users_registered; } set { _users_registered = value; } } + /// + /// Total number of subtitle downloads + /// + [Description("Total number of subtitle downloads"), Category("OS")] + public string subs_downloads { get { return _subs_downloads; } set { _subs_downloads = value; } } + /// + /// Total number of subtitle files stored on the server + /// + [Description("Total number of subtitle files stored on the server"), Category("OS")] + public string subs_subtitle_files { get { return _subs_subtitle_files; } set { _subs_subtitle_files = value; } } + /// + /// Total number of movies in the database + /// + [Description("Total number of movies in the database"), Category("OS")] + public string movies_total { get { return _movies_total; } set { _movies_total = value; } } + /// + /// Total number of movie A.K.A. titles in the database + /// + [Description("Total number of movie A.K.A. titles in the database"), Category("OS")] + public string movies_aka { get { return _movies_aka; } set { _movies_aka = value; } } + /// + /// Total number of subtitle languages supported + /// + [Description("Total number of subtitle languages supported"), Category("OS")] + public string total_subtitles_languages { get { return _total_subtitles_languages; } set { _total_subtitles_languages = value; } } + /// + /// Structure containing information about last updates of translations. + /// + [Description("Structure containing information about last updates of translations"), Category("OS")] + public List last_update_strings { get { return _last_update_strings; } set { _last_update_strings = value; } } + } +} diff --git a/OpenSubtitlesHandler/MethodResponses/MethodResponseSubtitleDownload.cs b/OpenSubtitlesHandler/MethodResponses/MethodResponseSubtitleDownload.cs new file mode 100644 index 0000000000..7ad9f38ec4 --- /dev/null +++ b/OpenSubtitlesHandler/MethodResponses/MethodResponseSubtitleDownload.cs @@ -0,0 +1,44 @@ +/* This file is part of OpenSubtitles Handler + A library that handle OpenSubtitles.org XML-RPC methods. + + Copyright © Ala Ibrahim Hadid 2013 + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + */ +using System; +using System.Collections.Generic; +namespace OpenSubtitlesHandler +{ + /// + /// The response that should be used by subtitle download methods. + /// + [MethodResponseDescription("SubtitleDownload method response", + "SubtitleDownload method response hold all expected values from server.")] + public class MethodResponseSubtitleDownload : IMethodResponse + { + public MethodResponseSubtitleDownload() + : base() + { + results = new List(); + } + public MethodResponseSubtitleDownload(string name, string message) + : base(name, message) + { + results = new List(); + } + private List results; + public List Results + { get { return results; } set { results = value; } } + } +} diff --git a/OpenSubtitlesHandler/MethodResponses/MethodResponseSubtitleSearch.cs b/OpenSubtitlesHandler/MethodResponses/MethodResponseSubtitleSearch.cs new file mode 100644 index 0000000000..c359c0ffd0 --- /dev/null +++ b/OpenSubtitlesHandler/MethodResponses/MethodResponseSubtitleSearch.cs @@ -0,0 +1,46 @@ +/* This file is part of OpenSubtitles Handler + A library that handle OpenSubtitles.org XML-RPC methods. + + Copyright © Ala Ibrahim Hadid 2013 + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + */ +using System; +using System.Collections.Generic; + +namespace OpenSubtitlesHandler +{ + /// + /// Response to SearchSubtitle successed call. + /// + [MethodResponseDescription("SubtitleSearch method response", + "SubtitleSearch method response hold all expected values from server.")] + public class MethodResponseSubtitleSearch : IMethodResponse + { + public MethodResponseSubtitleSearch() + : base() + { + results = new List(); + } + public MethodResponseSubtitleSearch(string name, string message) + : base(name, message) + { + results = new List(); + } + + private List results; + public List Results + { get { return results; } set { results = value; } } + } +} diff --git a/OpenSubtitlesHandler/MethodResponses/MethodResponseSubtitlesVote.cs b/OpenSubtitlesHandler/MethodResponses/MethodResponseSubtitlesVote.cs new file mode 100644 index 0000000000..1f5364f0c1 --- /dev/null +++ b/OpenSubtitlesHandler/MethodResponses/MethodResponseSubtitlesVote.cs @@ -0,0 +1,44 @@ +/* This file is part of OpenSubtitles Handler + A library that handle OpenSubtitles.org XML-RPC methods. + + Copyright © Ala Ibrahim Hadid 2013 + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + */ +using System; + +namespace OpenSubtitlesHandler +{ + [MethodResponseDescription("SubtitlesVote method response", + "SubtitlesVote method response hold all expected values from server.")] + public class MethodResponseSubtitlesVote : IMethodResponse + { + public MethodResponseSubtitlesVote() + : base() + { } + public MethodResponseSubtitlesVote(string name, string message) + : base(name, message) + { } + private string _SubRating; + private string _SubSumVotes; + private string _IDSubtitle; + + public string SubRating + { get { return _SubRating; } set { _SubRating = value; } } + public string SubSumVotes + { get { return _SubSumVotes; } set { _SubSumVotes = value; } } + public string IDSubtitle + { get { return _IDSubtitle; } set { _IDSubtitle = value; } } + } +} diff --git a/OpenSubtitlesHandler/MethodResponses/MethodResponseTryUploadSubtitles.cs b/OpenSubtitlesHandler/MethodResponses/MethodResponseTryUploadSubtitles.cs new file mode 100644 index 0000000000..9dbf1576db --- /dev/null +++ b/OpenSubtitlesHandler/MethodResponses/MethodResponseTryUploadSubtitles.cs @@ -0,0 +1,40 @@ +/* This file is part of OpenSubtitles Handler + A library that handle OpenSubtitles.org XML-RPC methods. + + Copyright © Ala Ibrahim Hadid 2013 + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + */ +using System; +using System.Collections.Generic; + +namespace OpenSubtitlesHandler +{ + [MethodResponseDescription("TryUploadSubtitles method response", + "TryUploadSubtitles method response hold all expected values from server.")] + public class MethodResponseTryUploadSubtitles : IMethodResponse + { + public MethodResponseTryUploadSubtitles() + : base() + { } + public MethodResponseTryUploadSubtitles(string name, string message) + : base(name, message) + { } + private int alreadyindb; + private List results = new List(); + + public int AlreadyInDB { get { return alreadyindb; } set { alreadyindb = value; } } + public List Results { get { return results; } set { results = value; } } + } +} diff --git a/OpenSubtitlesHandler/MethodResponses/MethodResponseUploadSubtitles.cs b/OpenSubtitlesHandler/MethodResponses/MethodResponseUploadSubtitles.cs new file mode 100644 index 0000000000..3b2320db28 --- /dev/null +++ b/OpenSubtitlesHandler/MethodResponses/MethodResponseUploadSubtitles.cs @@ -0,0 +1,39 @@ +/* This file is part of OpenSubtitles Handler + A library that handle OpenSubtitles.org XML-RPC methods. + + Copyright © Ala Ibrahim Hadid 2013 + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + */ +using System; + +namespace OpenSubtitlesHandler +{ + [MethodResponseDescription("UploadSubtitles method response", + "UploadSubtitles method response hold all expected values from server.")] + public class MethodResponseUploadSubtitles : IMethodResponse + { + public MethodResponseUploadSubtitles() + : base() + { } + public MethodResponseUploadSubtitles(string name, string message) + : base(name, message) + { } + private string _data; + private bool _subtitles; + + public string Data { get { return _data; } set { _data = value; } } + public bool SubTitles { get { return _subtitles; } set { _subtitles = value; } } + } +} diff --git a/OpenSubtitlesHandler/Methods Implemeted.txt b/OpenSubtitlesHandler/Methods Implemeted.txt new file mode 100644 index 0000000000..5d7ae0d493 --- /dev/null +++ b/OpenSubtitlesHandler/Methods Implemeted.txt @@ -0,0 +1,39 @@ +List of available OpenSubtitles.org server XML-RPC methods. +========================================================== +Legends: +* OK: this method is fully implemented, tested and works fine. +* TODO: this method is in the plan to be added. +* NOT TESTED: this method added and expected to work fine but never tested. +* NOT WORK (x): this method added but not work. x= Description of the error. + +-------------------------------------------- +Method name | Status +-------------------------|------------------ +LogIn | OK +LogOut | OK +NoOperation | OK +SearchSubtitles | OK +DownloadSubtitles | OK +SearchToMail | OK +TryUploadSubtitles | OK +UploadSubtitles | OK +SearchMoviesOnIMDB | OK +GetIMDBMovieDetails | OK +InsertMovie | OK +InsertMovieHash | OK +ServerInfo | OK +ReportWrongMovieHash | OK +ReportWrongImdbMovie | OK +SubtitlesVote | OK +AddComment | OK +AddRequest | OK +GetComments | OK +GetSubLanguages | OK +DetectLanguage | OK +GetAvailableTranslations | OK +GetTranslation | NOT WORK (Returns status of error 410 'Other or unknown error') +AutoUpdate | NOT WORK (Returns status: 'parse error. not well formed') +CheckMovieHash | OK +CheckMovieHash2 | OK +CheckSubHash | OK +-------------------------------------------- \ No newline at end of file diff --git a/OpenSubtitlesHandler/MovieHasher.cs b/OpenSubtitlesHandler/MovieHasher.cs new file mode 100644 index 0000000000..a14bd20f8b --- /dev/null +++ b/OpenSubtitlesHandler/MovieHasher.cs @@ -0,0 +1,59 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace OpenSubtitlesHandler +{ + public class MovieHasher + { + public static byte[] ComputeMovieHash(string filename) + { + byte[] result; + using (Stream input = File.OpenRead(filename)) + { + result = ComputeMovieHash(input); + } + return result; + } + + private static byte[] ComputeMovieHash(Stream input) + { + long lhash, streamsize; + streamsize = input.Length; + lhash = streamsize; + + long i = 0; + byte[] buffer = new byte[sizeof(long)]; + while (i < 65536 / sizeof(long) && (input.Read(buffer, 0, sizeof(long)) > 0)) + { + i++; + lhash += BitConverter.ToInt64(buffer, 0); + } + + input.Position = Math.Max(0, streamsize - 65536); + i = 0; + while (i < 65536 / sizeof(long) && (input.Read(buffer, 0, sizeof(long)) > 0)) + { + i++; + lhash += BitConverter.ToInt64(buffer, 0); + } + input.Close(); + byte[] result = BitConverter.GetBytes(lhash); + Array.Reverse(result); + return result; + } + + public static string ToHexadecimal(byte[] bytes) + { + StringBuilder hexBuilder = new StringBuilder(); + for (int i = 0; i < bytes.Length; i++) + { + hexBuilder.Append(bytes[i].ToString("x2")); + } + return hexBuilder.ToString(); + } + } +} diff --git a/OpenSubtitlesHandler/Movies/CheckMovieHash2Data.cs b/OpenSubtitlesHandler/Movies/CheckMovieHash2Data.cs new file mode 100644 index 0000000000..4f6de82b1a --- /dev/null +++ b/OpenSubtitlesHandler/Movies/CheckMovieHash2Data.cs @@ -0,0 +1,42 @@ +/* This file is part of OpenSubtitles Handler + A library that handle OpenSubtitles.org XML-RPC methods. + + Copyright © Ala Ibrahim Hadid 2013 + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + */ + +namespace OpenSubtitlesHandler +{ + public struct CheckMovieHash2Data + { + private string _MovieHash; + private string _MovieImdbID; + private string _MovieName; + private string _MovieYear; + private string _MovieKind; + private string _SeriesSeason; + private string _SeriesEpisode; + private string _SeenCount; + + public string MovieHash { get { return _MovieHash; } set { _MovieHash = value; } } + public string MovieImdbID { get { return _MovieImdbID; } set { _MovieImdbID = value; } } + public string MovieName { get { return _MovieName; } set { _MovieName = value; } } + public string MovieYear { get { return _MovieYear; } set { _MovieYear = value; } } + public string MovieKind { get { return _MovieKind; } set { _MovieKind = value; } } + public string SeriesSeason { get { return _SeriesSeason; } set { _SeriesSeason = value; } } + public string SeriesEpisode { get { return _SeriesEpisode; } set { _SeriesEpisode = value; } } + public string SeenCount { get { return _SeenCount; } set { _SeenCount = value; } } + } +} diff --git a/OpenSubtitlesHandler/Movies/CheckMovieHash2Result.cs b/OpenSubtitlesHandler/Movies/CheckMovieHash2Result.cs new file mode 100644 index 0000000000..e91541c3ce --- /dev/null +++ b/OpenSubtitlesHandler/Movies/CheckMovieHash2Result.cs @@ -0,0 +1,37 @@ +/* This file is part of OpenSubtitles Handler + A library that handle OpenSubtitles.org XML-RPC methods. + + Copyright © Ala Ibrahim Hadid 2013 + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + */ +using System; +using System.Collections.Generic; + +namespace OpenSubtitlesHandler +{ + public class CheckMovieHash2Result + { + private string name; + private List data = new List(); + + public string Name { get { return name; } set { name = value; } } + public List Items { get { return data; } set { data = value; } } + + public override string ToString() + { + return name; + } + } +} diff --git a/OpenSubtitlesHandler/Movies/CheckMovieHashResult.cs b/OpenSubtitlesHandler/Movies/CheckMovieHashResult.cs new file mode 100644 index 0000000000..b51181f237 --- /dev/null +++ b/OpenSubtitlesHandler/Movies/CheckMovieHashResult.cs @@ -0,0 +1,42 @@ +/* This file is part of OpenSubtitles Handler + A library that handle OpenSubtitles.org XML-RPC methods. + + Copyright © Ala Ibrahim Hadid 2013 + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + */ +using System; + +namespace OpenSubtitlesHandler +{ + public struct CheckMovieHashResult + { + private string name; + private string _MovieHash; + private string _MovieImdbID; + private string _MovieName; + private string _MovieYear; + + public string MovieHash { get { return _MovieHash; } set { _MovieHash = value; } } + public string MovieImdbID { get { return _MovieImdbID; } set { _MovieImdbID = value; } } + public string MovieName { get { return _MovieName; } set { _MovieName = value; } } + public string MovieYear { get { return _MovieYear; } set { _MovieYear = value; } } + public string Name { get { return name; } set { name = value; } } + + public override string ToString() + { + return name; + } + } +} diff --git a/OpenSubtitlesHandler/Movies/InsertMovieHashParameters.cs b/OpenSubtitlesHandler/Movies/InsertMovieHashParameters.cs new file mode 100644 index 0000000000..58402324b5 --- /dev/null +++ b/OpenSubtitlesHandler/Movies/InsertMovieHashParameters.cs @@ -0,0 +1,38 @@ +/* This file is part of OpenSubtitles Handler + A library that handle OpenSubtitles.org XML-RPC methods. + + Copyright © Ala Ibrahim Hadid 2013 + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + */ + +namespace OpenSubtitlesHandler +{ + public class InsertMovieHashParameters + { + private string _moviehash = ""; + private string _moviebytesize = ""; + private string _imdbid = ""; + private string _movietimems = ""; + private string _moviefps = ""; + private string _moviefilename = ""; + + public string moviehash { get { return _moviehash; } set { _moviehash = value; } } + public string moviebytesize { get { return _moviebytesize; } set { _moviebytesize = value; } } + public string imdbid { get { return _imdbid; } set { _imdbid = value; } } + public string movietimems { get { return _movietimems; } set { _movietimems = value; } } + public string moviefps { get { return _moviefps; } set { _moviefps = value; } } + public string moviefilename { get { return _moviefilename; } set { _moviefilename = value; } } + } +} diff --git a/OpenSubtitlesHandler/Movies/MovieSearchResult.cs b/OpenSubtitlesHandler/Movies/MovieSearchResult.cs new file mode 100644 index 0000000000..fe085acc43 --- /dev/null +++ b/OpenSubtitlesHandler/Movies/MovieSearchResult.cs @@ -0,0 +1,41 @@ +/* This file is part of OpenSubtitles Handler + A library that handle OpenSubtitles.org XML-RPC methods. + + Copyright © Ala Ibrahim Hadid 2013 + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + */ +using System; + +namespace OpenSubtitlesHandler +{ + public struct MovieSearchResult + { + private string id; + private string title; + + public string ID + { get { return id; } set { id = value; } } + public string Title + { get { return title; } set { title = value; } } + /// + /// Title + /// + /// + public override string ToString() + { + return title; + } + } +} diff --git a/OpenSubtitlesHandler/Movies/SearchToMailMovieParameter.cs b/OpenSubtitlesHandler/Movies/SearchToMailMovieParameter.cs new file mode 100644 index 0000000000..d5e3fc4c6b --- /dev/null +++ b/OpenSubtitlesHandler/Movies/SearchToMailMovieParameter.cs @@ -0,0 +1,30 @@ +/* This file is part of OpenSubtitles Handler + A library that handle OpenSubtitles.org XML-RPC methods. + + Copyright © Ala Ibrahim Hadid 2013 + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + */ + +namespace OpenSubtitlesHandler +{ + public struct SearchToMailMovieParameter + { + private string _moviehash; + private double _moviesize; + + public string moviehash { get { return _moviehash; } set { _moviehash = value; } } + public double moviesize { get { return _moviesize; } set { _moviesize = value; } } + } +} diff --git a/OpenSubtitlesHandler/OpenSubtitles.cs b/OpenSubtitlesHandler/OpenSubtitles.cs new file mode 100644 index 0000000000..ba3c461a1b --- /dev/null +++ b/OpenSubtitlesHandler/OpenSubtitles.cs @@ -0,0 +1,2387 @@ +/* This file is part of OpenSubtitles Handler + A library that handle OpenSubtitles.org XML-RPC methods. + + Copyright © Ala Ibrahim Hadid 2013 + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + */ +using System; +using System.Text; +using System.Collections.Generic; +using System.IO; +using OpenSubtitlesHandler.Console; +using XmlRpcHandler; + +namespace OpenSubtitlesHandler +{ + /// + /// The core of the OpenSubtitles Handler library. All members are static. + /// + public sealed class OpenSubtitles + { + private static string XML_PRC_USERAGENT = ""; + // This is session id after log in, important value and MUST be set by LogIn before any other call. + private static string TOKEN = ""; + + /// + /// Set the useragent value. This must be called before doing anything else. + /// + /// The useragent value + public static void SetUserAgent(string agent) + { + XML_PRC_USERAGENT = agent; + } + + /*Session handling*/ + /// + /// Send a LogIn request, this must be called before anything else in this class. + /// + /// The user name of OpenSubtitles + /// The password + /// The language, usally en + /// Status of the login operation + public static IMethodResponse LogIn(string userName, string password, string language) + { + // Method call .. + List parms = new List(); + parms.Add(new XmlRpcValueBasic(userName)); + parms.Add(new XmlRpcValueBasic(password)); + parms.Add(new XmlRpcValueBasic(language)); + parms.Add(new XmlRpcValueBasic(XML_PRC_USERAGENT)); + XmlRpcMethodCall call = new XmlRpcMethodCall("LogIn", parms); + OSHConsole.WriteLine("Sending LogIn request to the server ...", DebugCode.Good); + + //File.WriteAllText(".\\request.txt", Encoding.UTF8.GetString(XmlRpcGenerator.Generate(call))); + // 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. We expect Struct here. + XmlRpcMethodCall[] calls = XmlRpcGenerator.DecodeMethodResponse(response); + if (calls.Length > 0) + { + if (calls[0].Parameters.Count > 0) + { + XmlRpcValueStruct mainStruct = (XmlRpcValueStruct)calls[0].Parameters[0]; + MethodResponseLogIn re = new MethodResponseLogIn("Success", "Log in successful."); + foreach (XmlRpcStructMember MEMBER in mainStruct.Members) + { + switch (MEMBER.Name) + { + case "token": re.Token = TOKEN = MEMBER.Data.Data.ToString(); OSHConsole.WriteLine(MEMBER.Name + "= " + MEMBER.Data.Data.ToString()); break; + case "seconds": re.Seconds = (double)MEMBER.Data.Data; OSHConsole.WriteLine(MEMBER.Name + "= " + MEMBER.Data.Data.ToString()); break; + case "status": re.Status = MEMBER.Data.Data.ToString(); OSHConsole.WriteLine(MEMBER.Name + "= " + MEMBER.Data.Data.ToString()); break; + } + } + return re; + } + } + } + else + { + OSHConsole.WriteLine(response, DebugCode.Error); + return new MethodResponseError("Fail", response); + } + return new MethodResponseError("Fail", "Log in failed !"); + } + /// + /// Log out from the server. Call this to terminate the session. + /// + /// + public static IMethodResponse LogOut() + { + 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 parms = new List(); + parms.Add(new XmlRpcValueBasic(TOKEN, XmlRpcBasicValueType.String)); + XmlRpcMethodCall call = new XmlRpcMethodCall("LogOut", parms); + + OSHConsole.WriteLine("Sending LogOut 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. We expect Struct here. + XmlRpcMethodCall[] calls = XmlRpcGenerator.DecodeMethodResponse(response); + if (calls.Length > 0) + { + if (calls[0].Parameters.Count > 0) + { + XmlRpcValueStruct strct = (XmlRpcValueStruct)calls[0].Parameters[0]; + OSHConsole.WriteLine("STATUS=" + ((XmlRpcValueBasic)strct.Members[0].Data).Data.ToString()); + OSHConsole.WriteLine("SECONDS=" + ((XmlRpcValueBasic)strct.Members[1].Data).Data.ToString()); + MethodResponseLogIn re = new MethodResponseLogIn("Success", "Log out successful."); + re.Status = ((XmlRpcValueBasic)strct.Members[0].Data).Data.ToString(); + re.Seconds = (double)((XmlRpcValueBasic)strct.Members[1].Data).Data; + return re; + } + } + } + else + { + OSHConsole.WriteLine(response, DebugCode.Error); + return new MethodResponseError("Fail", response); + } + return new MethodResponseError("Fail", "Log out failed !"); + } + /// + /// keep-alive user's session, verify token/session validity + /// + /// Status of the call operation + public static IMethodResponse NoOperation() + { + 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 parms = new List(); + parms.Add(new XmlRpcValueBasic(TOKEN, XmlRpcBasicValueType.String)); + parms.Add(new XmlRpcValueBasic(XML_PRC_USERAGENT, XmlRpcBasicValueType.String)); + XmlRpcMethodCall call = new XmlRpcMethodCall("NoOperation", parms); + + OSHConsole.WriteLine("Sending NoOperation 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. We expect Struct here. + XmlRpcMethodCall[] calls = XmlRpcGenerator.DecodeMethodResponse(response); + if (calls.Length > 0) + { + if (calls[0].Parameters.Count > 0) + { + MethodResponseNoOperation R = new MethodResponseNoOperation(); + XmlRpcValueStruct mainStruct = (XmlRpcValueStruct)calls[0].Parameters[0]; + // 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); break; + case "seconds": R.Seconds = (double)MEMBER.Data.Data; OSHConsole.WriteLine(MEMBER.Name + "= " + MEMBER.Data.Data); break; + case "download_limits": + XmlRpcValueStruct dlStruct = (XmlRpcValueStruct)MEMBER.Data; + foreach (XmlRpcStructMember dlmember in dlStruct.Members) + { + OSHConsole.WriteLine(" >" + dlmember.Name + "= " + dlmember.Data.Data.ToString()); + switch (dlmember.Name) + { + case "global_wrh_download_limit": R.global_wrh_download_limit = dlmember.Data.Data.ToString(); break; + case "client_ip": R.client_ip = dlmember.Data.Data.ToString(); break; + case "limit_check_by": R.limit_check_by = dlmember.Data.Data.ToString(); break; + case "client_24h_download_count": R.client_24h_download_count = dlmember.Data.Data.ToString(); break; + case "client_downlaod_quota": R.client_downlaod_quota = dlmember.Data.Data.ToString(); break; + case "client_24h_download_limit": R.client_24h_download_limit = dlmember.Data.Data.ToString(); break; + } + } + break; + } + } + return R; + } + } + } + else + { + OSHConsole.WriteLine(response, DebugCode.Error); + return new MethodResponseError("Fail", response); + } + return new MethodResponseError("Fail", "NoOperation call failed !"); + } + /*Search and download*/ + /// + /// Search for subtitle files matching your videos using either video file hashes or IMDb IDs. + /// + /// List of search subtitle parameters which each one represents 'struct parameter' as descriped at http://trac.opensubtitles.org/projects/opensubtitles/wiki/XmlRpcSearchSubtitles + /// Status of the call operation. If the call success the response will be 'MethodResponseSubtitleSearch' + public static IMethodResponse SearchSubtitles(SubtitleSearchParameters[] 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."); + } + 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 parms = new List(); + // 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()); + // 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(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) + { + // 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 !"); + } + /// + /// Download subtitle file(s) + /// + /// The subtitle IDS (an array of IDSubtitleFile value that given by server as SearchSubtiles results) + /// Status of the call operation. If the call success the response will be 'MethodResponseSubtitleDownload' which will hold downloaded subtitles + public static IMethodResponse DownloadSubtitles(int[] subIDS) + { + 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 (subIDS == null) + { + OSHConsole.UpdateLine("No subtitle id passed !!", DebugCode.Error); + return new MethodResponseError("Fail", "No subtitle id passed"); ; + } + if (subIDS.Length == 0) + { + OSHConsole.UpdateLine("No subtitle id passed !!", DebugCode.Error); + return new MethodResponseError("Fail", "No subtitle id passed"); ; + } + // Method call .. + List parms = new List(); + // 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 (int id in subIDS) + { + array.Values.Add(new XmlRpcValueBasic(id, XmlRpcBasicValueType.Int)); + } + // Add the array to the parameters + parms.Add(array); + // Call ! + XmlRpcMethodCall call = new XmlRpcMethodCall("DownloadSubtitles", parms); + OSHConsole.WriteLine("Sending DownloadSubtitles 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) + { + // 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 + MethodResponseSubtitleDownload R = new MethodResponseSubtitleDownload(); + + // 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("Download results:"); + XmlRpcValueArray rarray = (XmlRpcValueArray)MEMBER.Data; + foreach (IXmlRpcValue subStruct in rarray.Values) + { + if (subStruct == null) continue; + if (!(subStruct is XmlRpcValueStruct)) continue; + + SubtitleDownloadResult result = new SubtitleDownloadResult(); + 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 "idsubtitlefile": result.IdSubtitleFile = (string)submember.Data.Data; break; + case "data": result.Data = (string)submember.Data.Data; break; + } + } + R.Results.Add(result); + OSHConsole.WriteLine("> IDSubtilteFile= " + 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", "DownloadSubtitles call failed !"); + } + /// + /// Returns comments for subtitles + /// + /// The subtitle IDS (an array of IDSubtitleFile value that given by server as SearchSubtiles results) + /// Status of the call operation. If the call success the response will be 'MethodResponseGetComments' + public static IMethodResponse GetComments(int[] subIDS) + { + 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 (subIDS == null) + { + OSHConsole.UpdateLine("No subtitle id passed !!", DebugCode.Error); + return new MethodResponseError("Fail", "No subtitle id passed"); ; + } + if (subIDS.Length == 0) + { + OSHConsole.UpdateLine("No subtitle id passed !!", DebugCode.Error); + return new MethodResponseError("Fail", "No subtitle id passed"); ; + } + // Method call .. + List parms = new List(); + // Add token param + parms.Add(new XmlRpcValueBasic(TOKEN)); + // Add subtitle search parameters. Each one will be like 'array' of structs. + XmlRpcValueArray array = new XmlRpcValueArray(subIDS); + // Add the array to the parameters + parms.Add(array); + // Call ! + XmlRpcMethodCall call = new XmlRpcMethodCall("GetComments", parms); + OSHConsole.WriteLine("Sending GetComments 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 + MethodResponseGetComments R = new MethodResponseGetComments(); + + // 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("Comments results:"); + XmlRpcValueArray rarray = (XmlRpcValueArray)MEMBER.Data; + foreach (IXmlRpcValue commentStruct in rarray.Values) + { + if (commentStruct == null) continue; + if (!(commentStruct is XmlRpcValueStruct)) continue; + + GetCommentsResult result = new GetCommentsResult(); + foreach (XmlRpcStructMember commentmember in ((XmlRpcValueStruct)commentStruct).Members) + { + // To avoid errors of arranged info or missing ones, let's do it with switch.. + switch (commentmember.Name) + { + case "IDSubtitle": result.IDSubtitle = (string)commentmember.Data.Data; break; + case "UserID": result.UserID = (string)commentmember.Data.Data; break; + case "UserNickName": result.UserNickName = (string)commentmember.Data.Data; break; + case "Comment": result.Comment = (string)commentmember.Data.Data; break; + case "Created": result.Created = (string)commentmember.Data.Data; break; + } + } + R.Results.Add(result); + OSHConsole.WriteLine("> IDSubtitle= " + 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", "GetComments call failed !"); + } + + /// + /// Schedule a periodical search for subtitles matching given video files, send results to user's e-mail address. + /// + /// The language 3 lenght ids array + /// The movies parameters + /// Status of the call operation. If the call success the response will be 'MethodResponseSearchToMail' + 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 parms = new List(); + 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()); + 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 !"); + } + /*Movies*/ + /// + /// Search for a movie (using movie title) + /// + /// Movie title user is searching for, this is cleaned-up a bit (remove dvdrip, etc.) before searching + /// Status of the call operation. If the call success the response will be 'MethodResponseSubtitleSearch' + public static IMethodResponse SearchMoviesOnIMDB(string query) + { + 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 parms = new List(); + // Add token param + parms.Add(new XmlRpcValueBasic(TOKEN, XmlRpcBasicValueType.String)); + // Add query param + parms.Add(new XmlRpcValueBasic(query, XmlRpcBasicValueType.String)); + // Call ! + XmlRpcMethodCall call = new XmlRpcMethodCall("SearchMoviesOnIMDB", parms); + OSHConsole.WriteLine("Sending SearchMoviesOnIMDB 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 + MethodResponseMovieSearch R = new MethodResponseMovieSearch(); + + // 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; + + MovieSearchResult result = new MovieSearchResult(); + 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 "id": result.ID = (string)submember.Data.Data; break; + case "title": result.Title = (string)submember.Data.Data; 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", "SearchMoviesOnIMDB call failed !"); + } + /// + /// Get movie details for given IMDb ID + /// + /// http://www.imdb.com/ + /// Status of the call operation. If the call success the response will be 'MethodResponseMovieDetails' + public static IMethodResponse GetIMDBMovieDetails(string imdbid) + { + 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 parms = new List(); + // Add token param + parms.Add(new XmlRpcValueBasic(TOKEN)); + // Add query param + parms.Add(new XmlRpcValueBasic(imdbid)); + // Call ! + XmlRpcMethodCall call = new XmlRpcMethodCall("GetIMDBMovieDetails", parms); + OSHConsole.WriteLine("Sending GetIMDBMovieDetails 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 + MethodResponseMovieDetails R = new MethodResponseMovieDetails(); + + // 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") + { + // We expect struct with details... + if (MEMBER.Data is XmlRpcValueStruct) + { + OSHConsole.WriteLine("Details result:"); + XmlRpcValueStruct detailsStruct = (XmlRpcValueStruct)MEMBER.Data; + foreach (XmlRpcStructMember dmem in detailsStruct.Members) + { + switch (dmem.Name) + { + case "id": R.ID = dmem.Data.Data.ToString(); OSHConsole.WriteLine(">" + dmem.Name + "= " + dmem.Data.Data.ToString()); break; + case "title": R.Title = dmem.Data.Data.ToString(); OSHConsole.WriteLine(">" + dmem.Name + "= " + dmem.Data.Data.ToString()); break; + case "year": R.Year = dmem.Data.Data.ToString(); OSHConsole.WriteLine(">" + dmem.Name + "= " + dmem.Data.Data.ToString()); break; + case "cover": R.CoverLink = dmem.Data.Data.ToString(); OSHConsole.WriteLine(">" + dmem.Name + "= " + dmem.Data.Data.ToString()); break; + case "duration": R.Duration = dmem.Data.Data.ToString(); OSHConsole.WriteLine(">" + dmem.Name + "= " + dmem.Data.Data.ToString()); break; + case "tagline": R.Tagline = dmem.Data.Data.ToString(); OSHConsole.WriteLine(">" + dmem.Name + "= " + dmem.Data.Data.ToString()); break; + case "plot": R.Plot = dmem.Data.Data.ToString(); OSHConsole.WriteLine(">" + dmem.Name + "= " + dmem.Data.Data.ToString()); break; + case "goofs": R.Goofs = dmem.Data.Data.ToString(); OSHConsole.WriteLine(">" + dmem.Name + "= " + dmem.Data.Data.ToString()); break; + case "trivia": R.Trivia = dmem.Data.Data.ToString(); OSHConsole.WriteLine(">" + dmem.Name + "= " + dmem.Data.Data.ToString()); break; + case "cast": + // this is another struct with cast members... + OSHConsole.WriteLine(">" + dmem.Name + "= "); + XmlRpcValueStruct castStruct = (XmlRpcValueStruct)dmem.Data; + foreach (XmlRpcStructMember castMemeber in castStruct.Members) + { + R.Cast.Add(castMemeber.Data.Data.ToString()); + OSHConsole.WriteLine(" >" + castMemeber.Data.Data.ToString()); + } + break; + case "directors": + OSHConsole.WriteLine(">" + dmem.Name + "= "); + // this is another struct with directors members... + XmlRpcValueStruct directorsStruct = (XmlRpcValueStruct)dmem.Data; + foreach (XmlRpcStructMember directorsMember in directorsStruct.Members) + { + R.Directors.Add(directorsMember.Data.Data.ToString()); + OSHConsole.WriteLine(" >" + directorsMember.Data.Data.ToString()); + } + break; + case "writers": + OSHConsole.WriteLine(">" + dmem.Name + "= "); + // this is another struct with writers members... + XmlRpcValueStruct writersStruct = (XmlRpcValueStruct)dmem.Data; + foreach (XmlRpcStructMember writersMember in writersStruct.Members) + { + R.Writers.Add(writersMember.Data.Data.ToString()); + OSHConsole.WriteLine("+->" + writersMember.Data.Data.ToString()); + } + break; + case "awards": + // this is an array of genres... + XmlRpcValueArray awardsArray = (XmlRpcValueArray)dmem.Data; + foreach (XmlRpcValueBasic award in awardsArray.Values) + { + R.Awards.Add(award.Data.ToString()); + OSHConsole.WriteLine(" >" + award.Data.ToString()); + } + break; + case "genres": + OSHConsole.WriteLine(">" + dmem.Name + "= "); + // this is an array of genres... + XmlRpcValueArray genresArray = (XmlRpcValueArray)dmem.Data; + foreach (XmlRpcValueBasic genre in genresArray.Values) + { + R.Genres.Add(genre.Data.ToString()); + OSHConsole.WriteLine(" >" + genre.Data.ToString()); + } + break; + case "country": + OSHConsole.WriteLine(">" + dmem.Name + "= "); + // this is an array of country... + XmlRpcValueArray countryArray = (XmlRpcValueArray)dmem.Data; + foreach (XmlRpcValueBasic country in countryArray.Values) + { + R.Country.Add(country.Data.ToString()); + OSHConsole.WriteLine(" >" + country.Data.ToString()); + } + break; + case "language": + OSHConsole.WriteLine(">" + dmem.Name + "= "); + // this is an array of language... + XmlRpcValueArray languageArray = (XmlRpcValueArray)dmem.Data; + foreach (XmlRpcValueBasic language in languageArray.Values) + { + R.Language.Add(language.Data.ToString()); + OSHConsole.WriteLine(" >" + language.Data.ToString()); + } + break; + case "certification": + OSHConsole.WriteLine(">" + dmem.Name + "= "); + // this is an array of certification... + XmlRpcValueArray certificationArray = (XmlRpcValueArray)dmem.Data; + foreach (XmlRpcValueBasic certification in certificationArray.Values) + { + R.Certification.Add(certification.Data.ToString()); + OSHConsole.WriteLine(" >" + certification.Data.ToString()); + } + break; + } + } + } + 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", "GetIMDBMovieDetails call failed !"); + } + /// + /// Allows registered users to insert new movies (not stored in IMDb) to the database. + /// + /// Movie title + /// Release year + /// Status of the call operation. If the call success the response will be 'MethodResponseInsertMovie' + 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 parms = new List(); + // Add token param + parms.Add(new XmlRpcValueBasic(TOKEN, XmlRpcBasicValueType.String)); + // Add movieinfo struct + XmlRpcValueStruct movieinfo = new XmlRpcValueStruct(new List()); + 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 !"); + } + /// + /// Inserts or updates data to tables, which are used for CheckMovieHash() and !CheckMovieHash2(). + /// + /// The parameters + /// Status of the call operation. If the call success the response will be 'MethodResponseInsertMovieHash' + 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 parms = new List(); + parms.Add(new XmlRpcValueBasic(TOKEN, XmlRpcBasicValueType.String)); + foreach (InsertMovieHashParameters p in parameters) + { + XmlRpcValueStruct pstruct = new XmlRpcValueStruct(new List()); + 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 !"); + } + /*Reporting and rating*/ + /// + /// Get basic server information and statistics + /// + /// Status of the call operation. If the call success the response will be 'MethodResponseServerInfo' + public static IMethodResponse ServerInfo() + { + 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 parms = new List(); + parms.Add(new XmlRpcValueBasic(TOKEN, XmlRpcBasicValueType.String)); + parms.Add(new XmlRpcValueBasic(XML_PRC_USERAGENT, XmlRpcBasicValueType.String)); + XmlRpcMethodCall call = new XmlRpcMethodCall("ServerInfo", parms); + + OSHConsole.WriteLine("Sending ServerInfo 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 + MethodResponseServerInfo R = new MethodResponseServerInfo(); + + // 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 "xmlrpc_version": + R.xmlrpc_version = (string)MEMBER.Data.Data; + OSHConsole.WriteLine(">" + MEMBER.Name + "= " + MEMBER.Data.Data.ToString()); + break; + case "xmlrpc_url": + R.xmlrpc_url = (string)MEMBER.Data.Data; + OSHConsole.WriteLine(">" + MEMBER.Name + "= " + MEMBER.Data.Data.ToString()); + break; + case "application": + R.application = (string)MEMBER.Data.Data; + OSHConsole.WriteLine(">" + MEMBER.Name + "= " + MEMBER.Data.Data.ToString()); + break; + case "contact": + R.contact = (string)MEMBER.Data.Data; + OSHConsole.WriteLine(">" + MEMBER.Name + "= " + MEMBER.Data.Data.ToString()); + break; + case "website_url": + R.website_url = (string)MEMBER.Data.Data; + OSHConsole.WriteLine(">" + MEMBER.Name + "= " + MEMBER.Data.Data.ToString()); + break; + case "users_online_total": + R.users_online_total = (int)MEMBER.Data.Data; + OSHConsole.WriteLine(">" + MEMBER.Name + "= " + MEMBER.Data.Data.ToString()); + break; + case "users_online_program": + R.users_online_program = (int)MEMBER.Data.Data; + OSHConsole.WriteLine(">" + MEMBER.Name + "= " + MEMBER.Data.Data.ToString()); + break; + case "users_loggedin": + R.users_loggedin = (int)MEMBER.Data.Data; + OSHConsole.WriteLine(">" + MEMBER.Name + "= " + MEMBER.Data.Data.ToString()); + break; + case "users_max_alltime": + R.users_max_alltime = (string)MEMBER.Data.Data; + OSHConsole.WriteLine(">" + MEMBER.Name + "= " + MEMBER.Data.Data.ToString()); + break; + case "users_registered": + R.users_registered = (string)MEMBER.Data.Data; + OSHConsole.WriteLine(">" + MEMBER.Name + "= " + MEMBER.Data.Data.ToString()); + break; + case "subs_downloads": + R.subs_downloads = (string)MEMBER.Data.Data; + OSHConsole.WriteLine(">" + MEMBER.Name + "= " + MEMBER.Data.Data.ToString()); + break; + case "subs_subtitle_files": + R.subs_subtitle_files = (string)MEMBER.Data.Data; + OSHConsole.WriteLine(">" + MEMBER.Name + "= " + MEMBER.Data.Data.ToString()); + break; + case "movies_total": + R.movies_total = (string)MEMBER.Data.Data; + OSHConsole.WriteLine(">" + MEMBER.Name + "= " + MEMBER.Data.Data.ToString()); + break; + case "movies_aka": + R.movies_aka = (string)MEMBER.Data.Data; + OSHConsole.WriteLine(">" + MEMBER.Name + "= " + MEMBER.Data.Data.ToString()); + break; + case "total_subtitles_languages": + R.total_subtitles_languages = (string)MEMBER.Data.Data; + OSHConsole.WriteLine(">" + MEMBER.Name + "= " + MEMBER.Data.Data.ToString()); + break; + case "last_update_strings": + //R.total_subtitles_languages = (string)MEMBER.Data.Data; + OSHConsole.WriteLine(">" + MEMBER.Name + ":"); + XmlRpcValueStruct luStruct = (XmlRpcValueStruct)MEMBER.Data; + foreach (XmlRpcStructMember luMemeber in luStruct.Members) + { + R.last_update_strings.Add(luMemeber.Name + " [" + luMemeber.Data.Data.ToString() + "]"); + OSHConsole.WriteLine(" >" + luMemeber.Name + "= " + luMemeber.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", "ServerInfo call failed !"); + } + /// + /// Report wrong subtitle file <--> video file combination + /// + /// Identifier of the subtitle file <--> video file combination + /// Status of the call operation. If the call success the response will be 'MethodResponseReportWrongMovieHash' + public static IMethodResponse ReportWrongMovieHash(string IDSubMovieFile) + { + 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 parms = new List(); + parms.Add(new XmlRpcValueBasic(TOKEN, XmlRpcBasicValueType.String)); + parms.Add(new XmlRpcValueBasic(IDSubMovieFile, XmlRpcBasicValueType.String)); + XmlRpcMethodCall call = new XmlRpcMethodCall("ReportWrongMovieHash", parms); + + OSHConsole.WriteLine("Sending ReportWrongMovieHash 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 + MethodResponseReportWrongMovieHash R = new MethodResponseReportWrongMovieHash(); + + // 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", "ReportWrongMovieHash call failed !"); + } + /// + /// This method is needed to report bad movie hash for imdbid. This method should be used for correcting wrong entries, + /// when using CheckMovieHash2. Pass moviehash and moviebytesize for file, and imdbid as new, corrected one IMDBID + /// (id number without trailing zeroes). After some reports, moviehash will be linked to new imdbid. + /// + /// The movie hash + /// The movie size in bytes + /// The movie imbid + /// Status of the call operation. If the call success the response will be 'MethodResponseReportWrongImdbMovie' + public static IMethodResponse ReportWrongImdbMovie(string moviehash, string moviebytesize, string imdbid) + { + 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 parms = new List(); + parms.Add(new XmlRpcValueBasic(TOKEN, XmlRpcBasicValueType.String)); + XmlRpcValueStruct s = new XmlRpcValueStruct(new List()); + s.Members.Add(new XmlRpcStructMember("moviehash", new XmlRpcValueBasic(moviehash))); + s.Members.Add(new XmlRpcStructMember("moviebytesize", new XmlRpcValueBasic(moviebytesize))); + s.Members.Add(new XmlRpcStructMember("imdbid", new XmlRpcValueBasic(imdbid))); + parms.Add(s); + XmlRpcMethodCall call = new XmlRpcMethodCall("ReportWrongImdbMovie", parms); + + OSHConsole.WriteLine("Sending ReportWrongImdbMovie 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 + MethodResponseAddComment R = new MethodResponseAddComment(); + + // 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", "ReportWrongImdbMovie call failed !"); + } + /// + /// Rate subtitles + /// + /// Id of subtitle (NOT subtitle file) user wants to rate + /// Subtitle rating, must be in interval 1 (worst) to 10 (best). + /// Status of the call operation. If the call success the response will be 'MethodResponseSubtitlesVote' + public static IMethodResponse SubtitlesVote(int idsubtitle, int score) + { + 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 parms = new List(); + parms.Add(new XmlRpcValueBasic(TOKEN, XmlRpcBasicValueType.String)); + XmlRpcValueStruct s = new XmlRpcValueStruct(new List()); + s.Members.Add(new XmlRpcStructMember("idsubtitle", new XmlRpcValueBasic(idsubtitle))); + s.Members.Add(new XmlRpcStructMember("score", new XmlRpcValueBasic(score))); + parms.Add(s); + XmlRpcMethodCall call = new XmlRpcMethodCall("SubtitlesVote", parms); + + OSHConsole.WriteLine("Sending SubtitlesVote 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 + MethodResponseSubtitlesVote R = new MethodResponseSubtitlesVote(); + + // 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) + { + OSHConsole.WriteLine(" >" + dataMemeber.Name + "= " + dataMemeber.Data.Data.ToString()); + switch (dataMemeber.Name) + { + case "SubRating": R.SubRating = dataMemeber.Data.Data.ToString(); break; + case "SubSumVotes": R.SubSumVotes = dataMemeber.Data.Data.ToString(); break; + case "IDSubtitle": R.IDSubtitle = 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", "SubtitlesVote call failed !"); + } + /// + /// Add comment to a subtitle + /// + /// Subtitle identifier (BEWARE! this is not the ID of subtitle file but of the whole subtitle (a subtitle can contain multiple subtitle files)) + /// User's comment + /// Optional parameter. If set to 1, subtitles are marked as bad. + /// Status of the call operation. If the call success the response will be 'MethodResponseAddComment' + public static IMethodResponse AddComment(int idsubtitle, string comment, int badsubtitle) + { + 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 parms = new List(); + parms.Add(new XmlRpcValueBasic(TOKEN, XmlRpcBasicValueType.String)); + XmlRpcValueStruct s = new XmlRpcValueStruct(new List()); + s.Members.Add(new XmlRpcStructMember("idsubtitle", new XmlRpcValueBasic(idsubtitle))); + s.Members.Add(new XmlRpcStructMember("comment", new XmlRpcValueBasic(comment))); + s.Members.Add(new XmlRpcStructMember("badsubtitle", new XmlRpcValueBasic(badsubtitle))); + parms.Add(s); + XmlRpcMethodCall call = new XmlRpcMethodCall("AddComment", parms); + + OSHConsole.WriteLine("Sending AddComment 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 + MethodResponseAddComment R = new MethodResponseAddComment(); + + // 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", "AddComment call failed !"); + } + /// + /// Add new request for subtitles, user must be logged in + /// + /// The subtitle language id 3 length + /// http://www.imdb.com/ + /// The comment + /// Status of the call operation. If the call success the response will be 'MethodResponseAddRequest' + 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 parms = new List(); + parms.Add(new XmlRpcValueBasic(TOKEN, XmlRpcBasicValueType.String)); + XmlRpcValueStruct s = new XmlRpcValueStruct(new List()); + 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 !"); + } + /*User interface*/ + /// + /// Get list of supported subtitle languages + /// + /// ISO639-1 2-letter language code of user's interface language. + /// Status of the call operation. If the call success the response will be 'MethodResponseGetSubLanguages' + public static IMethodResponse GetSubLanguages(string language) + { + 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 parms = new List(); + parms.Add(new XmlRpcValueBasic(TOKEN)); + parms.Add(new XmlRpcValueBasic(language)); + XmlRpcMethodCall call = new XmlRpcMethodCall("GetSubLanguages", parms); + + OSHConsole.WriteLine("Sending GetSubLanguages 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 + MethodResponseGetSubLanguages R = new MethodResponseGetSubLanguages(); + + // 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":// array of structs + XmlRpcValueArray array = (XmlRpcValueArray)MEMBER.Data; + foreach (IXmlRpcValue value in array.Values) + { + if (value is XmlRpcValueStruct) + { + XmlRpcValueStruct valueStruct = (XmlRpcValueStruct)value; + SubtitleLanguage lang = new SubtitleLanguage(); + OSHConsole.WriteLine(">SubLanguage:"); + foreach (XmlRpcStructMember langMemeber in valueStruct.Members) + { + OSHConsole.WriteLine(" >" + langMemeber.Name + "= " + langMemeber.Data.Data.ToString()); + switch (langMemeber.Name) + { + case "SubLanguageID": lang.SubLanguageID = langMemeber.Data.Data.ToString(); break; + case "LanguageName": lang.LanguageName = langMemeber.Data.Data.ToString(); break; + case "ISO639": lang.ISO639 = langMemeber.Data.Data.ToString(); break; + } + } + R.Languages.Add(lang); + } + else + { + OSHConsole.WriteLine(">" + MEMBER.Name + "= " + + MEMBER.Data.Data.ToString() + " [Struct expected !]", 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", "GetSubLanguages call failed !"); + } + /// + /// Detect language for given strings + /// + /// Array of strings you want language detected for + /// The encoding that will be used to get buffer of given strings. (this is not OS official parameter) + /// Status of the call operation. If the call success the response will be 'MethodResponseDetectLanguage' + public static IMethodResponse DetectLanguage(string[] texts, Encoding encodingUsed) + { + 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 parms = new List(); + parms.Add(new XmlRpcValueBasic(TOKEN, XmlRpcBasicValueType.String)); + // We need to gzip texts then code them with base 24 + List decodedTexts = new List(); + foreach (string text in texts) + { + // compress + Stream str = new MemoryStream(); + byte[] stringData = encodingUsed.GetBytes(text); + str.Write(stringData, 0, stringData.Length); + str.Position = 0; + byte[] data = Utilities.Compress(str); + //base 64 + decodedTexts.Add(Convert.ToBase64String(data)); + } + parms.Add(new XmlRpcValueArray(decodedTexts.ToArray())); + XmlRpcMethodCall call = new XmlRpcMethodCall("DetectLanguage", parms); + + OSHConsole.WriteLine("Sending DetectLanguage 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 + MethodResponseDetectLanguage R = new MethodResponseDetectLanguage(); + + // 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": + if (MEMBER.Data is XmlRpcValueStruct) + { + OSHConsole.WriteLine(">Languages:"); + XmlRpcValueStruct dataStruct = (XmlRpcValueStruct)MEMBER.Data; + foreach (XmlRpcStructMember dataMember in dataStruct.Members) + { + DetectLanguageResult lang = new DetectLanguageResult(); + lang.InputSample = dataMember.Name; + lang.LanguageID = dataMember.Data.Data.ToString(); + R.Results.Add(lang); + OSHConsole.WriteLine(" >" + dataMember.Name + " (" + dataMember.Data.Data.ToString() + ")"); + } + } + else + { + OSHConsole.WriteLine(">Languages ?? Struct expected but server return another type!!", 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", "DetectLanguage call failed !"); + } + /// + /// Get available translations for given program + /// + /// Name of the program/client application you want translations for. Currently supported values: subdownloader, oscar + /// Status of the call operation. If the call success the response will be 'MethodResponseGetAvailableTranslations' + public static IMethodResponse GetAvailableTranslations(string program) + { + 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 parms = new List(); + parms.Add(new XmlRpcValueBasic(TOKEN)); + parms.Add(new XmlRpcValueBasic(program)); + XmlRpcMethodCall call = new XmlRpcMethodCall("GetAvailableTranslations", parms); + + OSHConsole.WriteLine("Sending GetAvailableTranslations 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 + MethodResponseGetAvailableTranslations R = new MethodResponseGetAvailableTranslations(); + + // 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; + OSHConsole.WriteLine(">data:"); + foreach (XmlRpcStructMember dataMember in dataStruct.Members) + { + if (dataMember.Data is XmlRpcValueStruct) + { + XmlRpcValueStruct resStruct = (XmlRpcValueStruct)dataMember.Data; + GetAvailableTranslationsResult res = new GetAvailableTranslationsResult(); + res.LanguageID = dataMember.Name; + OSHConsole.WriteLine(" >LanguageID: " + dataMember.Name); + foreach (XmlRpcStructMember resMember in resStruct.Members) + { + switch (resMember.Name) + { + case "LastCreated": res.LastCreated = resMember.Data.Data.ToString(); OSHConsole.WriteLine(" >" + resMember.Name + "= " + resMember.Data.Data.ToString()); break; + case "StringsNo": res.StringsNo = resMember.Data.Data.ToString(); OSHConsole.WriteLine(" >" + resMember.Name + "= " + resMember.Data.Data.ToString()); break; + } + R.Results.Add(res); + } + } + else + { + OSHConsole.WriteLine(" >Struct expected !!", 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", "GetAvailableTranslations call failed !"); + } + /// + /// Get a translation for given program and language + /// + /// language ​ISO639-1 2-letter code + /// available formats: [gnugettext compatible: mo, po] and [additional: txt, xml] + /// Name of the program/client application you want translations for. (currently supported values: subdownloader, oscar) + /// Status of the call operation. If the call success the response will be 'MethodResponseGetTranslation' + public static IMethodResponse GetTranslation(string iso639, string format, string program) + { + 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 parms = new List(); + parms.Add(new XmlRpcValueBasic(TOKEN)); + parms.Add(new XmlRpcValueBasic(iso639)); + parms.Add(new XmlRpcValueBasic(format)); + parms.Add(new XmlRpcValueBasic(program)); + XmlRpcMethodCall call = new XmlRpcMethodCall("GetTranslation", parms); + + OSHConsole.WriteLine("Sending GetTranslation request to the server ...", DebugCode.Good); + // Send the request to the server + //File.WriteAllText(".\\REQUEST_GetTranslation.xml", Encoding.ASCII.GetString(XmlRpcGenerator.Generate(call))); + 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 + MethodResponseGetTranslation R = new MethodResponseGetTranslation(); + + // 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.ContentData = (string)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", "GetTranslation call failed !"); + } + /// + /// Check for the latest version of given application + /// + /// name of the program/client application you want to check. (Currently supported values: subdownloader, oscar) + /// Status of the call operation. If the call success the response will be 'MethodResponseAutoUpdate' + public static IMethodResponse AutoUpdate(string program) + { + /*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 parms = new List(); + // parms.Add(new XmlRpcValueBasic(TOKEN)); + parms.Add(new XmlRpcValueBasic(program)); + // parms.Add(new XmlRpcValueBasic(XML_PRC_USERAGENT)); + + XmlRpcMethodCall call = new XmlRpcMethodCall("AutoUpdate", parms); + OSHConsole.WriteLine("Sending AutoUpdate 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 + MethodResponseAutoUpdate R = new MethodResponseAutoUpdate(); + + // 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 "version": R.version = (string)MEMBER.Data.Data; OSHConsole.WriteLine(">" + MEMBER.Name + "= " + MEMBER.Data.Data.ToString()); break; + case "url_windows": R.url_windows = (string)MEMBER.Data.Data; OSHConsole.WriteLine(">" + MEMBER.Name + "= " + MEMBER.Data.Data.ToString()); break; + case "url_linux": R.url_linux = (string)MEMBER.Data.Data; OSHConsole.WriteLine(">" + MEMBER.Name + "= " + MEMBER.Data.Data.ToString()); break; + case "comments": R.comments = (string)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", "AutoUpdate call failed !"); + } + /*Checking*/ + /// + /// Check if video file hashes are already stored in the database + /// + /// Array of video file hashes + /// Status of the call operation. If the call success the response will be 'MethodResponseCheckMovieHash' + public static IMethodResponse CheckMovieHash(string[] hashes) + { + 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 parms = new List(); + parms.Add(new XmlRpcValueBasic(TOKEN)); + parms.Add(new XmlRpcValueArray(hashes)); + XmlRpcMethodCall call = new XmlRpcMethodCall("CheckMovieHash", parms); + + OSHConsole.WriteLine("Sending CheckMovieHash 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 + MethodResponseCheckMovieHash R = new MethodResponseCheckMovieHash(); + + // 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; + OSHConsole.WriteLine(">Data:"); + foreach (XmlRpcStructMember dataMember in dataStruct.Members) + { + CheckMovieHashResult res = new CheckMovieHashResult(); + res.Name = dataMember.Name; + OSHConsole.WriteLine(" >" + res.Name + ":"); + XmlRpcValueStruct movieStruct = (XmlRpcValueStruct)dataMember.Data; + foreach (XmlRpcStructMember movieMember in movieStruct.Members) + { + switch (movieMember.Name) + { + case "MovieHash": res.MovieHash = movieMember.Data.Data.ToString(); OSHConsole.WriteLine(" >" + movieMember.Name + "= " + movieMember.Data.Data.ToString()); break; + case "MovieImdbID": res.MovieImdbID = movieMember.Data.Data.ToString(); OSHConsole.WriteLine(" >" + movieMember.Name + "= " + movieMember.Data.Data.ToString()); break; + case "MovieName": res.MovieName = movieMember.Data.Data.ToString(); OSHConsole.WriteLine(" >" + movieMember.Name + "= " + movieMember.Data.Data.ToString()); break; + case "MovieYear": res.MovieYear = movieMember.Data.Data.ToString(); OSHConsole.WriteLine(" >" + movieMember.Name + "= " + movieMember.Data.Data.ToString()); break; + } + } + R.Results.Add(res); + } + break; + } + } + // Return the response to user !! + return R; + } + } + } + else + { + OSHConsole.WriteLine(response, DebugCode.Error); + return new MethodResponseError("Fail", response); + } + return new MethodResponseError("Fail", "CheckMovieHash call failed !"); + } + /// + /// Check if video file hashes are already stored in the database. This method returns matching !MovieImdbID, MovieName, MovieYear, SeriesSeason, SeriesEpisode, + /// MovieKind if available for each $moviehash, always sorted by SeenCount DESC. + /// + /// Array of video file hashes + /// Status of the call operation. If the call success the response will be 'MethodResponseCheckMovieHash2' + public static IMethodResponse CheckMovieHash2(string[] hashes) + { + 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 parms = new List(); + parms.Add(new XmlRpcValueBasic(TOKEN)); + parms.Add(new XmlRpcValueArray(hashes)); + XmlRpcMethodCall call = new XmlRpcMethodCall("CheckMovieHash2", parms); + + OSHConsole.WriteLine("Sending CheckMovieHash2 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 + MethodResponseCheckMovieHash2 R = new MethodResponseCheckMovieHash2(); + + // 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; + OSHConsole.WriteLine(">Data:"); + foreach (XmlRpcStructMember dataMember in dataStruct.Members) + { + CheckMovieHash2Result res = new CheckMovieHash2Result(); + res.Name = dataMember.Name; + OSHConsole.WriteLine(" >" + res.Name + ":"); + + XmlRpcValueArray dataArray = (XmlRpcValueArray)dataMember.Data; + foreach (XmlRpcValueStruct movieStruct in dataArray.Values) + { + CheckMovieHash2Data d = new CheckMovieHash2Data(); + foreach (XmlRpcStructMember movieMember in movieStruct.Members) + { + switch (movieMember.Name) + { + case "MovieHash": d.MovieHash = movieMember.Data.Data.ToString(); OSHConsole.WriteLine(" >" + movieMember.Name + "= " + movieMember.Data.Data.ToString()); break; + case "MovieImdbID": d.MovieImdbID = movieMember.Data.Data.ToString(); OSHConsole.WriteLine(" >" + movieMember.Name + "= " + movieMember.Data.Data.ToString()); break; + case "MovieName": d.MovieName = movieMember.Data.Data.ToString(); OSHConsole.WriteLine(" >" + movieMember.Name + "= " + movieMember.Data.Data.ToString()); break; + case "MovieYear": d.MovieYear = movieMember.Data.Data.ToString(); OSHConsole.WriteLine(" >" + movieMember.Name + "= " + movieMember.Data.Data.ToString()); break; + case "MovieKind": d.MovieKind = movieMember.Data.Data.ToString(); OSHConsole.WriteLine(" >" + movieMember.Name + "= " + movieMember.Data.Data.ToString()); break; + case "SeriesSeason": d.SeriesSeason = movieMember.Data.Data.ToString(); OSHConsole.WriteLine(" >" + movieMember.Name + "= " + movieMember.Data.Data.ToString()); break; + case "SeriesEpisode": d.SeriesEpisode = movieMember.Data.Data.ToString(); OSHConsole.WriteLine(" >" + movieMember.Name + "= " + movieMember.Data.Data.ToString()); break; + case "SeenCount": d.MovieYear = movieMember.Data.Data.ToString(); OSHConsole.WriteLine(" >" + movieMember.Name + "= " + movieMember.Data.Data.ToString()); break; + } + } + res.Items.Add(d); + } + R.Results.Add(res); + } + break; + } + } + // Return the response to user !! + return R; + } + } + } + else + { + OSHConsole.WriteLine(response, DebugCode.Error); + return new MethodResponseError("Fail", response); + } + return new MethodResponseError("Fail", "CheckMovieHash2 call failed !"); + } + /// + /// Check if given subtitle files are already stored in the database + /// + /// Array of subtitle file hashes (MD5 hashes of subtitle file contents) + /// Status of the call operation. If the call success the response will be 'MethodResponseCheckSubHash' + public static IMethodResponse CheckSubHash(string[] hashes) + { + 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 parms = new List(); + parms.Add(new XmlRpcValueBasic(TOKEN)); + parms.Add(new XmlRpcValueArray(hashes)); + XmlRpcMethodCall call = new XmlRpcMethodCall("CheckSubHash", parms); + + OSHConsole.WriteLine("Sending CheckSubHash 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 + MethodResponseCheckSubHash R = new MethodResponseCheckSubHash(); + + // 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": + OSHConsole.WriteLine(">Data:"); + XmlRpcValueStruct dataStruct = (XmlRpcValueStruct)MEMBER.Data; + foreach (XmlRpcStructMember dataMember in dataStruct.Members) + { + OSHConsole.WriteLine(" >" + dataMember.Name + "= " + dataMember.Data.Data.ToString()); + CheckSubHashResult r = new CheckSubHashResult(); + r.Hash = dataMember.Name; + r.SubID = dataMember.Data.Data.ToString(); + R.Results.Add(r); + } + break; + } + } + // Return the response to user !! + return R; + } + } + } + else + { + OSHConsole.WriteLine(response, DebugCode.Error); + return new MethodResponseError("Fail", response); + } + return new MethodResponseError("Fail", "CheckSubHash call failed !"); + } + /*Upload*/ + /// + /// Try to upload subtitles, perform pre-upload checking (i.e. check if subtitles already exist on server) + /// + /// The subtitle parameters collection to try to upload + /// Status of the call operation. If the call success the response will be 'MethodResponseTryUploadSubtitles' + 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 parms = new List(); + parms.Add(new XmlRpcValueBasic(TOKEN, XmlRpcBasicValueType.String)); + XmlRpcValueStruct s = new XmlRpcValueStruct(new List()); + int i = 1; + foreach (TryUploadSubtitlesParameters cd in subs) + { + XmlRpcStructMember member = new XmlRpcStructMember("cd" + i, null); + XmlRpcValueStruct memberStruct = new XmlRpcValueStruct(new List()); + 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 !"); + } + /// + /// Upload given subtitles to OSDb server + /// + /// The pamaters of upload method + /// Status of the call operation. If the call success the response will be 'MethodResponseUploadSubtitles' + 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 parms = new List(); + parms.Add(new XmlRpcValueBasic(TOKEN)); + // Main struct + XmlRpcValueStruct s = new XmlRpcValueStruct(new List()); + + // Base info member as struct + XmlRpcStructMember member = new XmlRpcStructMember("baseinfo", null); + XmlRpcValueStruct memberStruct = new XmlRpcValueStruct(new List()); + 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()); + 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 !"); + } + } +} diff --git a/OpenSubtitlesHandler/OpenSubtitlesHandler.csproj b/OpenSubtitlesHandler/OpenSubtitlesHandler.csproj new file mode 100644 index 0000000000..ba27c71408 --- /dev/null +++ b/OpenSubtitlesHandler/OpenSubtitlesHandler.csproj @@ -0,0 +1,123 @@ + + + + + Debug + AnyCPU + {4A4402D4-E910-443B-B8FC-2C18286A2CA0} + Library + Properties + OpenSubtitlesHandler + OpenSubtitlesHandler + v4.5 + 512 + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + {9142eefa-7570-41e1-bfcc-468bb571af2f} + MediaBrowser.Common + + + {7eeeb4bb-f3e8-48fc-b4c5-70f0fff8329b} + MediaBrowser.Model + + + + + + + + \ No newline at end of file diff --git a/OpenSubtitlesHandler/OtherTypes/GetAvailableTranslationsResult.cs b/OpenSubtitlesHandler/OtherTypes/GetAvailableTranslationsResult.cs new file mode 100644 index 0000000000..ae6317b4d5 --- /dev/null +++ b/OpenSubtitlesHandler/OtherTypes/GetAvailableTranslationsResult.cs @@ -0,0 +1,39 @@ +/* This file is part of OpenSubtitles Handler + A library that handle OpenSubtitles.org XML-RPC methods. + + Copyright © Ala Ibrahim Hadid 2013 + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + */ +namespace OpenSubtitlesHandler +{ + public struct GetAvailableTranslationsResult + { + private string _language; + private string _LastCreated; + private string _StringsNo; + + public string LanguageID { get { return _language; } set { _language = value; } } + public string LastCreated { get { return _LastCreated; } set { _LastCreated = value; } } + public string StringsNo { get { return _StringsNo; } set { _StringsNo = value; } } + /// + /// LanguageID (LastCreated) + /// + /// + public override string ToString() + { + return _language + " (" + _LastCreated + ")"; + } + } +} diff --git a/OpenSubtitlesHandler/OtherTypes/GetCommentsResult.cs b/OpenSubtitlesHandler/OtherTypes/GetCommentsResult.cs new file mode 100644 index 0000000000..2eedd25380 --- /dev/null +++ b/OpenSubtitlesHandler/OtherTypes/GetCommentsResult.cs @@ -0,0 +1,37 @@ +/* This file is part of OpenSubtitles Handler + A library that handle OpenSubtitles.org XML-RPC methods. + + Copyright © Ala Ibrahim Hadid 2013 + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + */ +using System; + +namespace OpenSubtitlesHandler +{ + public struct GetCommentsResult + { + private string _IDSubtitle; + private string _UserID; + private string _UserNickName; + private string _Comment; + private string _Created; + + public string IDSubtitle { get { return _IDSubtitle; } set { _IDSubtitle = value; } } + public string UserID { get { return _UserID; } set { _UserID = value; } } + public string UserNickName { get { return _UserNickName; } set { _UserNickName = value; } } + public string Comment { get { return _Comment; } set { _Comment = value; } } + public string Created { get { return _Created; } set { _Created = value; } } + } +} diff --git a/OpenSubtitlesHandler/Properties/AssemblyInfo.cs b/OpenSubtitlesHandler/Properties/AssemblyInfo.cs new file mode 100644 index 0000000000..9fad43d749 --- /dev/null +++ b/OpenSubtitlesHandler/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("OpenSubtitlesHandler")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("OpenSubtitlesHandler")] +[assembly: AssemblyCopyright("Copyright © 2014")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("7c43bda2-2037-449d-8aac-9c0ccee8191f")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/OpenSubtitlesHandler/Readme.txt b/OpenSubtitlesHandler/Readme.txt new file mode 100644 index 0000000000..42b4fdab3c --- /dev/null +++ b/OpenSubtitlesHandler/Readme.txt @@ -0,0 +1,20 @@ +OpenSubtitlesHandler +==================== +This project is for OpenSubtitles.org integration‏. The point is to allow user to access OpenSubtitles.org database directly +within ASM without the need to open internet browser. +The plan: Implement the "OSDb protocol" http://trac.opensubtitles.org/projects/opensubtitles/wiki/OSDb + +Copyright: +========= +This library ann all its content are written by Ala Ibrahim Hadid. +Copyright © Ala Ibrahim Hadid 2013 +mailto:ahdsoftwares@hotmail.com + +Resources: +========== +* GetHash.dll: this dll is used to compute hash for movie. + For more information please visit http://trac.opensubtitles.org/projects/opensubtitles/wiki/HashSourceCodes#C2 + +XML_RPC: +======== +This class is created to generate XML-RPC requests as XML String. All you need is to call XML_RPC.Generate() method. \ No newline at end of file diff --git a/OpenSubtitlesHandler/SubtitleTypes/CheckSubHashResult.cs b/OpenSubtitlesHandler/SubtitleTypes/CheckSubHashResult.cs new file mode 100644 index 0000000000..0e77601ba8 --- /dev/null +++ b/OpenSubtitlesHandler/SubtitleTypes/CheckSubHashResult.cs @@ -0,0 +1,31 @@ +/* This file is part of OpenSubtitles Handler + A library that handle OpenSubtitles.org XML-RPC methods. + + Copyright © Ala Ibrahim Hadid 2013 + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + */ +using System; + +namespace OpenSubtitlesHandler +{ + public struct CheckSubHashResult + { + private string _hash; + private string _id; + + public string Hash { get { return _hash; } set { _hash = value; } } + public string SubID { get { return _id; } set { _id = value; } } + } +} diff --git a/OpenSubtitlesHandler/SubtitleTypes/SubtitleDownloadResult.cs b/OpenSubtitlesHandler/SubtitleTypes/SubtitleDownloadResult.cs new file mode 100644 index 0000000000..35bf796e6a --- /dev/null +++ b/OpenSubtitlesHandler/SubtitleTypes/SubtitleDownloadResult.cs @@ -0,0 +1,44 @@ +/* This file is part of OpenSubtitles Handler + A library that handle OpenSubtitles.org XML-RPC methods. + + Copyright © Ala Ibrahim Hadid 2013 + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + */ +using System; + +namespace OpenSubtitlesHandler +{ + public struct SubtitleDownloadResult + { + private string idsubtitlefile; + private string data; + + public string IdSubtitleFile + { get { return idsubtitlefile; } set { idsubtitlefile = value; } } + /// + /// Get or set the data of subtitle file. To decode, decode the string to base64 and then decompress with GZIP. + /// + public string Data + { get { return data; } set { data = value; } } + /// + /// IdSubtitleFile + /// + /// + public override string ToString() + { + return idsubtitlefile.ToString(); + } + } +} diff --git a/OpenSubtitlesHandler/SubtitleTypes/SubtitleLanguage.cs b/OpenSubtitlesHandler/SubtitleTypes/SubtitleLanguage.cs new file mode 100644 index 0000000000..511c986704 --- /dev/null +++ b/OpenSubtitlesHandler/SubtitleTypes/SubtitleLanguage.cs @@ -0,0 +1,39 @@ +/* This file is part of OpenSubtitles Handler + A library that handle OpenSubtitles.org XML-RPC methods. + + Copyright © Ala Ibrahim Hadid 2013 + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + */ +namespace OpenSubtitlesHandler +{ + public struct SubtitleLanguage + { + private string _SubLanguageID; + private string _LanguageName; + private string _ISO639; + + public string SubLanguageID { get { return _SubLanguageID; } set { _SubLanguageID = value; } } + public string LanguageName { get { return _LanguageName; } set { _LanguageName = value; } } + public string ISO639 { get { return _ISO639; } set { _ISO639 = value; } } + /// + /// LanguageName [SubLanguageID] + /// + /// LanguageName [SubLanguageID] + public override string ToString() + { + return _LanguageName + " [" + _SubLanguageID + "]"; + } + } +} diff --git a/OpenSubtitlesHandler/SubtitleTypes/SubtitleSearchParameters.cs b/OpenSubtitlesHandler/SubtitleTypes/SubtitleSearchParameters.cs new file mode 100644 index 0000000000..e11ff1b9a9 --- /dev/null +++ b/OpenSubtitlesHandler/SubtitleTypes/SubtitleSearchParameters.cs @@ -0,0 +1,115 @@ +/* This file is part of OpenSubtitles Handler + A library that handle OpenSubtitles.org XML-RPC methods. + + Copyright © Ala Ibrahim Hadid 2013 + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + */ +using System; + +namespace OpenSubtitlesHandler +{ + /// + /// Paramaters for subtitle search call + /// + public struct SubtitleSearchParameters + { + /// + /// Paramaters for subtitle search call + /// + /// List of language ISO639-3 language codes to search for, divided by ',' (e.g. 'cze,eng,slo') + /// Video file hash as calculated by one of the implementation functions as seen on http://trac.opensubtitles.org/projects/opensubtitles/wiki/HashSourceCodes + /// Size of video file in bytes + public SubtitleSearchParameters(string subLanguageId, string movieHash, long movieByteSize) + { + this.subLanguageId = subLanguageId; + this.movieHash = movieHash; + this.movieByteSize = movieByteSize; + this.imdbid = ""; + this._episode = ""; + this._season = ""; + this._query = ""; + } + + public SubtitleSearchParameters(string subLanguageId, string query, string season, string episode) + { + this.subLanguageId = subLanguageId; + this.movieHash = ""; + this.movieByteSize = 0; + this.imdbid = ""; + this._episode = episode; + this._season = season; + this._query = query; + } + + /// + /// Paramaters for subtitle search call + /// + /// List of language ISO639-3 language codes to search for, divided by ',' (e.g. 'cze,eng,slo') + /// Video file hash as calculated by one of the implementation functions as seen on http://trac.opensubtitles.org/projects/opensubtitles/wiki/HashSourceCodes + /// Size of video file in bytes + /// IMDb ID of movie this video is part of, belongs to. + public SubtitleSearchParameters(string subLanguageId, string movieHash, long movieByteSize, string imdbid) + { + this.subLanguageId = subLanguageId; + this.movieHash = movieHash; + this.movieByteSize = movieByteSize; + this.imdbid = imdbid; + this._episode = ""; + this._season = ""; + this._query = ""; + } + + private string subLanguageId; + private string movieHash; + private long movieByteSize; + private string imdbid; + private string _query; + private string _episode; + + public string Episode { + get { return _episode; } + set { _episode = value; } + } + + public string Season { + get { return _season; } + set { _season = value; } + } + + private string _season; + + public string Query { + get { return _query; } + set { _query = value; } + } + + /// + /// List of language ISO639-3 language codes to search for, divided by ',' (e.g. 'cze,eng,slo') + /// + public string SubLangaugeID { get { return subLanguageId; } set { subLanguageId = value; } } + /// + /// Video file hash as calculated by one of the implementation functions as seen on http://trac.opensubtitles.org/projects/opensubtitles/wiki/HashSourceCodes + /// + public string MovieHash { get { return movieHash; } set { movieHash = value; } } + /// + /// Size of video file in bytes + /// + public long MovieByteSize { get { return movieByteSize; } set { movieByteSize = value; } } + /// + /// ​IMDb ID of movie this video is part of, belongs to. + /// + public string IMDbID { get { return imdbid; } set { imdbid = value; } } + } +} diff --git a/OpenSubtitlesHandler/SubtitleTypes/SubtitleSearchResult.cs b/OpenSubtitlesHandler/SubtitleTypes/SubtitleSearchResult.cs new file mode 100644 index 0000000000..a56a6edaba --- /dev/null +++ b/OpenSubtitlesHandler/SubtitleTypes/SubtitleSearchResult.cs @@ -0,0 +1,137 @@ +/* This file is part of OpenSubtitles Handler + A library that handle OpenSubtitles.org XML-RPC methods. + + Copyright © Ala Ibrahim Hadid 2013 + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + */ +using System; + +namespace OpenSubtitlesHandler +{ + /// + /// The subtitle search result that comes with server response on SearchSubtitles successed call + /// + public struct SubtitleSearchResult + { + private string _IDSubMovieFile; + private string _MovieHash; + private string _MovieByteSize; + private string _MovieTimeMS; + private string _IDSubtitleFile; + private string _SubFileName; + private string _SubActualCD; + private string _SubSize; + private string _SubHash; + private string _IDSubtitle; + private string _UserID; + private string _SubLanguageID; + private string _SubFormat; + private string _SeriesSeason; + private string _SeriesEpisode; + private string _SubSumCD; + private string _SubAuthorComment; + private string _SubAddDate; + private string _SubBad; + private string _SubRating; + private string _SubDownloadsCnt; + private string _MovieReleaseName; + private string _IDMovie; + private string _IDMovieImdb; + private string _MovieName; + private string _MovieNameEng; + private string _MovieYear; + private string _MovieImdbRating; + private string _UserNickName; + private string _ISO639; + private string _LanguageName; + private string _SubDownloadLink; + private string _ZipDownloadLink; + + public string IDSubMovieFile + { get { return _IDSubMovieFile; } set { _IDSubMovieFile = value; } } + public string MovieHash + { get { return _MovieHash; } set { _MovieHash = value; } } + public string MovieByteSize + { get { return _MovieByteSize; } set { _MovieByteSize = value; } } + public string MovieTimeMS + { get { return _MovieTimeMS; } set { _MovieTimeMS = value; } } + public string IDSubtitleFile + { get { return _IDSubtitleFile; } set { _IDSubtitleFile = value; } } + public string SubFileName + { get { return _SubFileName; } set { _SubFileName = value; } } + public string SubActualCD + { get { return _SubActualCD; } set { _SubActualCD = value; } } + public string SubSize + { get { return _SubSize; } set { _SubSize = value; } } + public string SubHash + { get { return _SubHash; } set { _SubHash = value; } } + public string IDSubtitle + { get { return _IDSubtitle; } set { _IDSubtitle = value; } } + public string UserID + { get { return _UserID; } set { _UserID = value; } } + public string SubLanguageID + { get { return _SubLanguageID; } set { _SubLanguageID = value; } } + public string SubFormat + { get { return _SubFormat; } set { _SubFormat = value; } } + public string SubSumCD + { get { return _SubSumCD; } set { _SubSumCD = value; } } + public string SubAuthorComment + { get { return _SubAuthorComment; } set { _SubAuthorComment = value; } } + public string SubAddDate + { get { return _SubAddDate; } set { _SubAddDate = value; } } + public string SubBad + { get { return _SubBad; } set { _SubBad = value; } } + public string SubRating + { get { return _SubRating; } set { _SubRating = value; } } + public string SubDownloadsCnt + { get { return _SubDownloadsCnt; } set { _SubDownloadsCnt = value; } } + public string MovieReleaseName + { get { return _MovieReleaseName; } set { _MovieReleaseName = value; } } + public string IDMovie + { get { return _IDMovie; } set { _IDMovie = value; } } + public string IDMovieImdb + { get { return _IDMovieImdb; } set { _IDMovieImdb = value; } } + public string MovieName + { get { return _MovieName; } set { _MovieName = value; } } + public string MovieNameEng + { get { return _MovieNameEng; } set { _MovieNameEng = value; } } + public string MovieYear + { get { return _MovieYear; } set { _MovieYear = value; } } + public string MovieImdbRating + { get { return _MovieImdbRating; } set { _MovieImdbRating = value; } } + public string UserNickName + { get { return _UserNickName; } set { _UserNickName = value; } } + public string ISO639 + { get { return _ISO639; } set { _ISO639 = value; } } + public string LanguageName + { get { return _LanguageName; } set { _LanguageName = value; } } + public string SubDownloadLink + { get { return _SubDownloadLink; } set { _SubDownloadLink = value; } } + public string ZipDownloadLink + { get { return _ZipDownloadLink; } set { _ZipDownloadLink = value; } } + public string SeriesSeason + { get { return _SeriesSeason; } set { _SeriesSeason = value; } } + public string SeriesEpisode + { get { return _SeriesEpisode; } set { _SeriesEpisode = value; } } + /// + /// SubFileName + " (" + SubFormat + ")" + /// + /// + public override string ToString() + { + return _SubFileName + " (" + _SubFormat + ")"; + } + } +} diff --git a/OpenSubtitlesHandler/SubtitleTypes/TryUploadSubtitlesParameters.cs b/OpenSubtitlesHandler/SubtitleTypes/TryUploadSubtitlesParameters.cs new file mode 100644 index 0000000000..a95d151eb2 --- /dev/null +++ b/OpenSubtitlesHandler/SubtitleTypes/TryUploadSubtitlesParameters.cs @@ -0,0 +1,48 @@ +/* This file is part of OpenSubtitles Handler + A library that handle OpenSubtitles.org XML-RPC methods. + + Copyright © Ala Ibrahim Hadid 2013 + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + */ +using System; + +namespace OpenSubtitlesHandler +{ + public class TryUploadSubtitlesParameters + { + private string _subhash = ""; + private string _subfilename = ""; + private string _moviehash = ""; + private string _moviebytesize = ""; + private int _movietimems = 0; + private int _movieframes = 0; + private double _moviefps = 0; + private string _moviefilename = ""; + + public string subhash { get { return _subhash; } set { _subhash = value; } } + public string subfilename { get { return _subfilename; } set { _subfilename = value; } } + public string moviehash { get { return _moviehash; } set { _moviehash = value; } } + public string moviebytesize { get { return _moviebytesize; } set { _moviebytesize = value; } } + public int movietimems { get { return _movietimems; } set { _movietimems = value; } } + public int movieframes { get { return _movieframes; } set { _movieframes = value; } } + public double moviefps { get { return _moviefps; } set { _moviefps = value; } } + public string moviefilename { get { return _moviefilename; } set { _moviefilename = value; } } + + public override string ToString() + { + return _subfilename + " (" + _subhash + ")"; + } + } +} diff --git a/OpenSubtitlesHandler/SubtitleTypes/UploadSubtitleInfoParameter.cs b/OpenSubtitlesHandler/SubtitleTypes/UploadSubtitleInfoParameter.cs new file mode 100644 index 0000000000..8e147878ba --- /dev/null +++ b/OpenSubtitlesHandler/SubtitleTypes/UploadSubtitleInfoParameter.cs @@ -0,0 +1,46 @@ +/* This file is part of OpenSubtitles Handler + A library that handle OpenSubtitles.org XML-RPC methods. + + Copyright © Ala Ibrahim Hadid 2013 + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + */ +using System; +using System.Collections.Generic; + +namespace OpenSubtitlesHandler +{ + public class UploadSubtitleInfoParameters + { + private string _idmovieimdb; + private string _moviereleasename; + private string _movieaka; + private string _sublanguageid; + private string _subauthorcomment; + private bool _hearingimpaired; + private bool _highdefinition; + private bool _automatictranslation; + private List cds; + + public string idmovieimdb { get { return _idmovieimdb; } set { _idmovieimdb = value; } } + public string moviereleasename { get { return _moviereleasename; } set { _moviereleasename = value; } } + public string movieaka { get { return _movieaka; } set { _movieaka = value; } } + public string sublanguageid { get { return _sublanguageid; } set { _sublanguageid = value; } } + public string subauthorcomment { get { return _subauthorcomment; } set { _subauthorcomment = value; } } + public bool hearingimpaired { get { return _hearingimpaired; } set { _hearingimpaired = value; } } + public bool highdefinition { get { return _highdefinition; } set { _highdefinition = value; } } + public bool automatictranslation { get { return _automatictranslation; } set { _automatictranslation = value; } } + public List CDS { get { return cds; } set { cds = value; } } + } +} diff --git a/OpenSubtitlesHandler/SubtitleTypes/UploadSubtitleParameters.cs b/OpenSubtitlesHandler/SubtitleTypes/UploadSubtitleParameters.cs new file mode 100644 index 0000000000..90a2739599 --- /dev/null +++ b/OpenSubtitlesHandler/SubtitleTypes/UploadSubtitleParameters.cs @@ -0,0 +1,53 @@ +/* This file is part of OpenSubtitles Handler + A library that handle OpenSubtitles.org XML-RPC methods. + + Copyright © Ala Ibrahim Hadid 2013 + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + */ +using System; + +namespace OpenSubtitlesHandler +{ + public struct UploadSubtitleParameters + { + private string _subhash; + private string _subfilename; + private string _moviehash; + private double _moviebytesize; + private int _movietimems; + private int _movieframes; + private double _moviefps; + private string _moviefilename; + private string _subcontent; + + public string subhash { get { return _subhash; } set { _subhash = value; } } + public string subfilename { get { return _subfilename; } set { _subfilename = value; } } + public string moviehash { get { return _moviehash; } set { _moviehash = value; } } + public double moviebytesize { get { return _moviebytesize; } set { _moviebytesize = value; } } + public int movietimems { get { return _movietimems; } set { _movietimems = value; } } + public int movieframes { get { return _movieframes; } set { _movieframes = value; } } + public double moviefps { get { return _moviefps; } set { _moviefps = value; } } + public string moviefilename { get { return _moviefilename; } set { _moviefilename = value; } } + /// + /// Sub content. Note: this value must be the subtitle file gziped and then base64 decoded. + /// + public string subcontent { get { return _subcontent; } set { _subcontent = value; } } + + public override string ToString() + { + return _subfilename + " (" + _subhash + ")"; + } + } +} diff --git a/OpenSubtitlesHandler/Utilities.cs b/OpenSubtitlesHandler/Utilities.cs new file mode 100644 index 0000000000..5c72f4fde7 --- /dev/null +++ b/OpenSubtitlesHandler/Utilities.cs @@ -0,0 +1,235 @@ +/* This file is part of OpenSubtitles Handler + A library that handle OpenSubtitles.org XML-RPC methods. + + Copyright © Ala Ibrahim Hadid 2013 + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + */ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.IO; +using System.IO.Compression; +using System.Net; +using System.Security.Cryptography; +using System.Threading.Tasks; +using MediaBrowser.Common.Net; + +namespace OpenSubtitlesHandler +{ + /// + /// Include helper methods. All member are statics. + /// + public sealed class Utilities + { + private const string XML_RPC_SERVER = "http://api.opensubtitles.org/xml-rpc"; + + /// + /// Compute movie hash + /// + /// The complete media file path + /// The hash as Hexadecimal string + public static string ComputeHash(string fileName) + { + byte[] hash = MovieHasher.ComputeMovieHash(fileName); + return MovieHasher.ToHexadecimal(hash); + } + /// + /// Compute md5 for a file + /// + /// The complete file path + /// MD5 of the file + public static string ComputeMd5(string filename) + { + var md5 = MD5.Create(); + var sb = new StringBuilder(); + Stream str = new FileStream(filename, FileMode.Open, FileAccess.Read); + + foreach (var b in md5.ComputeHash(str)) + sb.Append(b.ToString("x2").ToLower()); + str.Close(); + return sb.ToString(); + } + /// + /// Decompress data using GZip + /// + /// The stream that hold the data + /// Bytes array of decompressed data + public static byte[] Decompress(Stream dataToDecompress) + { + MemoryStream target = new MemoryStream(); + + using (System.IO.Compression.GZipStream decompressionStream = new System.IO.Compression.GZipStream(dataToDecompress, + System.IO.Compression.CompressionMode.Decompress)) + { + decompressionStream.CopyTo(target); + } + return target.GetBuffer(); + + } + + /// + /// Compress data using GZip (the retunred buffer will be WITHOUT HEADER) + /// + /// The stream that hold the data + /// Bytes array of compressed data WITHOUT HEADER bytes + public static byte[] Compress(Stream dataToCompress) + { + /*using (var compressed = new MemoryStream()) + { + using (var compressor = new System.IO.Compression.GZipStream(compressed, + System.IO.Compression.CompressionMode.Compress)) + { + dataToCompress.CopyTo(compressor); + } + // Get the compressed bytes only after closing the GZipStream + return compressed.ToArray(); + }*/ + //using (var compressedOutput = new MemoryStream()) + //{ + // using (var compressedStream = new ZlibStream(compressedOutput, + // Ionic.Zlib.CompressionMode.Compress, + // CompressionLevel.Default, false)) + // { + // var buffer = new byte[4096]; + // int byteCount; + // do + // { + // byteCount = dataToCompress.Read(buffer, 0, buffer.Length); + + // if (byteCount > 0) + // { + // compressedStream.Write(buffer, 0, byteCount); + // } + // } while (byteCount > 0); + // } + // return compressedOutput.ToArray(); + //} + + throw new NotImplementedException(); + } + + /// + /// Handle server response stream and decode it as given encoding string. + /// + /// The response stream. Expects a stream that doesn't support seek. + /// The encoding that should be used to decode buffer + /// The string of the stream after decode using given encoding + public static string GetStreamString(Stream responseStream, Encoding encoding) + { + // Handle response, should be XML text. + List data = new List(); + while (true) + { + int r = responseStream.ReadByte(); + if (r < 0) + break; + data.Add((byte)r); + } + responseStream.Close(); + return encoding.GetString(data.ToArray()); + } + /// + /// Handle server response stream and decode it as ASCII encoding string. + /// + /// The response stream. Expects a stream that doesn't support seek. + /// The string of the stream after decode using ASCII encoding + public static string GetStreamString(Stream responseStream) + { + return GetStreamString(responseStream, Encoding.ASCII); + } + + public static IHttpClient HttpClient { get; set; } + + /// + /// Send a request to the server + /// + /// The request buffer to send as bytes array. + /// The user agent value. + /// Response of the server or stream of error message as string started with 'ERROR:' keyword. + public static Stream SendRequest(byte[] request, string userAgent) + { + return SendRequestAsync(request, userAgent).Result; + + //HttpWebRequest req = (HttpWebRequest)WebRequest.Create(XML_RPC_SERVER); + //req.ContentType = "text/xml"; + //req.Host = "api.opensubtitles.org:80"; + //req.Method = "POST"; + //req.UserAgent = "xmlrpc-epi-php/0.2 (PHP)"; + //req.ContentLength = request.Length; + //ServicePointManager.Expect100Continue = false; + //try + //{ + // using (Stream stm = req.GetRequestStream()) + // { + // stm.Write(request, 0, request.Length); + // } + + // WebResponse response = req.GetResponse(); + // return response.GetResponseStream(); + //} + //catch (Exception ex) + //{ + // Stream errorStream = new MemoryStream(); + // byte[] dd = Encoding.ASCII.GetBytes("ERROR: " + ex.Message); + // errorStream.Write(dd, 0, dd.Length); + // errorStream.Position = 0; + // return errorStream; + //} + } + + public static async Task SendRequestAsync(byte[] request, string userAgent) + { + var options = new HttpRequestOptions + { + RequestContentBytes = request, + RequestContentType = "text/xml", + UserAgent = "xmlrpc-epi-php/0.2 (PHP)", + Url = XML_RPC_SERVER + }; + + var result = await HttpClient.Post(options).ConfigureAwait(false); + + return result.Content; + + //HttpWebRequest req = (HttpWebRequest)WebRequest.Create(XML_RPC_SERVER); + //req.ContentType = "text/xml"; + //req.Host = "api.opensubtitles.org:80"; + //req.Method = "POST"; + //req.UserAgent = "xmlrpc-epi-php/0.2 (PHP)"; + //req.ContentLength = request.Length; + //ServicePointManager.Expect100Continue = false; + //try + //{ + // using (Stream stm = req.GetRequestStream()) + // { + // stm.Write(request, 0, request.Length); + // } + + // WebResponse response = req.GetResponse(); + // return response.GetResponseStream(); + //} + //catch (Exception ex) + //{ + // Stream errorStream = new MemoryStream(); + // byte[] dd = Encoding.ASCII.GetBytes("ERROR: " + ex.Message); + // errorStream.Write(dd, 0, dd.Length); + // errorStream.Position = 0; + // return errorStream; + //} + } + + } +} diff --git a/OpenSubtitlesHandler/XML-RPC/Docs/XML-RPC.txt b/OpenSubtitlesHandler/XML-RPC/Docs/XML-RPC.txt new file mode 100644 index 0000000000..8c84444a99 --- /dev/null +++ b/OpenSubtitlesHandler/XML-RPC/Docs/XML-RPC.txt @@ -0,0 +1,225 @@ +XML-RPC Specification + +Tue, Jun 15, 1999; by Dave Winer. + +Updated 6/30/03 DW + +Updated 10/16/99 DW + +Updated 1/21/99 DW + +This specification documents the XML-RPC protocol implemented in UserLand Frontier 5.1. + +For a non-technical explanation, see XML-RPC for Newbies. + +This page provides all the information that an implementor needs. + +Overview + +XML-RPC is a Remote Procedure Calling protocol that works over the Internet. + +An XML-RPC message is an HTTP-POST request. The body of the request is in XML. A procedure executes on the server and the value it returns is also formatted in XML. + +Procedure parameters can be scalars, numbers, strings, dates, etc.; and can also be complex record and list structures. + +Request example + +Here's an example of an XML-RPC request: + +POST /RPC2 HTTP/1.0 +User-Agent: Frontier/5.1.2 (WinNT) +Host: betty.userland.com +Content-Type: text/xml +Content-length: 181 + + + + examples.getStateName + + + + 41 + + + + + +Header requirements + +The format of the URI in the first line of the header is not specified. For example, it could be empty, a single slash, if the server is only handling XML-RPC calls. However, if the server is handling a mix of incoming HTTP requests, we allow the URI to help route the request to the code that handles XML-RPC requests. (In the example, the URI is /RPC2, telling the server to route the request to the "RPC2" responder.) + +A User-Agent and Host must be specified. + +The Content-Type is text/xml. + +The Content-Length must be specified and must be correct. + +Payload format + +The payload is in XML, a single structure. + +The must contain a sub-item, a string, containing the name of the method to be called. The string may only contain identifier characters, upper and lower-case A-Z, the numeric characters, 0-9, underscore, dot, colon and slash. It's entirely up to the server to decide how to interpret the characters in a methodName. + +For example, the methodName could be the name of a file containing a script that executes on an incoming request. It could be the name of a cell in a database table. Or it could be a path to a file contained within a hierarchy of folders and files. + +If the procedure call has parameters, the must contain a sub-item. The sub-item can contain any number of s, each of which has a . + +Scalar s + +s can be scalars, type is indicated by nesting the value inside one of the tags listed in this table: + +Tag Type Example + or four-byte signed integer -12 + 0 (false) or 1 (true) 1 + string hello world + double-precision signed floating point number -12.214 + date/time 19980717T14:08:55 + base64-encoded binary eW91IGNhbid0IHJlYWQgdGhpcyE= + +If no type is indicated, the type is string. + +s + +A value can also be of type . + +A contains s and each contains a and a . + +Here's an example of a two-element : + + + + lowerBound + 18 + + + upperBound + 139 + + + +s can be recursive, any may contain a or any other type, including an , described below. + +s + +A value can also be of type . + +An contains a single element, which can contain any number of s. + +Here's an example of a four-element array: + + + + 12 + Egypt + 0 + -31 + + + + elements do not have names. + +You can mix types as the example above illustrates. + +s can be recursive, any value may contain an or any other type, including a , described above. + +Response example + +Here's an example of a response to an XML-RPC request: + +HTTP/1.1 200 OK +Connection: close +Content-Length: 158 +Content-Type: text/xml +Date: Fri, 17 Jul 1998 19:55:08 GMT +Server: UserLand Frontier/5.1.2-WinNT + + South Dakota + +Response format + +Unless there's a lower-level error, always return 200 OK. + +The Content-Type is text/xml. Content-Length must be present and correct. + +The body of the response is a single XML structure, a , which can contain a single which contains a single which contains a single . + +The could also contain a which contains a which is a containing two elements, one named , an and one named , a . + +A can not contain both a and a . + +Fault example + +HTTP/1.1 200 OK +Connection: close +Content-Length: 426 +Content-Type: text/xml +Date: Fri, 17 Jul 1998 19:55:02 GMT +Server: UserLand Frontier/5.1.2-WinNT + + faultCode 4 faultString Too many parameters. + +Strategies/Goals + +Firewalls. The goal of this protocol is to lay a compatible foundation across different environments, no new power is provided beyond the capabilities of the CGI interface. Firewall software can watch for POSTs whose Content-Type is text/xml. + +Discoverability. We wanted a clean, extensible format that's very simple. It should be possible for an HTML coder to be able to look at a file containing an XML-RPC procedure call, understand what it's doing, and be able to modify it and have it work on the first or second try. + +Easy to implement. We also wanted it to be an easy to implement protocol that could quickly be adapted to run in other environments or on other operating systems. + +Updated 1/21/99 DW + +The following questions came up on the UserLand discussion group as XML-RPC was being implemented in Python. + + The Response Format section says "The body of the response is a single XML structure, a , which can contain a single ..." This is confusing. Can we leave out the ? + + No you cannot leave it out if the procedure executed successfully. There are only two options, either a response contains a structure or it contains a structure. That's why we used the word "can" in that sentence. + + Is "boolean" a distinct data type, or can boolean values be interchanged with integers (e.g. zero=false, non-zero=true)? + + Yes, boolean is a distinct data type. Some languages/environments allow for an easy coercion from zero to false and one to true, but if you mean true, send a boolean type with the value true, so your intent can't possibly be misunderstood. + + What is the legal syntax (and range) for integers? How to deal with leading zeros? Is a leading plus sign allowed? How to deal with whitespace? + + An integer is a 32-bit signed number. You can include a plus or minus at the beginning of a string of numeric characters. Leading zeros are collapsed. Whitespace is not permitted. Just numeric characters preceeded by a plus or minus. + + What is the legal syntax (and range) for floating point values (doubles)? How is the exponent represented? How to deal with whitespace? Can infinity and "not a number" be represented? + + There is no representation for infinity or negative infinity or "not a number". At this time, only decimal point notation is allowed, a plus or a minus, followed by any number of numeric characters, followed by a period and any number of numeric characters. Whitespace is not allowed. The range of allowable values is implementation-dependent, is not specified. + + What characters are allowed in strings? Non-printable characters? Null characters? Can a "string" be used to hold an arbitrary chunk of binary data? + + Any characters are allowed in a string except < and &, which are encoded as < and &. A string can be used to encode binary data. + + Does the "struct" element keep the order of keys. Or in other words, is the struct "foo=1, bar=2" equivalent to "bar=2, foo=1" or not? + + The struct element does not preserve the order of the keys. The two structs are equivalent. + + Can the struct contain other members than and ? Is there a global list of faultCodes? (so they can be mapped to distinct exceptions for languages like Python and Java)? + + A struct may not contain members other than those specified. This is true for all other structures. We believe the specification is flexible enough so that all reasonable data-transfer needs can be accomodated within the specified structures. If you believe strongly that this is not true, please post a message on the discussion group. + + There is no global list of fault codes. It is up to the server implementer, or higher-level standards to specify fault codes. + + What timezone should be assumed for the dateTime.iso8601 type? UTC? localtime? + + Don't assume a timezone. It should be specified by the server in its documentation what assumptions it makes about timezones. + +Additions + + type. 1/21/99 DW. + +Updated 6/30/03 DW + +Removed "ASCII" from definition of string. + +Changed copyright dates, below, to 1999-2003 from 1998-99. + +Copyright and disclaimer + +© Copyright 1998-2003 UserLand Software. All Rights Reserved. + +This document and translations of it may be copied and furnished to others, and derivative works that comment on or otherwise explain it or assist in its implementation may be prepared, copied, published and distributed, in whole or in part, without restriction of any kind, provided that the above copyright notice and these paragraphs are included on all such copies and derivative works. + +This document may not be modified in any way, such as by removing the copyright notice or references to UserLand or other organizations. Further, while these copyright restrictions apply to the written XML-RPC specification, no claim of ownership is made by UserLand to the protocol it describes. Any party may, for commercial or non-commercial purposes, implement this protocol without royalty or license fee to UserLand. The limited permissions granted herein are perpetual and will not be revoked by UserLand or its successors or assigns. + +This document and the information contained herein is provided on an "AS IS" basis and USERLAND DISCLAIMS ALL WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTY THAT THE USE OF THE INFORMATION HEREIN WILL NOT INFRINGE ANY RIGHTS OR ANY IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. \ No newline at end of file diff --git a/OpenSubtitlesHandler/XML-RPC/Enums/XmlRpcValueType.cs b/OpenSubtitlesHandler/XML-RPC/Enums/XmlRpcValueType.cs new file mode 100644 index 0000000000..ef0c203ff1 --- /dev/null +++ b/OpenSubtitlesHandler/XML-RPC/Enums/XmlRpcValueType.cs @@ -0,0 +1,25 @@ +/* This file is part of OpenSubtitles Handler + A library that handle OpenSubtitles.org XML-RPC methods. + + Copyright © Ala Ibrahim Hadid 2013 + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + */ +namespace XmlRpcHandler +{ + public enum XmlRpcBasicValueType + { + String, Int, Boolean, Double, dateTime_iso8601, base64 + } +} diff --git a/OpenSubtitlesHandler/XML-RPC/Types/XmlRpcMethodCall.cs b/OpenSubtitlesHandler/XML-RPC/Types/XmlRpcMethodCall.cs new file mode 100644 index 0000000000..1ec3622b23 --- /dev/null +++ b/OpenSubtitlesHandler/XML-RPC/Types/XmlRpcMethodCall.cs @@ -0,0 +1,63 @@ +/* This file is part of OpenSubtitles Handler + A library that handle OpenSubtitles.org XML-RPC methods. + + Copyright © Ala Ibrahim Hadid 2013 + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + */ +using System; +using System.Collections.Generic; + +namespace XmlRpcHandler +{ + /// + /// A method call + /// + public struct XmlRpcMethodCall + { + /// + /// A method call + /// + /// The name of this method + public XmlRpcMethodCall(string name) + { + this.name = name; + this.parameters = new List(); + } + /// + /// A method call + /// + /// The name of this method + /// A list of parameters + public XmlRpcMethodCall(string name, List parameters) + { + this.name = name; + this.parameters = parameters; + } + + private string name; + private List parameters; + + /// + /// Get or set the name of this method + /// + public string Name + { get { return name; } set { name = value; } } + /// + /// Get or set the parameters to be sent + /// + public List Parameters + { get { return parameters; } set { parameters = value; } } + } +} diff --git a/OpenSubtitlesHandler/XML-RPC/Values/IXmlRpcValue.cs b/OpenSubtitlesHandler/XML-RPC/Values/IXmlRpcValue.cs new file mode 100644 index 0000000000..19bc60347b --- /dev/null +++ b/OpenSubtitlesHandler/XML-RPC/Values/IXmlRpcValue.cs @@ -0,0 +1,37 @@ +/* This file is part of OpenSubtitles Handler + A library that handle OpenSubtitles.org XML-RPC methods. + + Copyright © Ala Ibrahim Hadid 2013 + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + */ +using System; + +namespace XmlRpcHandler +{ + public abstract class IXmlRpcValue + { + public IXmlRpcValue() + { } + public IXmlRpcValue(object data) + { + this.data = data; + } + private object data; + /// + /// Get or set the data of this value + /// + public virtual object Data { get { return data; } set { data = value; } } + } +} diff --git a/OpenSubtitlesHandler/XML-RPC/Values/XmlRpcStructMember.cs b/OpenSubtitlesHandler/XML-RPC/Values/XmlRpcStructMember.cs new file mode 100644 index 0000000000..12c86fdbfe --- /dev/null +++ b/OpenSubtitlesHandler/XML-RPC/Values/XmlRpcStructMember.cs @@ -0,0 +1,44 @@ +/* This file is part of OpenSubtitles Handler + A library that handle OpenSubtitles.org XML-RPC methods. + + Copyright © Ala Ibrahim Hadid 2013 + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + */ +using System; + +namespace XmlRpcHandler +{ + public class XmlRpcStructMember + { + public XmlRpcStructMember(string name, IXmlRpcValue data) + { + this.name = name; + this.data = data; + } + private string name; + private IXmlRpcValue data; + + /// + /// Get or set the name of this member + /// + public string Name + { get { return name; } set { name = value; } } + /// + /// Get or set the data of this member + /// + public IXmlRpcValue Data + { get { return data; } set { data = value; } } + } +} diff --git a/OpenSubtitlesHandler/XML-RPC/Values/XmlRpcValueArray.cs b/OpenSubtitlesHandler/XML-RPC/Values/XmlRpcValueArray.cs new file mode 100644 index 0000000000..8fd8b5ca03 --- /dev/null +++ b/OpenSubtitlesHandler/XML-RPC/Values/XmlRpcValueArray.cs @@ -0,0 +1,121 @@ +/* This file is part of OpenSubtitles Handler + A library that handle OpenSubtitles.org XML-RPC methods. + + Copyright © Ala Ibrahim Hadid 2013 + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + */ +using System; +using System.Collections.Generic; + +namespace XmlRpcHandler +{ + public class XmlRpcValueArray : IXmlRpcValue + { + public XmlRpcValueArray() : + base() + { + values = new List(); + } + public XmlRpcValueArray(object data) : + base(data) + { + values = new List(); + } + public XmlRpcValueArray(string[] texts) : + base() + { + values = new List(); + foreach (string val in texts) + { + values.Add(new XmlRpcValueBasic(val)); + } + } + public XmlRpcValueArray(int[] ints) : + base() + { + values = new List(); + foreach (int val in ints) + { + values.Add(new XmlRpcValueBasic(val)); + } + } + public XmlRpcValueArray(double[] doubles) : + base() + { + values = new List(); + foreach (double val in doubles) + { + values.Add(new XmlRpcValueBasic(val)); + } + } + public XmlRpcValueArray(bool[] bools) : + base() + { + values = new List(); + foreach (bool val in bools) + { + values.Add(new XmlRpcValueBasic(val)); + } + } + public XmlRpcValueArray(long[] base24s) : + base() + { + values = new List(); + foreach (long val in base24s) + { + values.Add(new XmlRpcValueBasic(val)); + } + } + public XmlRpcValueArray(DateTime[] dates) : + base() + { + values = new List(); + foreach (DateTime val in dates) + { + values.Add(new XmlRpcValueBasic(val)); + } + } + public XmlRpcValueArray(XmlRpcValueBasic[] basicValues) : + base() + { + values = new List(); + foreach (XmlRpcValueBasic val in basicValues) + { + values.Add(val); + } + } + public XmlRpcValueArray(XmlRpcValueStruct[] structs) : + base() + { + values = new List(); + foreach (XmlRpcValueStruct val in structs) + { + values.Add(val); + } + } + public XmlRpcValueArray(XmlRpcValueArray[] arrays) : + base() + { + values = new List(); + foreach (XmlRpcValueArray val in arrays) + { + values.Add(val); + } + } + private List values; + + public List Values { get { return values; } set { values = value; } } + } +} diff --git a/OpenSubtitlesHandler/XML-RPC/Values/XmlRpcValueBasic.cs b/OpenSubtitlesHandler/XML-RPC/Values/XmlRpcValueBasic.cs new file mode 100644 index 0000000000..2827283ff8 --- /dev/null +++ b/OpenSubtitlesHandler/XML-RPC/Values/XmlRpcValueBasic.cs @@ -0,0 +1,100 @@ +/* This file is part of OpenSubtitles Handler + A library that handle OpenSubtitles.org XML-RPC methods. + + Copyright © Ala Ibrahim Hadid 2013 + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + */ +using System; +using System.Collections.Generic; + +namespace XmlRpcHandler +{ + public class XmlRpcValueBasic : IXmlRpcValue + { + public XmlRpcValueBasic() + : base() + { } + public XmlRpcValueBasic(string data) + : base(data) + { this.type = XmlRpcBasicValueType.String; } + public XmlRpcValueBasic(int data) + : base(data) + { this.type = XmlRpcBasicValueType.Int; } + public XmlRpcValueBasic(double data) + : base(data) + { this.type = XmlRpcBasicValueType.Double; } + public XmlRpcValueBasic(DateTime data) + : base(data) + { this.type = XmlRpcBasicValueType.dateTime_iso8601; } + public XmlRpcValueBasic(bool data) + : base(data) + { this.type = XmlRpcBasicValueType.Boolean; } + public XmlRpcValueBasic(long data) + : base(data) + { this.type = XmlRpcBasicValueType.base64; } + public XmlRpcValueBasic(object data, XmlRpcBasicValueType type) + : base(data) + { this.type = type; } + + private XmlRpcBasicValueType type = XmlRpcBasicValueType.String; + /// + /// Get or set the type of this basic value + /// + public XmlRpcBasicValueType ValueType { get { return type; } set { type = value; } } + /*Oprators. help a lot.*/ + public static implicit operator string(XmlRpcValueBasic f) + { + if (f.type == XmlRpcBasicValueType.String) + return f.Data.ToString(); + else + throw new Exception("Unable to convert, this value is not string type."); + } + public static implicit operator int(XmlRpcValueBasic f) + { + if (f.type == XmlRpcBasicValueType.String) + return (int)f.Data; + else + throw new Exception("Unable to convert, this value is not int type."); + } + public static implicit operator double(XmlRpcValueBasic f) + { + if (f.type == XmlRpcBasicValueType.String) + return (double)f.Data; + else + throw new Exception("Unable to convert, this value is not double type."); + } + public static implicit operator bool(XmlRpcValueBasic f) + { + if (f.type == XmlRpcBasicValueType.String) + return (bool)f.Data; + else + throw new Exception("Unable to convert, this value is not bool type."); + } + public static implicit operator long(XmlRpcValueBasic f) + { + if (f.type == XmlRpcBasicValueType.String) + return (long)f.Data; + else + throw new Exception("Unable to convert, this value is not long type."); + } + public static implicit operator DateTime(XmlRpcValueBasic f) + { + if (f.type == XmlRpcBasicValueType.String) + return (DateTime)f.Data; + else + throw new Exception("Unable to convert, this value is not DateTime type."); + } + } +} diff --git a/OpenSubtitlesHandler/XML-RPC/Values/XmlRpcValueStruct.cs b/OpenSubtitlesHandler/XML-RPC/Values/XmlRpcValueStruct.cs new file mode 100644 index 0000000000..9e4cf6056e --- /dev/null +++ b/OpenSubtitlesHandler/XML-RPC/Values/XmlRpcValueStruct.cs @@ -0,0 +1,43 @@ +/* This file is part of OpenSubtitles Handler + A library that handle OpenSubtitles.org XML-RPC methods. + + Copyright © Ala Ibrahim Hadid 2013 + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + */ +using System; +using System.Collections.Generic; + +namespace XmlRpcHandler +{ + /// + /// Represents XML-RPC struct + /// + public class XmlRpcValueStruct : IXmlRpcValue + { + /// + /// Represents XML-RPC struct + /// + /// + public XmlRpcValueStruct(List members) + { this.members = members; } + + private List members; + /// + /// Get or set the members collection + /// + public List Members + { get { return members; } set { members = value; } } + } +} diff --git a/OpenSubtitlesHandler/XML-RPC/XmlRpcGenerator.cs b/OpenSubtitlesHandler/XML-RPC/XmlRpcGenerator.cs new file mode 100644 index 0000000000..028b734dc5 --- /dev/null +++ b/OpenSubtitlesHandler/XML-RPC/XmlRpcGenerator.cs @@ -0,0 +1,323 @@ +/* This file is part of OpenSubtitles Handler + A library that handle OpenSubtitles.org XML-RPC methods. + + Copyright © Ala Ibrahim Hadid 2013 + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + */ +using System; +using System.Text; +using System.Collections.Generic; +using System.IO; +using System.Xml; +namespace XmlRpcHandler +{ + /// + /// A class for making XML-RPC requests. The requests then can be sent directly as http request. + /// + public class XmlRpcGenerator + { + /// + /// Generate XML-RPC request using method call. + /// + /// The method call + /// The request in xml. + public static byte[] Generate(XmlRpcMethodCall method) + { return Generate(new XmlRpcMethodCall[] { method }); } + /// + /// Generate XML-RPC request using method calls array. + /// + /// The method calls array + /// The request in utf8 xml string as buffer + public static byte[] Generate(XmlRpcMethodCall[] methods) + { + if (methods == null) + throw new Exception("No method to write !"); + if (methods.Length == 0) + throw new Exception("No method to write !"); + // Create xml + XmlWriterSettings sett = new XmlWriterSettings(); + sett.Indent = true; + + sett.Encoding = Encoding.UTF8; + FileStream str = new FileStream(Path.GetTempPath() + "\\request.xml", FileMode.Create, FileAccess.Write); + + XmlWriter XMLwrt = XmlWriter.Create(str, sett); + // Let's write the methods + foreach (XmlRpcMethodCall method in methods) + { + XMLwrt.WriteStartElement("methodCall");//methodCall + XMLwrt.WriteStartElement("methodName");//methodName + XMLwrt.WriteString(method.Name); + XMLwrt.WriteEndElement();//methodName + XMLwrt.WriteStartElement("params");//params + // Write values + foreach (IXmlRpcValue p in method.Parameters) + { + XMLwrt.WriteStartElement("param");//param + if (p is XmlRpcValueBasic) + { + WriteBasicValue(XMLwrt, (XmlRpcValueBasic)p); + } + else if (p is XmlRpcValueStruct) + { + WriteStructValue(XMLwrt, (XmlRpcValueStruct)p); + } + else if (p is XmlRpcValueArray) + { + WriteArrayValue(XMLwrt, (XmlRpcValueArray)p); + } + XMLwrt.WriteEndElement();//param + } + + XMLwrt.WriteEndElement();//params + XMLwrt.WriteEndElement();//methodCall + } + XMLwrt.Flush(); + XMLwrt.Close(); + str.Close(); + string requestContent = File.ReadAllText(Path.GetTempPath() + "\\request.xml"); + return Encoding.UTF8.GetBytes(requestContent); + } + /// + /// Decode response then return the values + /// + /// The response xml string as provided by server as methodResponse + /// + public static XmlRpcMethodCall[] DecodeMethodResponse(string xmlResponse) + { + List methods = new List(); + XmlReaderSettings sett = new XmlReaderSettings(); + sett.DtdProcessing = DtdProcessing.Ignore; + sett.IgnoreWhitespace = true; + MemoryStream str = new MemoryStream(Encoding.ASCII.GetBytes(xmlResponse)); + if (xmlResponse.Contains(@"encoding=""utf-8""")) + { + str = new MemoryStream(Encoding.UTF8.GetBytes(xmlResponse)); + } + XmlReader XMLread = XmlReader.Create(str, sett); + + XmlRpcMethodCall call = new XmlRpcMethodCall("methodResponse"); + // Read parameters + while (XMLread.Read()) + { + if (XMLread.Name == "param" && XMLread.IsStartElement()) + { + IXmlRpcValue val = ReadValue(XMLread); + if (val != null) + call.Parameters.Add(val); + } + } + methods.Add(call); + XMLread.Close(); + return methods.ToArray(); + } + + private static void WriteBasicValue(XmlWriter XMLwrt, XmlRpcValueBasic val) + { + XMLwrt.WriteStartElement("value");//value + switch (val.ValueType) + { + case XmlRpcBasicValueType.String: + XMLwrt.WriteStartElement("string"); + if (val.Data != null) + XMLwrt.WriteString(val.Data.ToString()); + XMLwrt.WriteEndElement(); + break; + case XmlRpcBasicValueType.Int: + XMLwrt.WriteStartElement("int"); + if (val.Data != null) + XMLwrt.WriteString(val.Data.ToString()); + XMLwrt.WriteEndElement(); + break; + case XmlRpcBasicValueType.Boolean: + XMLwrt.WriteStartElement("boolean"); + if (val.Data != null) + XMLwrt.WriteString(((bool)val.Data) ? "1" : "0"); + XMLwrt.WriteEndElement(); + break; + case XmlRpcBasicValueType.Double: + XMLwrt.WriteStartElement("double"); + if (val.Data != null) + XMLwrt.WriteString(val.Data.ToString()); + XMLwrt.WriteEndElement(); + break; + case XmlRpcBasicValueType.dateTime_iso8601: + XMLwrt.WriteStartElement("dateTime.iso8601"); + // Get date time format + if (val.Data != null) + { + DateTime time = (DateTime)val.Data; + string dt = time.Year + time.Month.ToString("D2") + time.Day.ToString("D2") + + "T" + time.Hour.ToString("D2") + ":" + time.Minute.ToString("D2") + ":" + + time.Second.ToString("D2"); + XMLwrt.WriteString(dt); + } + XMLwrt.WriteEndElement(); + break; + case XmlRpcBasicValueType.base64: + XMLwrt.WriteStartElement("base64"); + if (val.Data != null) + XMLwrt.WriteString(Convert.ToBase64String(BitConverter.GetBytes((long)val.Data))); + XMLwrt.WriteEndElement(); + break; + } + XMLwrt.WriteEndElement();//value + } + 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 + } + private static void WriteArrayValue(XmlWriter XMLwrt, XmlRpcValueArray val) + { + XMLwrt.WriteStartElement("value");//value + XMLwrt.WriteStartElement("array");//array + XMLwrt.WriteStartElement("data");//data + foreach (IXmlRpcValue o in val.Values) + { + if (o is XmlRpcValueBasic) + { + WriteBasicValue(XMLwrt, (XmlRpcValueBasic)o); + } + else if (o is XmlRpcValueStruct) + { + WriteStructValue(XMLwrt, (XmlRpcValueStruct)o); + } + else if (o is XmlRpcValueArray) + { + WriteArrayValue(XMLwrt, (XmlRpcValueArray)o); + } + } + XMLwrt.WriteEndElement();//data + XMLwrt.WriteEndElement();//array + XMLwrt.WriteEndElement();//value + } + 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()), 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()), XmlRpcBasicValueType.Double); + } + else if (xmlReader.Name == "dateTime.iso8601" && xmlReader.IsStartElement()) + { + string date = xmlReader.ReadString(); + int year = int.Parse(date.Substring(0, 4)); + int month = int.Parse(date.Substring(4, 2)); + int day = int.Parse(date.Substring(6, 2)); + int hour = int.Parse(date.Substring(9, 2)); + int minute = int.Parse(date.Substring(12, 2));//19980717T14:08:55 + int sec = int.Parse(date.Substring(15, 2)); + 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()); + // 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; + } + } +}