remove open subtitles from the server

pull/1096/head
dkanada 5 years ago
parent f77af5f6e4
commit 715ddbb3b0

@ -13,7 +13,6 @@
<ProjectReference Include="..\Mono.Nat\Mono.Nat.csproj" />
<ProjectReference Include="..\MediaBrowser.Api\MediaBrowser.Api.csproj" />
<ProjectReference Include="..\MediaBrowser.LocalMetadata\MediaBrowser.LocalMetadata.csproj" />
<ProjectReference Include="..\OpenSubtitlesHandler\OpenSubtitlesHandler.csproj" />
<ProjectReference Include="..\Emby.Photos\Emby.Photos.csproj" />
<ProjectReference Include="..\Emby.Drawing\Emby.Drawing.csproj" />
<ProjectReference Include="..\Emby.XmlTv\Emby.XmlTv\Emby.XmlTv.csproj" />

@ -14,7 +14,6 @@
<ProjectReference Include="..\MediaBrowser.Common\MediaBrowser.Common.csproj" />
<ProjectReference Include="..\MediaBrowser.Controller\MediaBrowser.Controller.csproj" />
<ProjectReference Include="..\MediaBrowser.Model\MediaBrowser.Model.csproj" />
<ProjectReference Include="..\OpenSubtitlesHandler\OpenSubtitlesHandler.csproj" />
</ItemGroup>
<ItemGroup>

@ -1,29 +0,0 @@
using System.Collections.Generic;
using MediaBrowser.Common.Configuration;
using MediaBrowser.Model.Providers;
namespace MediaBrowser.MediaEncoding.Subtitles
{
public static class ConfigurationExtension
{
public static SubtitleOptions GetSubtitleConfiguration(this IConfigurationManager manager)
{
return manager.GetConfiguration<SubtitleOptions>("subtitles");
}
}
public class SubtitleConfigurationFactory : IConfigurationFactory
{
public IEnumerable<ConfigurationStore> GetConfigurations()
{
return new List<ConfigurationStore>
{
new ConfigurationStore
{
Key = "subtitles",
ConfigurationType = typeof (SubtitleOptions)
}
};
}
}
}

@ -1,347 +0,0 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using MediaBrowser.Common.Configuration;
using MediaBrowser.Common.Extensions;
using MediaBrowser.Common.Net;
using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Providers;
using MediaBrowser.Controller.Security;
using MediaBrowser.Controller.Subtitles;
using MediaBrowser.Model.Dto;
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.IO;
using MediaBrowser.Model.Providers;
using MediaBrowser.Model.Serialization;
using Microsoft.Extensions.Logging;
using OpenSubtitlesHandler;
namespace MediaBrowser.MediaEncoding.Subtitles
{
public class OpenSubtitleDownloader : ISubtitleProvider, IDisposable
{
private readonly ILogger _logger;
private readonly IHttpClient _httpClient;
private readonly CultureInfo _usCulture = new CultureInfo("en-US");
private readonly IServerConfigurationManager _config;
private readonly IJsonSerializer _json;
private readonly IFileSystem _fileSystem;
public OpenSubtitleDownloader(ILoggerFactory loggerFactory, IHttpClient httpClient, IServerConfigurationManager config, IJsonSerializer json, IFileSystem fileSystem)
{
_logger = loggerFactory.CreateLogger(GetType().Name);
_httpClient = httpClient;
_config = config;
_json = json;
_fileSystem = fileSystem;
_config.NamedConfigurationUpdating += _config_NamedConfigurationUpdating;
Utilities.HttpClient = httpClient;
OpenSubtitles.SetUserAgent("jellyfin");
}
private const string PasswordHashPrefix = "h:";
void _config_NamedConfigurationUpdating(object sender, ConfigurationUpdateEventArgs e)
{
if (!string.Equals(e.Key, "subtitles", StringComparison.OrdinalIgnoreCase))
{
return;
}
var options = (SubtitleOptions)e.NewConfiguration;
if (options != null &&
!string.IsNullOrWhiteSpace(options.OpenSubtitlesPasswordHash) &&
!options.OpenSubtitlesPasswordHash.StartsWith(PasswordHashPrefix, StringComparison.OrdinalIgnoreCase))
{
options.OpenSubtitlesPasswordHash = EncodePassword(options.OpenSubtitlesPasswordHash);
}
}
private static string EncodePassword(string password)
{
var bytes = Encoding.UTF8.GetBytes(password);
return PasswordHashPrefix + Convert.ToBase64String(bytes);
}
private static string DecodePassword(string password)
{
if (password == null ||
!password.StartsWith(PasswordHashPrefix, StringComparison.OrdinalIgnoreCase))
{
return string.Empty;
}
var bytes = Convert.FromBase64String(password.Substring(2));
return Encoding.UTF8.GetString(bytes, 0, bytes.Length);
}
public string Name => "Open Subtitles";
private SubtitleOptions GetOptions()
{
return _config.GetSubtitleConfiguration();
}
public IEnumerable<VideoContentType> SupportedMediaTypes
{
get
{
var options = GetOptions();
if (string.IsNullOrWhiteSpace(options.OpenSubtitlesUsername) ||
string.IsNullOrWhiteSpace(options.OpenSubtitlesPasswordHash))
{
return new VideoContentType[] { };
}
return new[] { VideoContentType.Episode, VideoContentType.Movie };
}
}
public Task<SubtitleResponse> GetSubtitles(string id, CancellationToken cancellationToken)
{
return GetSubtitlesInternal(id, GetOptions(), cancellationToken);
}
private DateTime _lastRateLimitException;
private async Task<SubtitleResponse> GetSubtitlesInternal(string id,
SubtitleOptions options,
CancellationToken cancellationToken)
{
if (string.IsNullOrWhiteSpace(id))
{
throw new ArgumentNullException(nameof(id));
}
var idParts = id.Split(new[] { '-' }, 3);
var format = idParts[0];
var language = idParts[1];
var ossId = idParts[2];
var downloadsList = new[] { int.Parse(ossId, _usCulture) };
await Login(cancellationToken).ConfigureAwait(false);
if ((DateTime.UtcNow - _lastRateLimitException).TotalHours < 1)
{
throw new RateLimitExceededException("OpenSubtitles rate limit reached");
}
var resultDownLoad = await OpenSubtitles.DownloadSubtitlesAsync(downloadsList, cancellationToken).ConfigureAwait(false);
if ((resultDownLoad.Status ?? string.Empty).IndexOf("407", StringComparison.OrdinalIgnoreCase) != -1)
{
_lastRateLimitException = DateTime.UtcNow;
throw new RateLimitExceededException("OpenSubtitles rate limit reached");
}
if (!(resultDownLoad is MethodResponseSubtitleDownload))
{
throw new Exception("Invalid response type");
}
var results = ((MethodResponseSubtitleDownload)resultDownLoad).Results;
_lastRateLimitException = DateTime.MinValue;
if (results.Count == 0)
{
var msg = string.Format("Subtitle with Id {0} was not found. Name: {1}. Status: {2}. Message: {3}",
ossId,
resultDownLoad.Name ?? string.Empty,
resultDownLoad.Status ?? string.Empty,
resultDownLoad.Message ?? string.Empty);
throw new ResourceNotFoundException(msg);
}
var data = Convert.FromBase64String(results.First().Data);
return new SubtitleResponse
{
Format = format,
Language = language,
Stream = new MemoryStream(Utilities.Decompress(new MemoryStream(data)))
};
}
private DateTime _lastLogin;
private async Task Login(CancellationToken cancellationToken)
{
if ((DateTime.UtcNow - _lastLogin).TotalSeconds < 60)
{
return;
}
var options = GetOptions();
var user = options.OpenSubtitlesUsername ?? string.Empty;
var password = DecodePassword(options.OpenSubtitlesPasswordHash);
var loginResponse = await OpenSubtitles.LogInAsync(user, password, "en", cancellationToken).ConfigureAwait(false);
if (!(loginResponse is MethodResponseLogIn))
{
throw new Exception("Authentication to OpenSubtitles failed.");
}
_lastLogin = DateTime.UtcNow;
}
public async Task<IEnumerable<NameIdPair>> GetSupportedLanguages(CancellationToken cancellationToken)
{
await Login(cancellationToken).ConfigureAwait(false);
var result = OpenSubtitles.GetSubLanguages("en");
if (!(result is MethodResponseGetSubLanguages))
{
_logger.LogError("Invalid response type");
return new List<NameIdPair>();
}
var results = ((MethodResponseGetSubLanguages)result).Languages;
return results.Select(i => new NameIdPair
{
Name = i.LanguageName,
Id = i.SubLanguageID
});
}
private string NormalizeLanguage(string language)
{
// Problem with Greek subtitle download #1349
if (string.Equals(language, "gre", StringComparison.OrdinalIgnoreCase))
{
return "ell";
}
return language;
}
public async Task<IEnumerable<RemoteSubtitleInfo>> Search(SubtitleSearchRequest request, CancellationToken cancellationToken)
{
var imdbIdText = request.GetProviderId(MetadataProviders.Imdb);
long imdbId = 0;
switch (request.ContentType)
{
case VideoContentType.Episode:
if (!request.IndexNumber.HasValue || !request.ParentIndexNumber.HasValue || string.IsNullOrEmpty(request.SeriesName))
{
_logger.LogDebug("Episode information missing");
return new List<RemoteSubtitleInfo>();
}
break;
case VideoContentType.Movie:
if (string.IsNullOrEmpty(request.Name))
{
_logger.LogDebug("Movie name missing");
return new List<RemoteSubtitleInfo>();
}
if (string.IsNullOrWhiteSpace(imdbIdText) || !long.TryParse(imdbIdText.TrimStart('t'), NumberStyles.Any, _usCulture, out imdbId))
{
_logger.LogDebug("Imdb id missing");
return new List<RemoteSubtitleInfo>();
}
break;
}
if (string.IsNullOrEmpty(request.MediaPath))
{
_logger.LogDebug("Path Missing");
return new List<RemoteSubtitleInfo>();
}
await Login(cancellationToken).ConfigureAwait(false);
var subLanguageId = NormalizeLanguage(request.Language);
string hash;
using (var fileStream = File.OpenRead(request.MediaPath))
{
hash = Utilities.ComputeHash(fileStream);
}
var fileInfo = _fileSystem.GetFileInfo(request.MediaPath);
var movieByteSize = fileInfo.Length;
var searchImdbId = request.ContentType == VideoContentType.Movie ? imdbId.ToString(_usCulture) : "";
var subtitleSearchParameters = request.ContentType == VideoContentType.Episode
? new List<SubtitleSearchParameters> {
new SubtitleSearchParameters(subLanguageId,
query: request.SeriesName,
season: request.ParentIndexNumber.Value.ToString(_usCulture),
episode: request.IndexNumber.Value.ToString(_usCulture))
}
: new List<SubtitleSearchParameters> {
new SubtitleSearchParameters(subLanguageId, imdbid: searchImdbId),
new SubtitleSearchParameters(subLanguageId, query: request.Name, imdbid: searchImdbId)
};
var parms = new List<SubtitleSearchParameters> {
new SubtitleSearchParameters( subLanguageId,
movieHash: hash,
movieByteSize: movieByteSize,
imdbid: searchImdbId ),
};
parms.AddRange(subtitleSearchParameters);
var result = await OpenSubtitles.SearchSubtitlesAsync(parms.ToArray(), cancellationToken).ConfigureAwait(false);
if (!(result is MethodResponseSubtitleSearch))
{
_logger.LogError("Invalid response type");
return new List<RemoteSubtitleInfo>();
}
Predicate<SubtitleSearchResult> mediaFilter =
x =>
request.ContentType == VideoContentType.Episode
? !string.IsNullOrEmpty(x.SeriesSeason) && !string.IsNullOrEmpty(x.SeriesEpisode) &&
int.Parse(x.SeriesSeason, _usCulture) == request.ParentIndexNumber &&
int.Parse(x.SeriesEpisode, _usCulture) == request.IndexNumber
: !string.IsNullOrEmpty(x.IDMovieImdb) && long.Parse(x.IDMovieImdb, _usCulture) == imdbId;
var results = ((MethodResponseSubtitleSearch)result).Results;
// Avoid implicitly captured closure
var hasCopy = hash;
return results.Where(x => x.SubBad == "0" && mediaFilter(x) && (!request.IsPerfectMatch || string.Equals(x.MovieHash, hash, StringComparison.OrdinalIgnoreCase)))
.OrderBy(x => (string.Equals(x.MovieHash, hash, StringComparison.OrdinalIgnoreCase) ? 0 : 1))
.ThenBy(x => Math.Abs(long.Parse(x.MovieByteSize, _usCulture) - movieByteSize))
.ThenByDescending(x => int.Parse(x.SubDownloadsCnt, _usCulture))
.ThenByDescending(x => double.Parse(x.SubRating, _usCulture))
.Select(i => new RemoteSubtitleInfo
{
Author = i.UserNickName,
Comment = i.SubAuthorComment,
CommunityRating = float.Parse(i.SubRating, _usCulture),
DownloadCount = int.Parse(i.SubDownloadsCnt, _usCulture),
Format = i.SubFormat,
ProviderName = Name,
ThreeLetterISOLanguageName = i.SubLanguageID,
Id = i.SubFormat + "-" + i.SubLanguageID + "-" + i.IDSubtitleFile,
Name = i.SubFileName,
DateCreated = DateTime.Parse(i.SubAddDate, _usCulture),
IsHashMatch = i.MovieHash == hasCopy
}).Where(i => !string.Equals(i.Format, "sub", StringComparison.OrdinalIgnoreCase) && !string.Equals(i.Format, "idx", StringComparison.OrdinalIgnoreCase));
}
public void Dispose()
{
_config.NamedConfigurationUpdating -= _config_NamedConfigurationUpdating;
}
}
}

@ -15,8 +15,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MediaBrowser.WebDashboard",
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MediaBrowser.Providers", "MediaBrowser.Providers\MediaBrowser.Providers.csproj", "{442B5058-DCAF-4263-BB6A-F21E31120A1B}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OpenSubtitlesHandler", "OpenSubtitlesHandler\OpenSubtitlesHandler.csproj", "{4A4402D4-E910-443B-B8FC-2C18286A2CA0}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MediaBrowser.XbmcMetadata", "MediaBrowser.XbmcMetadata\MediaBrowser.XbmcMetadata.csproj", "{23499896-B135-4527-8574-C26E926EA99E}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MediaBrowser.LocalMetadata", "MediaBrowser.LocalMetadata\MediaBrowser.LocalMetadata.csproj", "{7EF9F3E0-697D-42F3-A08F-19DEB5F84392}"

@ -1,92 +0,0 @@
/* 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 <http://www.gnu.org/licenses/>.
*/
using System;
namespace OpenSubtitlesHandler.Console
{
public class OSHConsole
{
/// <summary>
/// Write line to the console and raise the "LineWritten" event
/// </summary>
///
/// <param name="text">The debug line</param>
/// <param name="code">The status</param>
public static void WriteLine(string text, DebugCode code = DebugCode.None)
{
if (LineWritten != null)
LineWritten(null, new DebugEventArgs(text, code));
}
/// <summary>
/// Update the last written line
/// </summary>
/// <param name="text">The debug line</param>
/// <param name="code">The status</param>
public static void UpdateLine(string text, DebugCode code = DebugCode.None)
{
if (UpdateLastLine != null)
UpdateLastLine(null, new DebugEventArgs(text, code));
}
public static event EventHandler<DebugEventArgs> LineWritten;
public static event EventHandler<DebugEventArgs> UpdateLastLine;
}
public enum DebugCode
{
None,
Good,
Warning,
Error
}
/// <summary>
/// Console Debug Args
/// </summary>
public class DebugEventArgs : EventArgs
{
public DebugCode Code { get; private set; }
public string Text { get; private set; }
/// <summary>
/// Console Debug Args
/// </summary>
/// <param name="text">The debug line</param>
/// <param name="code">The status</param>
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; } }
}
}

@ -1,71 +0,0 @@
/* 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 <http://www.gnu.org/licenses/>.
*/
using System;
namespace OpenSubtitlesHandler
{
/// <summary>
/// When you call a method to communicate with OpenSubtitles server, that method should return this response with the reuired information.
/// </summary>
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 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; } }
}
public class DescriptionAttribute : Attribute
{
public DescriptionAttribute(string text) { }
}
public class CategoryAttribute : Attribute
{
public CategoryAttribute(string text) { }
}
}

@ -1,40 +0,0 @@
/* 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 <http://www.gnu.org/licenses/>.
*/
using System;
namespace OpenSubtitlesHandler
{
/// <summary>
/// Attributes to describe a method response object.
/// </summary>
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; } }
}
}

@ -1,31 +0,0 @@
/* 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 <http://www.gnu.org/licenses/>.
*/
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; } }
}
}

@ -1,32 +0,0 @@
/* 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 <http://www.gnu.org/licenses/>.
*/
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)
{ }
}
}

@ -1,35 +0,0 @@
/* 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 <http://www.gnu.org/licenses/>.
*/
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; } }
}
}

@ -1,59 +0,0 @@
/* 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 <http://www.gnu.org/licenses/>.
*/
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;
/// <summary>
/// Latest application version
/// </summary>
[Description("Latest application version"), Category("AutoUpdate")]
public string version { get { return _version; } set { _version = value; } }
/// <summary>
/// Download URL for Windows version
/// </summary>
[Description("Download URL for Windows version"), Category("AutoUpdate")]
public string url_windows { get { return _url_windows; } set { _url_windows = value; } }
/// <summary>
/// Application changelog and other comments
/// </summary>
[Description("Application changelog and other comments"), Category("AutoUpdate")]
public string comments { get { return _comments; } set { _comments = value; } }
/// <summary>
/// Download URL for Linux version
/// </summary>
[Description("Download URL for Linux version"), Category("AutoUpdate")]
public string url_linux { get { return _url_linux; } set { _url_linux = value; } }
}
}

@ -1,37 +0,0 @@
/* 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 <http://www.gnu.org/licenses/>.
*/
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<CheckMovieHashResult> results = new List<CheckMovieHashResult>();
public List<CheckMovieHashResult> Results
{ get { return results; } set { results = value; } }
}
}

@ -1,37 +0,0 @@
/* 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 <http://www.gnu.org/licenses/>.
*/
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<CheckMovieHash2Result> results = new List<CheckMovieHash2Result>();
public List<CheckMovieHash2Result> Results
{ get { return results; } set { results = value; } }
}
}

@ -1,38 +0,0 @@
/* 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 <http://www.gnu.org/licenses/>.
*/
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<CheckSubHashResult> results = new List<CheckSubHashResult>();
public List<CheckSubHashResult> Results { get { return results; } set { results = value; } }
}
}

@ -1,37 +0,0 @@
/* 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 <http://www.gnu.org/licenses/>.
*/
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<DetectLanguageResult> results = new List<DetectLanguageResult>();
public List<DetectLanguageResult> Results
{ get { return results; } set { results = value; } }
}
}

@ -1,36 +0,0 @@
/* 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 <http://www.gnu.org/licenses/>.
*/
namespace OpenSubtitlesHandler
{
/// <summary>
/// Response that can be used for general error like internet connection fail.
/// </summary>
[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)
{ }
}
}

@ -1,37 +0,0 @@
/* 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 <http://www.gnu.org/licenses/>.
*/
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<GetAvailableTranslationsResult> results = new List<GetAvailableTranslationsResult>();
public List<GetAvailableTranslationsResult> Results { get { return results; } set { results = value; } }
}
}

@ -1,39 +0,0 @@
/* 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 <http://www.gnu.org/licenses/>.
*/
using System.Collections.Generic;
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<GetCommentsResult> results = new List<GetCommentsResult>();
public List<GetCommentsResult> Results
{ get { return results; } set { results = value; } }
}
}

@ -1,39 +0,0 @@
/* 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 <http://www.gnu.org/licenses/>.
*/
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<SubtitleLanguage> languages = new List<SubtitleLanguage>();
public List<SubtitleLanguage> Languages
{ get { return languages; } set { languages = value; } }
}
}

@ -1,36 +0,0 @@
/* 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 <http://www.gnu.org/licenses/>.
*/
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; } }
}
}

@ -1,36 +0,0 @@
/* 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 <http://www.gnu.org/licenses/>.
*/
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; } }
}
}

@ -1,38 +0,0 @@
/* 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 <http://www.gnu.org/licenses/>.
*/
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<string> _accepted_moviehashes = new List<string>();
private List<string> _new_imdbs = new List<string>();
public List<string> accepted_moviehashes { get { return _accepted_moviehashes; } set { _accepted_moviehashes = value; } }
public List<string> new_imdbs { get { return _new_imdbs; } set { _new_imdbs = value; } }
}
}

@ -1,39 +0,0 @@
/* 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 <http://www.gnu.org/licenses/>.
*/
namespace OpenSubtitlesHandler
{
/// <summary>
/// Response can be used for log in/out operation.
/// </summary>
[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; } }
}
}

@ -1,73 +0,0 @@
/* 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 <http://www.gnu.org/licenses/>.
*/
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<string> cast = new List<string>();
private List<string> directors = new List<string>();
private List<string> writers = new List<string>();
private List<string> awards = new List<string>();
private List<string> genres = new List<string>();
private List<string> country = new List<string>();
private List<string> language = new List<string>();
private List<string> certification = new List<string>();
// 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<string> Cast { get { return cast; } set { cast = value; } }
public List<string> Directors { get { return directors; } set { directors = value; } }
public List<string> Writers { get { return writers; } set { writers = value; } }
public List<string> Genres { get { return genres; } set { genres = value; } }
public List<string> Awards { get { return awards; } set { awards = value; } }
public List<string> Country { get { return country; } set { country = value; } }
public List<string> Language { get { return language; } set { language = value; } }
public List<string> Certification { get { return certification; } set { certification = value; } }
}
}

@ -1,43 +0,0 @@
/* 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 <http://www.gnu.org/licenses/>.
*/
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<MovieSearchResult>();
}
public MethodResponseMovieSearch(string name, string message)
: base(name, message)
{
results = new List<MovieSearchResult>();
}
private List<MovieSearchResult> results;
public List<MovieSearchResult> Results
{ get { return results; } set { results = value; } }
}
}

@ -1,52 +0,0 @@
/* 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 <http://www.gnu.org/licenses/>.
*/
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; } }
}
}

@ -1,33 +0,0 @@
/* 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 <http://www.gnu.org/licenses/>.
*/
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)
{ }
}
}

@ -1,33 +0,0 @@
/* 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 <http://www.gnu.org/licenses/>.
*/
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)
{ }
}
}

@ -1,32 +0,0 @@
/* 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 <http://www.gnu.org/licenses/>.
*/
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)
{ }
}
}

@ -1,131 +0,0 @@
/* 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 <http://www.gnu.org/licenses/>.
*/
using System.Collections.Generic;
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<string> _last_update_strings = new List<string>();
/// <summary>
/// Version of server's XML-RPC API implementation
/// </summary>
[Description("Version of server's XML-RPC API implementation"), Category("OS")]
public string xmlrpc_version { get { return _xmlrpc_version; } set { _xmlrpc_version = value; } }
/// <summary>
/// XML-RPC interface URL
/// </summary>
[Description("XML-RPC interface URL"), Category("OS")]
public string xmlrpc_url { get { return _xmlrpc_url; } set { _xmlrpc_url = value; } }
/// <summary>
/// Server's application name and version
/// </summary>
[Description("Server's application name and version"), Category("OS")]
public string application { get { return _application; } set { _application = value; } }
/// <summary>
/// Contact e-mail address for server related quuestions and problems
/// </summary>
[Description("Contact e-mail address for server related quuestions and problems"), Category("OS")]
public string contact { get { return _contact; } set { _contact = value; } }
/// <summary>
/// Main server URL
/// </summary>
[Description("Main server URL"), Category("OS")]
public string website_url { get { return _website_url; } set { _website_url = value; } }
/// <summary>
/// Number of users currently online
/// </summary>
[Description("Number of users currently online"), Category("OS")]
public int users_online_total { get { return _users_online_total; } set { _users_online_total = value; } }
/// <summary>
/// Number of users currently online using a client application (XML-RPC API)
/// </summary>
[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; } }
/// <summary>
/// Number of currently logged-in users
/// </summary>
[Description("Number of currently logged-in users"), Category("OS")]
public int users_loggedin { get { return _users_loggedin; } set { _users_loggedin = value; } }
/// <summary>
/// Maximum number of users throughout the history
/// </summary>
[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; } }
/// <summary>
/// Number of registered users
/// </summary>
[Description("Number of registered users"), Category("OS")]
public string users_registered { get { return _users_registered; } set { _users_registered = value; } }
/// <summary>
/// Total number of subtitle downloads
/// </summary>
[Description("Total number of subtitle downloads"), Category("OS")]
public string subs_downloads { get { return _subs_downloads; } set { _subs_downloads = value; } }
/// <summary>
/// Total number of subtitle files stored on the server
/// </summary>
[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; } }
/// <summary>
/// Total number of movies in the database
/// </summary>
[Description("Total number of movies in the database"), Category("OS")]
public string movies_total { get { return _movies_total; } set { _movies_total = value; } }
/// <summary>
/// Total number of movie A.K.A. titles in the database
/// </summary>
[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; } }
/// <summary>
/// Total number of subtitle languages supported
/// </summary>
[Description("Total number of subtitle languages supported"), Category("OS")]
public string total_subtitles_languages { get { return _total_subtitles_languages; } set { _total_subtitles_languages = value; } }
/// <summary>
/// Structure containing information about last updates of translations.
/// </summary>
[Description("Structure containing information about last updates of translations"), Category("OS")]
public List<string> last_update_strings { get { return _last_update_strings; } set { _last_update_strings = value; } }
}
}

@ -1,44 +0,0 @@
/* 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 <http://www.gnu.org/licenses/>.
*/
using System.Collections.Generic;
namespace OpenSubtitlesHandler
{
/// <summary>
/// The response that should be used by subtitle download methods.
/// </summary>
[MethodResponseDescription("SubtitleDownload method response",
"SubtitleDownload method response hold all expected values from server.")]
public class MethodResponseSubtitleDownload : IMethodResponse
{
public MethodResponseSubtitleDownload()
: base()
{
results = new List<SubtitleDownloadResult>();
}
public MethodResponseSubtitleDownload(string name, string message)
: base(name, message)
{
results = new List<SubtitleDownloadResult>();
}
private List<SubtitleDownloadResult> results;
public List<SubtitleDownloadResult> Results
{ get { return results; } set { results = value; } }
}
}

@ -1,46 +0,0 @@
/* 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 <http://www.gnu.org/licenses/>.
*/
using System.Collections.Generic;
namespace OpenSubtitlesHandler
{
/// <summary>
/// Response to SearchSubtitle successed call.
/// </summary>
[MethodResponseDescription("SubtitleSearch method response",
"SubtitleSearch method response hold all expected values from server.")]
public class MethodResponseSubtitleSearch : IMethodResponse
{
public MethodResponseSubtitleSearch()
: base()
{
results = new List<SubtitleSearchResult>();
}
public MethodResponseSubtitleSearch(string name, string message)
: base(name, message)
{
results = new List<SubtitleSearchResult>();
}
private List<SubtitleSearchResult> results;
public List<SubtitleSearchResult> Results
{ get { return results; } set { results = value; } }
}
}

@ -1,43 +0,0 @@
/* 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 <http://www.gnu.org/licenses/>.
*/
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; } }
}
}

@ -1,40 +0,0 @@
/* 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 <http://www.gnu.org/licenses/>.
*/
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<SubtitleSearchResult> results = new List<SubtitleSearchResult>();
public int AlreadyInDB { get { return alreadyindb; } set { alreadyindb = value; } }
public List<SubtitleSearchResult> Results { get { return results; } set { results = value; } }
}
}

@ -1,38 +0,0 @@
/* 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 <http://www.gnu.org/licenses/>.
*/
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; } }
}
}

@ -1,39 +0,0 @@
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
--------------------------------------------

@ -1,48 +0,0 @@
using System;
using System.IO;
using System.Text;
namespace OpenSubtitlesHandler
{
public class MovieHasher
{
public static byte[] ComputeMovieHash(Stream input)
{
using (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);
}
byte[] result = BitConverter.GetBytes(lhash);
Array.Reverse(result);
return result;
}
}
public static string ToHexadecimal(byte[] bytes)
{
var hexBuilder = new StringBuilder();
for (int i = 0; i < bytes.Length; i++)
{
hexBuilder.Append(bytes[i].ToString("x2"));
}
return hexBuilder.ToString();
}
}
}

@ -1,42 +0,0 @@
/* 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 <http://www.gnu.org/licenses/>.
*/
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; } }
}
}

@ -1,37 +0,0 @@
/* 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 <http://www.gnu.org/licenses/>.
*/
using System.Collections.Generic;
namespace OpenSubtitlesHandler
{
public class CheckMovieHash2Result
{
private string name;
private List<CheckMovieHash2Data> data = new List<CheckMovieHash2Data>();
public string Name { get { return name; } set { name = value; } }
public List<CheckMovieHash2Data> Items { get { return data; } set { data = value; } }
public override string ToString()
{
return name;
}
}
}

@ -1,41 +0,0 @@
/* 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 <http://www.gnu.org/licenses/>.
*/
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;
}
}
}

@ -1,38 +0,0 @@
/* 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 <http://www.gnu.org/licenses/>.
*/
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; } }
}
}

@ -1,40 +0,0 @@
/* 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 <http://www.gnu.org/licenses/>.
*/
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; } }
/// <summary>
/// Title
/// </summary>
/// <returns></returns>
public override string ToString()
{
return title;
}
}
}

@ -1,30 +0,0 @@
/* 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 <http://www.gnu.org/licenses/>.
*/
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; } }
}
}

File diff suppressed because it is too large Load Diff

@ -1,13 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk">
<ItemGroup>
<ProjectReference Include="..\MediaBrowser.Common\MediaBrowser.Common.csproj" />
<ProjectReference Include="..\MediaBrowser.Model\MediaBrowser.Model.csproj" />
</ItemGroup>
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
</PropertyGroup>
</Project>

@ -1,39 +0,0 @@
/* 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 <http://www.gnu.org/licenses/>.
*/
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; } }
/// <summary>
/// LanguageID (LastCreated)
/// </summary>
/// <returns></returns>
public override string ToString()
{
return _language + " (" + _LastCreated + ")";
}
}
}

@ -1,36 +0,0 @@
/* 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 <http://www.gnu.org/licenses/>.
*/
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; } }
}
}

@ -1,24 +0,0 @@
using System.Reflection;
using System.Resources;
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("Jellyfin Project")]
[assembly: AssemblyProduct("Jellyfin: The Free Software Media System")]
[assembly: AssemblyCopyright("Copyright © 2013 Ala Ibrahim Hadid. Copyright © 2019 Jellyfin Contributors. Code released under the GNU General Public License Version 2")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: NeutralResourcesLanguage("en")]
// 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)]
[assembly: AssemblyVersion("1.0.3.0")]
[assembly: AssemblyFileVersion("2019.1.20.3")]

@ -1,20 +0,0 @@
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.

@ -1,30 +0,0 @@
/* 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 <http://www.gnu.org/licenses/>.
*/
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; } }
}
}

@ -1,43 +0,0 @@
/* 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 <http://www.gnu.org/licenses/>.
*/
namespace OpenSubtitlesHandler
{
public struct SubtitleDownloadResult
{
private string idsubtitlefile;
private string data;
public string IdSubtitleFile
{ get { return idsubtitlefile; } set { idsubtitlefile = value; } }
/// <summary>
/// Get or set the data of subtitle file. To decode, decode the string to base64 and then decompress with GZIP.
/// </summary>
public string Data
{ get { return data; } set { data = value; } }
/// <summary>
/// IdSubtitleFile
/// </summary>
/// <returns></returns>
public override string ToString()
{
return idsubtitlefile.ToString();
}
}
}

@ -1,39 +0,0 @@
/* 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 <http://www.gnu.org/licenses/>.
*/
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; } }
/// <summary>
/// LanguageName [SubLanguageID]
/// </summary>
/// <returns>LanguageName [SubLanguageID]</returns>
public override string ToString()
{
return _LanguageName + " [" + _SubLanguageID + "]";
}
}
}

@ -1,82 +0,0 @@
/* 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 <http://www.gnu.org/licenses/>.
*/
namespace OpenSubtitlesHandler
{
/// <summary>
/// Paramaters for subtitle search call
/// </summary>
public struct SubtitleSearchParameters
{
public SubtitleSearchParameters(string subLanguageId, string query = "", string season = "", string episode = "", string movieHash = "", long movieByteSize = 0, string imdbid = "")
{
this.subLanguageId = subLanguageId;
this.movieHash = movieHash;
this.movieByteSize = movieByteSize;
this.imdbid = imdbid;
this._episode = episode;
this._season = season;
this._query = 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; }
}
/// <summary>
/// List of language ISO639-3 language codes to search for, divided by ',' (e.g. 'cze,eng,slo')
/// </summary>
public string SubLangaugeID { get { return subLanguageId; } set { subLanguageId = value; } }
/// <summary>
/// Video file hash as calculated by one of the implementation functions as seen on http://trac.opensubtitles.org/projects/opensubtitles/wiki/HashSourceCodes
/// </summary>
public string MovieHash { get { return movieHash; } set { movieHash = value; } }
/// <summary>
/// Size of video file in bytes
/// </summary>
public long MovieByteSize { get { return movieByteSize; } set { movieByteSize = value; } }
/// <summary>
/// IMDb ID of movie this video is part of, belongs to.
/// </summary>
public string IMDbID { get { return imdbid; } set { imdbid = value; } }
}
}

@ -1,136 +0,0 @@
/* 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 <http://www.gnu.org/licenses/>.
*/
namespace OpenSubtitlesHandler
{
/// <summary>
/// The subtitle search result that comes with server response on SearchSubtitles successed call
/// </summary>
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; } }
/// <summary>
/// SubFileName + " (" + SubFormat + ")"
/// </summary>
/// <returns></returns>
public override string ToString()
{
return _SubFileName + " (" + _SubFormat + ")";
}
}
}

@ -1,47 +0,0 @@
/* 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 <http://www.gnu.org/licenses/>.
*/
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 + ")";
}
}
}

@ -1,46 +0,0 @@
/* 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 <http://www.gnu.org/licenses/>.
*/
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<UploadSubtitleParameters> 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<UploadSubtitleParameters> CDS { get { return cds; } set { cds = value; } }
}
}

@ -1,52 +0,0 @@
/* 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 <http://www.gnu.org/licenses/>.
*/
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; } }
/// <summary>
/// Sub content. Note: this value must be the subtitle file gziped and then base64 decoded.
/// </summary>
public string subcontent { get { return _subcontent; } set { _subcontent = value; } }
public override string ToString()
{
return _subfilename + " (" + _subhash + ")";
}
}
}

@ -1,174 +0,0 @@
/* 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 <http://www.gnu.org/licenses/>.
*/
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using MediaBrowser.Common.Net;
using MediaBrowser.Model.Cryptography;
namespace OpenSubtitlesHandler
{
/// <summary>
/// Include helper methods. All member are statics.
/// </summary>
public sealed class Utilities
{
public static ICryptoProvider CryptographyProvider { get; set; }
public static IHttpClient HttpClient { get; set; }
private static string XML_RPC_SERVER = "https://api.opensubtitles.org/xml-rpc";
//private static string XML_RPC_SERVER = "https://92.240.234.122/xml-rpc";
private static string HostHeader = "api.opensubtitles.org:443";
/// <summary>
/// Compute movie hash
/// </summary>
/// <returns>The hash as Hexadecimal string</returns>
public static string ComputeHash(Stream stream)
{
byte[] hash = MovieHasher.ComputeMovieHash(stream);
return MovieHasher.ToHexadecimal(hash);
}
/// <summary>
/// Decompress data using GZip
/// </summary>
/// <param name="dataToDecompress">The stream that hold the data</param>
/// <returns>Bytes array of decompressed data</returns>
public static byte[] Decompress(Stream dataToDecompress)
{
using (var target = new MemoryStream())
{
using (var decompressionStream = new System.IO.Compression.GZipStream(dataToDecompress, System.IO.Compression.CompressionMode.Decompress))
{
decompressionStream.CopyTo(target);
}
return target.ToArray();
}
}
/// <summary>
/// Compress data using GZip (the retunred buffer will be WITHOUT HEADER)
/// </summary>
/// <param name="dataToCompress">The stream that hold the data</param>
/// <returns>Bytes array of compressed data WITHOUT HEADER bytes</returns>
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();
}
/// <summary>
/// Handle server response stream and decode it as given encoding string.
/// </summary>
/// <returns>The string of the stream after decode using given encoding</returns>
public static string GetStreamString(Stream responseStream)
{
using (responseStream)
{
// Handle response, should be XML text.
var data = new List<byte>();
while (true)
{
int r = responseStream.ReadByte();
if (r < 0)
break;
data.Add((byte)r);
}
var bytes = data.ToArray();
return Encoding.ASCII.GetString(bytes, 0, bytes.Length);
}
}
public static byte[] GetASCIIBytes(string text)
{
return Encoding.ASCII.GetBytes(text);
}
/// <summary>
/// Send a request to the server
/// </summary>
/// <param name="request">The request buffer to send as bytes array.</param>
/// <param name="userAgent">The user agent value.</param>
/// <returns>Response of the server or stream of error message as string started with 'ERROR:' keyword.</returns>
public static Stream SendRequest(byte[] request, string userAgent)
{
return SendRequestAsync(request, userAgent, CancellationToken.None).Result;
}
public static async Task<Stream> SendRequestAsync(byte[] request, string userAgent, CancellationToken cancellationToken)
{
var options = new HttpRequestOptions
{
RequestContentBytes = request,
RequestContentType = "text/xml",
UserAgent = userAgent,
Host = HostHeader,
Url = XML_RPC_SERVER,
// Response parsing will fail with this enabled
EnableHttpCompression = false,
CancellationToken = cancellationToken,
BufferContent = false
};
if (string.IsNullOrEmpty(options.UserAgent))
{
options.UserAgent = "xmlrpc-epi-php/0.2 (PHP)";
}
var result = await HttpClient.Post(options).ConfigureAwait(false);
return result.Content;
}
}
}

@ -1,225 +0,0 @@
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
<?xml version="1.0"?>
<methodCall>
<methodName>examples.getStateName</methodName>
<params>
<param>
<value>
<i4>41</i4>
</value>
</param>
</params>
</methodCall>
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 <methodCall> structure.
The <methodCall> must contain a <methodName> 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 <methodCall> must contain a <params> sub-item. The <params> sub-item can contain any number of <param>s, each of which has a <value>.
Scalar <value>s
<value>s can be scalars, type is indicated by nesting the value inside one of the tags listed in this table:
Tag Type Example
<i4> or <int> four-byte signed integer -12
<boolean> 0 (false) or 1 (true) 1
<string> string hello world
<double> double-precision signed floating point number -12.214
<dateTime.iso8601> date/time 19980717T14:08:55
<base64> base64-encoded binary eW91IGNhbid0IHJlYWQgdGhpcyE=
If no type is indicated, the type is string.
<struct>s
A value can also be of type <struct>.
A <struct> contains <member>s and each <member> contains a <name> and a <value>.
Here's an example of a two-element <struct>:
<struct>
<member>
<name>lowerBound</name>
<value><i4>18</i4></value>
</member>
<member>
<name>upperBound</name>
<value><i4>139</i4></value>
</member>
</struct>
<struct>s can be recursive, any <value> may contain a <struct> or any other type, including an <array>, described below.
<array>s
A value can also be of type <array>.
An <array> contains a single <data> element, which can contain any number of <value>s.
Here's an example of a four-element array:
<array>
<data>
<value><i4>12</i4></value>
<value><string>Egypt</string></value>
<value><boolean>0</boolean></value>
<value><i4>-31</i4></value>
</data>
</array>
<array> elements do not have names.
You can mix types as the example above illustrates.
<arrays>s can be recursive, any value may contain an <array> or any other type, including a <struct>, 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
<?xml version="1.0"?> <methodResponse> <params> <param> <value><string>South Dakota</string></value> </param> </params> </methodResponse>
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 <methodResponse>, which can contain a single <params> which contains a single <param> which contains a single <value>.
The <methodResponse> could also contain a <fault> which contains a <value> which is a <struct> containing two elements, one named <faultCode>, an <int> and one named <faultString>, a <string>.
A <methodResponse> can not contain both a <fault> and a <params>.
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
<?xml version="1.0"?> <methodResponse> <fault> <value> <struct> <member> <name>faultCode</name> <value><int>4</int></value> </member> <member> <name>faultString</name> <value><string>Too many parameters.</string></value> </member> </struct> </value> </fault> </methodResponse>
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 <methodResponse>, which can contain a single <params>..." This is confusing. Can we leave out the <params>?
No you cannot leave it out if the procedure executed successfully. There are only two options, either a response contains a <params> structure or it contains a <fault> 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 &lt; and &amp;. 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 <fault> struct contain other members than <faultCode> and <faultString>? Is there a global list of faultCodes? (so they can be mapped to distinct exceptions for languages like Python and Java)?
A <fault> 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
<base64> 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.

@ -1,25 +0,0 @@
/* 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 <http://www.gnu.org/licenses/>.
*/
namespace XmlRpcHandler
{
public enum XmlRpcBasicValueType
{
String, Int, Boolean, Double, dateTime_iso8601, base64
}
}

@ -1,63 +0,0 @@
/* 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 <http://www.gnu.org/licenses/>.
*/
using System.Collections.Generic;
namespace XmlRpcHandler
{
/// <summary>
/// A method call
/// </summary>
public struct XmlRpcMethodCall
{
/// <summary>
/// A method call
/// </summary>
/// <param name="name">The name of this method</param>
public XmlRpcMethodCall(string name)
{
this.name = name;
this.parameters = new List<IXmlRpcValue>();
}
/// <summary>
/// A method call
/// </summary>
/// <param name="name">The name of this method</param>
/// <param name="parameters">A list of parameters</param>
public XmlRpcMethodCall(string name, List<IXmlRpcValue> parameters)
{
this.name = name;
this.parameters = parameters;
}
private string name;
private List<IXmlRpcValue> parameters;
/// <summary>
/// Get or set the name of this method
/// </summary>
public string Name
{ get { return name; } set { name = value; } }
/// <summary>
/// Get or set the parameters to be sent
/// </summary>
public List<IXmlRpcValue> Parameters
{ get { return parameters; } set { parameters = value; } }
}
}

@ -1,36 +0,0 @@
/* 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 <http://www.gnu.org/licenses/>.
*/
namespace XmlRpcHandler
{
public abstract class IXmlRpcValue
{
public IXmlRpcValue()
{ }
public IXmlRpcValue(object data)
{
this.data = data;
}
private object data;
/// <summary>
/// Get or set the data of this value
/// </summary>
public virtual object Data { get { return data; } set { data = value; } }
}
}

@ -1,43 +0,0 @@
/* 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 <http://www.gnu.org/licenses/>.
*/
namespace XmlRpcHandler
{
public class XmlRpcStructMember
{
public XmlRpcStructMember(string name, IXmlRpcValue data)
{
this.name = name;
this.data = data;
}
private string name;
private IXmlRpcValue data;
/// <summary>
/// Get or set the name of this member
/// </summary>
public string Name
{ get { return name; } set { name = value; } }
/// <summary>
/// Get or set the data of this member
/// </summary>
public IXmlRpcValue Data
{ get { return data; } set { data = value; } }
}
}

@ -1,121 +0,0 @@
/* 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 <http://www.gnu.org/licenses/>.
*/
using System;
using System.Collections.Generic;
namespace XmlRpcHandler
{
public class XmlRpcValueArray : IXmlRpcValue
{
public XmlRpcValueArray() :
base()
{
values = new List<IXmlRpcValue>();
}
public XmlRpcValueArray(object data) :
base(data)
{
values = new List<IXmlRpcValue>();
}
public XmlRpcValueArray(string[] texts) :
base()
{
values = new List<IXmlRpcValue>();
foreach (string val in texts)
{
values.Add(new XmlRpcValueBasic(val));
}
}
public XmlRpcValueArray(int[] ints) :
base()
{
values = new List<IXmlRpcValue>();
foreach (int val in ints)
{
values.Add(new XmlRpcValueBasic(val));
}
}
public XmlRpcValueArray(double[] doubles) :
base()
{
values = new List<IXmlRpcValue>();
foreach (double val in doubles)
{
values.Add(new XmlRpcValueBasic(val));
}
}
public XmlRpcValueArray(bool[] bools) :
base()
{
values = new List<IXmlRpcValue>();
foreach (bool val in bools)
{
values.Add(new XmlRpcValueBasic(val));
}
}
public XmlRpcValueArray(long[] base24s) :
base()
{
values = new List<IXmlRpcValue>();
foreach (long val in base24s)
{
values.Add(new XmlRpcValueBasic(val));
}
}
public XmlRpcValueArray(DateTime[] dates) :
base()
{
values = new List<IXmlRpcValue>();
foreach (var val in dates)
{
values.Add(new XmlRpcValueBasic(val));
}
}
public XmlRpcValueArray(XmlRpcValueBasic[] basicValues) :
base()
{
values = new List<IXmlRpcValue>();
foreach (var val in basicValues)
{
values.Add(val);
}
}
public XmlRpcValueArray(XmlRpcValueStruct[] structs) :
base()
{
values = new List<IXmlRpcValue>();
foreach (var val in structs)
{
values.Add(val);
}
}
public XmlRpcValueArray(XmlRpcValueArray[] arrays) :
base()
{
values = new List<IXmlRpcValue>();
foreach (var val in arrays)
{
values.Add(val);
}
}
private List<IXmlRpcValue> values;
public List<IXmlRpcValue> Values { get { return values; } set { values = value; } }
}
}

@ -1,99 +0,0 @@
/* 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 <http://www.gnu.org/licenses/>.
*/
using System;
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;
/// <summary>
/// Get or set the type of this basic value
/// </summary>
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.");
}
}
}

@ -1,43 +0,0 @@
/* 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 <http://www.gnu.org/licenses/>.
*/
using System.Collections.Generic;
namespace XmlRpcHandler
{
/// <summary>
/// Represents XML-RPC struct
/// </summary>
public class XmlRpcValueStruct : IXmlRpcValue
{
/// <summary>
/// Represents XML-RPC struct
/// </summary>
/// <param name="members"></param>
public XmlRpcValueStruct(List<XmlRpcStructMember> members)
{ this.members = members; }
private List<XmlRpcStructMember> members;
/// <summary>
/// Get or set the members collection
/// </summary>
public List<XmlRpcStructMember> Members
{ get { return members; } set { members = value; } }
}
}

@ -1,350 +0,0 @@
/* 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 <http://www.gnu.org/licenses/>.
*/
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Text;
using System.Xml;
using OpenSubtitlesHandler;
namespace XmlRpcHandler
{
/// <summary>
/// A class for making XML-RPC requests. The requests then can be sent directly as http request.
/// </summary>
public class XmlRpcGenerator
{
/// <summary>
/// Generate XML-RPC request using method call.
/// </summary>
/// <param name="method">The method call</param>
/// <returns>The request in xml.</returns>
public static byte[] Generate(XmlRpcMethodCall method)
{ return Generate(new XmlRpcMethodCall[] { method }); }
/// <summary>
/// Generate XML-RPC request using method calls array.
/// </summary>
/// <param name="methods">The method calls array</param>
/// <returns>The request in utf8 xml string as buffer</returns>
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
var sett = new XmlWriterSettings();
sett.Indent = true;
sett.Encoding = Encoding.UTF8;
using (var ms = new MemoryStream())
{
using (var XMLwrt = XmlWriter.Create(ms, 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();
return ms.ToArray();
}
}
}
/// <summary>
/// Decode response then return the values
/// </summary>
/// <param name="xmlResponse">The response xml string as provided by server as methodResponse</param>
/// <returns></returns>
public static XmlRpcMethodCall[] DecodeMethodResponse(string xmlResponse)
{
var methods = new List<XmlRpcMethodCall>();
var sett = new XmlReaderSettings();
sett.DtdProcessing = DtdProcessing.Ignore;
sett.IgnoreWhitespace = true;
MemoryStream str;
if (xmlResponse.Contains(@"encoding=""utf-8"""))
{
str = new MemoryStream(Encoding.UTF8.GetBytes(xmlResponse));
}
else
{
str = new MemoryStream(Utilities.GetASCIIBytes(xmlResponse));
}
using (str)
{
using (var XMLread = XmlReader.Create(str, sett))
{
var 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);
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)
{
var 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 readonly CultureInfo UsCulture = new CultureInfo("en-US");
private static string ReadString(XmlReader reader)
{
if (reader.NodeType == XmlNodeType.Element)
{
return reader.ReadElementContentAsString();
}
return reader.ReadContentAsString();
}
private static IXmlRpcValue ReadValue(XmlReader xmlReader, bool skipRead = false)
{
while (skipRead || xmlReader.Read())
{
if (xmlReader.Name == "value" && xmlReader.IsStartElement())
{
xmlReader.Read();
if (xmlReader.Name == "string" && xmlReader.IsStartElement())
{
return new XmlRpcValueBasic(ReadString(xmlReader), XmlRpcBasicValueType.String);
}
else if (xmlReader.Name == "int" && xmlReader.IsStartElement())
{
return new XmlRpcValueBasic(int.Parse(ReadString(xmlReader), UsCulture), XmlRpcBasicValueType.Int);
}
else if (xmlReader.Name == "boolean" && xmlReader.IsStartElement())
{
return new XmlRpcValueBasic(ReadString(xmlReader) == "1", XmlRpcBasicValueType.Boolean);
}
else if (xmlReader.Name == "double" && xmlReader.IsStartElement())
{
return new XmlRpcValueBasic(double.Parse(ReadString(xmlReader), UsCulture), XmlRpcBasicValueType.Double);
}
else if (xmlReader.Name == "dateTime.iso8601" && xmlReader.IsStartElement())
{
string date = ReadString(xmlReader);
int year = int.Parse(date.Substring(0, 4), UsCulture);
int month = int.Parse(date.Substring(4, 2), UsCulture);
int day = int.Parse(date.Substring(6, 2), UsCulture);
int hour = int.Parse(date.Substring(9, 2), UsCulture);
int minute = int.Parse(date.Substring(12, 2), UsCulture);//19980717T14:08:55
int sec = int.Parse(date.Substring(15, 2), UsCulture);
var 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(ReadString(xmlReader)), 0)
, XmlRpcBasicValueType.Double);
}
else if (xmlReader.Name == "struct" && xmlReader.IsStartElement())
{
var strct = new XmlRpcValueStruct(new List<XmlRpcStructMember>());
// Read members...
while (xmlReader.Read())
{
if (xmlReader.Name == "member" && xmlReader.IsStartElement())
{
var member = new XmlRpcStructMember("", null);
xmlReader.Read();// read name
member.Name = ReadString(xmlReader);
IXmlRpcValue val = ReadValue(xmlReader, true);
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())
{
var 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;
if (skipRead)
{
return null;
}
}
return null;
}
}
}
Loading…
Cancel
Save