2019-01-13 20:03:10 +00:00
/ * This file is part of OpenSubtitles Handler
2014-05-05 04:36:45 +00:00
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 ;
2019-01-13 19:27:11 +00:00
using System.Globalization ;
2014-05-05 04:36:45 +00:00
using System.IO ;
2019-01-13 19:27:11 +00:00
using System.Text ;
2014-05-07 02:28:19 +00:00
using System.Threading ;
using System.Threading.Tasks ;
2014-05-05 04:36:45 +00:00
using OpenSubtitlesHandler.Console ;
using XmlRpcHandler ;
namespace OpenSubtitlesHandler
{
/// <summary>
/// The core of the OpenSubtitles Handler library. All members are static.
/// </summary>
public sealed class OpenSubtitles
{
private static string XML_PRC_USERAGENT = "" ;
// This is session id after log in, important value and MUST be set by LogIn before any other call.
private static string TOKEN = "" ;
/// <summary>
/// Set the useragent value. This must be called before doing anything else.
/// </summary>
/// <param name="agent">The useragent value</param>
public static void SetUserAgent ( string agent )
{
XML_PRC_USERAGENT = agent ;
}
/*Session handling*/
/// <summary>
/// Send a LogIn request, this must be called before anything else in this class.
/// </summary>
/// <param name="userName">The user name of OpenSubtitles</param>
/// <param name="password">The password</param>
/// <param name="language">The language, usally en</param>
/// <returns>Status of the login operation</returns>
public static IMethodResponse LogIn ( string userName , string password , string language )
{
// Method call ..
2019-01-13 20:37:13 +00:00
var parms = new List < IXmlRpcValue > ( ) ;
2014-05-05 04:36:45 +00:00
parms . Add ( new XmlRpcValueBasic ( userName ) ) ;
parms . Add ( new XmlRpcValueBasic ( password ) ) ;
parms . Add ( new XmlRpcValueBasic ( language ) ) ;
parms . Add ( new XmlRpcValueBasic ( XML_PRC_USERAGENT ) ) ;
2019-01-13 20:37:13 +00:00
var call = new XmlRpcMethodCall ( "LogIn" , parms ) ;
2014-05-05 04:36:45 +00:00
OSHConsole . WriteLine ( "Sending LogIn request to the server ..." , DebugCode . Good ) ;
//File.WriteAllText(".\\request.txt", Encoding.UTF8.GetString(XmlRpcGenerator.Generate(call)));
// Send the request to the server
string response = Utilities . GetStreamString ( Utilities . SendRequest ( XmlRpcGenerator . Generate ( call ) , XML_PRC_USERAGENT ) ) ;
if ( ! response . Contains ( "ERROR:" ) )
{
// No error occur, get and decode the response. We expect Struct here.
XmlRpcMethodCall [ ] calls = XmlRpcGenerator . DecodeMethodResponse ( response ) ;
if ( calls . Length > 0 )
{
if ( calls [ 0 ] . Parameters . Count > 0 )
{
2019-01-13 20:37:13 +00:00
var mainStruct = ( XmlRpcValueStruct ) calls [ 0 ] . Parameters [ 0 ] ;
var re = new MethodResponseLogIn ( "Success" , "Log in successful." ) ;
2019-01-18 15:48:01 +00:00
foreach ( XmlRpcStructMember MEMBER in mainStruct . Members )
2014-05-05 04:36:45 +00:00
{
switch ( MEMBER . Name )
{
case "token" : re . Token = TOKEN = MEMBER . Data . Data . ToString ( ) ; OSHConsole . WriteLine ( MEMBER . Name + "= " + MEMBER . Data . Data . ToString ( ) ) ; break ;
case "seconds" : re . Seconds = ( double ) MEMBER . Data . Data ; OSHConsole . WriteLine ( MEMBER . Name + "= " + MEMBER . Data . Data . ToString ( ) ) ; break ;
case "status" : re . Status = MEMBER . Data . Data . ToString ( ) ; OSHConsole . WriteLine ( MEMBER . Name + "= " + MEMBER . Data . Data . ToString ( ) ) ; break ;
}
}
return re ;
}
}
}
else
{
OSHConsole . WriteLine ( response , DebugCode . Error ) ;
return new MethodResponseError ( "Fail" , response ) ;
}
return new MethodResponseError ( "Fail" , "Log in failed !" ) ;
}
2014-05-07 02:28:19 +00:00
public static async Task < IMethodResponse > LogInAsync ( string userName , string password , string language , CancellationToken cancellationToken )
{
// Method call ..
2019-01-13 20:37:13 +00:00
var parms = new List < IXmlRpcValue > ( ) ;
2014-05-07 02:28:19 +00:00
parms . Add ( new XmlRpcValueBasic ( userName ) ) ;
parms . Add ( new XmlRpcValueBasic ( password ) ) ;
parms . Add ( new XmlRpcValueBasic ( language ) ) ;
parms . Add ( new XmlRpcValueBasic ( XML_PRC_USERAGENT ) ) ;
2019-01-13 20:37:13 +00:00
var call = new XmlRpcMethodCall ( "LogIn" , parms ) ;
2014-05-07 02:28:19 +00:00
OSHConsole . WriteLine ( "Sending LogIn request to the server ..." , DebugCode . Good ) ;
//File.WriteAllText(".\\request.txt", Encoding.UTF8.GetString(XmlRpcGenerator.Generate(call)));
// Send the request to the server
var stream = await Utilities . SendRequestAsync ( XmlRpcGenerator . Generate ( call ) , XML_PRC_USERAGENT , cancellationToken )
. ConfigureAwait ( false ) ;
string response = Utilities . GetStreamString ( stream ) ;
if ( ! response . Contains ( "ERROR:" ) )
{
// No error occur, get and decode the response. We expect Struct here.
XmlRpcMethodCall [ ] calls = XmlRpcGenerator . DecodeMethodResponse ( response ) ;
if ( calls . Length > 0 )
{
if ( calls [ 0 ] . Parameters . Count > 0 )
{
2019-01-13 20:37:13 +00:00
var mainStruct = ( XmlRpcValueStruct ) calls [ 0 ] . Parameters [ 0 ] ;
var re = new MethodResponseLogIn ( "Success" , "Log in successful." ) ;
2019-01-18 15:48:01 +00:00
foreach ( XmlRpcStructMember MEMBER in mainStruct . Members )
2014-05-07 02:28:19 +00:00
{
switch ( MEMBER . Name )
{
2019-01-07 23:27:46 +00:00
case "token" :
re . Token = TOKEN = MEMBER . Data . Data . ToString ( ) ;
OSHConsole . WriteLine ( MEMBER . Name + "= " + MEMBER . Data . Data . ToString ( ) ) ;
2014-10-12 01:46:02 +00:00
break ;
case "seconds" :
re . Seconds = double . Parse ( MEMBER . Data . Data . ToString ( ) , CultureInfo . InvariantCulture ) ;
2019-01-07 23:27:46 +00:00
OSHConsole . WriteLine ( MEMBER . Name + "= " + MEMBER . Data . Data . ToString ( ) ) ;
2014-10-12 01:46:02 +00:00
break ;
2019-01-07 23:27:46 +00:00
case "status" :
re . Status = MEMBER . Data . Data . ToString ( ) ;
OSHConsole . WriteLine ( MEMBER . Name + "= " + MEMBER . Data . Data . ToString ( ) ) ;
2014-10-12 01:46:02 +00:00
break ;
2014-05-07 02:28:19 +00:00
}
}
return re ;
}
}
}
else
{
OSHConsole . WriteLine ( response , DebugCode . Error ) ;
return new MethodResponseError ( "Fail" , response ) ;
}
return new MethodResponseError ( "Fail" , "Log in failed !" ) ;
}
2019-01-07 23:27:46 +00:00
2014-05-05 04:36:45 +00:00
/// <summary>
/// Log out from the server. Call this to terminate the session.
/// </summary>
/// <returns></returns>
public static IMethodResponse LogOut ( )
{
if ( TOKEN = = "" )
{
OSHConsole . WriteLine ( "Can't do this call, 'token' value not set. Please use Log In method first." , DebugCode . Error ) ;
return new MethodResponseError ( "Fail" , "Can't do this call, 'token' value not set. Please use Log In method first." ) ;
}
// Method call ..
2019-01-13 20:37:13 +00:00
var parms = new List < IXmlRpcValue > ( ) ;
2014-05-05 04:36:45 +00:00
parms . Add ( new XmlRpcValueBasic ( TOKEN , XmlRpcBasicValueType . String ) ) ;
2019-01-13 20:37:13 +00:00
var call = new XmlRpcMethodCall ( "LogOut" , parms ) ;
2014-05-05 04:36:45 +00:00
OSHConsole . WriteLine ( "Sending LogOut request to the server ..." , DebugCode . Good ) ;
// Send the request to the server
string response = Utilities . GetStreamString ( Utilities . SendRequest ( XmlRpcGenerator . Generate ( call ) , XML_PRC_USERAGENT ) ) ;
if ( ! response . Contains ( "ERROR:" ) )
{
// No error occur, get and decode the response. We expect Struct here.
XmlRpcMethodCall [ ] calls = XmlRpcGenerator . DecodeMethodResponse ( response ) ;
if ( calls . Length > 0 )
{
if ( calls [ 0 ] . Parameters . Count > 0 )
{
2019-01-13 20:37:13 +00:00
var strct = ( XmlRpcValueStruct ) calls [ 0 ] . Parameters [ 0 ] ;
2014-05-05 04:36:45 +00:00
OSHConsole . WriteLine ( "STATUS=" + ( ( XmlRpcValueBasic ) strct . Members [ 0 ] . Data ) . Data . ToString ( ) ) ;
OSHConsole . WriteLine ( "SECONDS=" + ( ( XmlRpcValueBasic ) strct . Members [ 1 ] . Data ) . Data . ToString ( ) ) ;
2019-01-13 20:37:13 +00:00
var re = new MethodResponseLogIn ( "Success" , "Log out successful." ) ;
2014-05-05 04:36:45 +00:00
re . Status = ( ( XmlRpcValueBasic ) strct . Members [ 0 ] . Data ) . Data . ToString ( ) ;
re . Seconds = ( double ) ( ( XmlRpcValueBasic ) strct . Members [ 1 ] . Data ) . Data ;
return re ;
}
}
}
else
{
OSHConsole . WriteLine ( response , DebugCode . Error ) ;
return new MethodResponseError ( "Fail" , response ) ;
}
return new MethodResponseError ( "Fail" , "Log out failed !" ) ;
}
/// <summary>
2019-01-07 23:27:46 +00:00
/// keep-alive user's session, verify token/session validity
2014-05-05 04:36:45 +00:00
/// </summary>
/// <returns>Status of the call operation</returns>
public static IMethodResponse NoOperation ( )
{
if ( TOKEN = = "" )
{
OSHConsole . WriteLine ( "Can't do this call, 'token' value not set. Please use Log In method first." , DebugCode . Error ) ;
return new MethodResponseError ( "Fail" , "Can't do this call, 'token' value not set. Please use Log In method first." ) ;
}
// Method call ..
2019-01-13 20:37:13 +00:00
var parms = new List < IXmlRpcValue > ( ) ;
2014-05-05 04:36:45 +00:00
parms . Add ( new XmlRpcValueBasic ( TOKEN , XmlRpcBasicValueType . String ) ) ;
parms . Add ( new XmlRpcValueBasic ( XML_PRC_USERAGENT , XmlRpcBasicValueType . String ) ) ;
2019-01-13 20:37:13 +00:00
var call = new XmlRpcMethodCall ( "NoOperation" , parms ) ;
2014-05-05 04:36:45 +00:00
OSHConsole . WriteLine ( "Sending NoOperation request to the server ..." , DebugCode . Good ) ;
// Send the request to the server
string response = Utilities . GetStreamString ( Utilities . SendRequest ( XmlRpcGenerator . Generate ( call ) , XML_PRC_USERAGENT ) ) ;
if ( ! response . Contains ( "ERROR:" ) )
{
// No error occur, get and decode the response. We expect Struct here.
XmlRpcMethodCall [ ] calls = XmlRpcGenerator . DecodeMethodResponse ( response ) ;
if ( calls . Length > 0 )
{
if ( calls [ 0 ] . Parameters . Count > 0 )
{
2019-01-13 20:37:13 +00:00
var R = new MethodResponseNoOperation ( ) ;
var mainStruct = ( XmlRpcValueStruct ) calls [ 0 ] . Parameters [ 0 ] ;
2014-05-05 04:36:45 +00:00
// To make sure response is not currepted by server, do it in loop
2019-01-18 15:48:01 +00:00
foreach ( XmlRpcStructMember MEMBER in mainStruct . Members )
2014-05-05 04:36:45 +00:00
{
switch ( MEMBER . Name )
{
case "status" : R . Status = ( string ) MEMBER . Data . Data ; OSHConsole . WriteLine ( MEMBER . Name + "= " + MEMBER . Data . Data ) ; break ;
case "seconds" : R . Seconds = ( double ) MEMBER . Data . Data ; OSHConsole . WriteLine ( MEMBER . Name + "= " + MEMBER . Data . Data ) ; break ;
case "download_limits" :
2019-01-13 20:37:13 +00:00
var dlStruct = ( XmlRpcValueStruct ) MEMBER . Data ;
2019-01-18 15:48:01 +00:00
foreach ( XmlRpcStructMember dlmember in dlStruct . Members )
2014-05-05 04:36:45 +00:00
{
OSHConsole . WriteLine ( " >" + dlmember . Name + "= " + dlmember . Data . Data . ToString ( ) ) ;
switch ( dlmember . Name )
{
case "global_wrh_download_limit" : R . global_wrh_download_limit = dlmember . Data . Data . ToString ( ) ; break ;
case "client_ip" : R . client_ip = dlmember . Data . Data . ToString ( ) ; break ;
case "limit_check_by" : R . limit_check_by = dlmember . Data . Data . ToString ( ) ; break ;
case "client_24h_download_count" : R . client_24h_download_count = dlmember . Data . Data . ToString ( ) ; break ;
case "client_downlaod_quota" : R . client_downlaod_quota = dlmember . Data . Data . ToString ( ) ; break ;
case "client_24h_download_limit" : R . client_24h_download_limit = dlmember . Data . Data . ToString ( ) ; break ;
}
}
break ;
}
}
return R ;
}
}
}
else
{
OSHConsole . WriteLine ( response , DebugCode . Error ) ;
return new MethodResponseError ( "Fail" , response ) ;
}
return new MethodResponseError ( "Fail" , "NoOperation call failed !" ) ;
}
/*Search and download*/
/// <summary>
2019-01-07 23:27:46 +00:00
/// Search for subtitle files matching your videos using either video file hashes or IMDb IDs.
2014-05-05 04:36:45 +00:00
/// </summary>
/// <param name="parameters">List of search subtitle parameters which each one represents 'struct parameter' as descriped at http://trac.opensubtitles.org/projects/opensubtitles/wiki/XmlRpcSearchSubtitles </param>
/// <returns>Status of the call operation. If the call success the response will be 'MethodResponseSubtitleSearch'</returns>
public static IMethodResponse SearchSubtitles ( SubtitleSearchParameters [ ] parameters )
{
if ( TOKEN = = "" )
{
OSHConsole . WriteLine ( "Can't do this call, 'token' value not set. Please use Log In method first." , DebugCode . Error ) ;
return new MethodResponseError ( "Fail" , "Can't do this call, 'token' value not set. Please use Log In method first." ) ;
}
if ( parameters = = null )
{
OSHConsole . UpdateLine ( "No subtitle search parameter passed !!" , DebugCode . Error ) ;
2019-01-06 20:50:43 +00:00
return new MethodResponseError ( "Fail" , "No subtitle search parameter passed" ) ;
2014-05-05 04:36:45 +00:00
}
if ( parameters . Length = = 0 )
{
OSHConsole . UpdateLine ( "No subtitle search parameter passed !!" , DebugCode . Error ) ;
2019-01-06 20:50:43 +00:00
return new MethodResponseError ( "Fail" , "No subtitle search parameter passed" ) ;
2014-05-05 04:36:45 +00:00
}
// Method call ..
2019-01-13 20:37:13 +00:00
var parms = new List < IXmlRpcValue > ( ) ;
2014-05-05 04:36:45 +00:00
// Add token param
parms . Add ( new XmlRpcValueBasic ( TOKEN , XmlRpcBasicValueType . String ) ) ;
// Add subtitle search parameters. Each one will be like 'array' of structs.
2019-01-13 20:37:13 +00:00
var array = new XmlRpcValueArray ( ) ;
2019-01-18 15:48:01 +00:00
foreach ( SubtitleSearchParameters param in parameters )
2014-05-05 04:36:45 +00:00
{
2019-01-13 20:37:13 +00:00
var strct = new XmlRpcValueStruct ( new List < XmlRpcStructMember > ( ) ) ;
2014-05-05 04:36:45 +00:00
// sublanguageid member
2019-01-13 20:37:13 +00:00
var member = new XmlRpcStructMember ( "sublanguageid" ,
2014-05-05 04:36:45 +00:00
new XmlRpcValueBasic ( param . SubLangaugeID , XmlRpcBasicValueType . String ) ) ;
strct . Members . Add ( member ) ;
// moviehash member
2019-01-13 19:27:11 +00:00
if ( param . MovieHash . Length > 0 & & param . MovieByteSize > 0 )
{
2014-05-05 04:36:45 +00:00
member = new XmlRpcStructMember ( "moviehash" ,
new XmlRpcValueBasic ( param . MovieHash , XmlRpcBasicValueType . String ) ) ;
strct . Members . Add ( member ) ;
// moviehash member
member = new XmlRpcStructMember ( "moviebytesize" ,
new XmlRpcValueBasic ( param . MovieByteSize , XmlRpcBasicValueType . Int ) ) ;
strct . Members . Add ( member ) ;
}
2019-01-13 19:27:11 +00:00
if ( param . Query . Length > 0 )
{
2014-05-05 04:36:45 +00:00
member = new XmlRpcStructMember ( "query" ,
new XmlRpcValueBasic ( param . Query , XmlRpcBasicValueType . String ) ) ;
strct . Members . Add ( member ) ;
}
2019-01-13 19:27:11 +00:00
if ( param . Episode . Length > 0 & & param . Season . Length > 0 )
{
member = new XmlRpcStructMember ( "season" ,
new XmlRpcValueBasic ( param . Season , XmlRpcBasicValueType . String ) ) ;
strct . Members . Add ( member ) ;
member = new XmlRpcStructMember ( "episode" ,
new XmlRpcValueBasic ( param . Episode , XmlRpcBasicValueType . String ) ) ;
strct . Members . Add ( member ) ;
2014-05-05 04:36:45 +00:00
}
// imdbid member
if ( param . IMDbID . Length > 0 )
{
member = new XmlRpcStructMember ( "imdbid" ,
new XmlRpcValueBasic ( param . IMDbID , XmlRpcBasicValueType . String ) ) ;
strct . Members . Add ( member ) ;
}
// Add the struct to the array
array . Values . Add ( strct ) ;
}
// Add the array to the parameters
parms . Add ( array ) ;
// Call !
2019-01-13 20:37:13 +00:00
var call = new XmlRpcMethodCall ( "SearchSubtitles" , parms ) ;
2014-05-05 04:36:45 +00:00
OSHConsole . WriteLine ( "Sending SearchSubtitles request to the server ..." , DebugCode . Good ) ;
// Send the request to the server
string response = Utilities . GetStreamString ( Utilities . SendRequest ( XmlRpcGenerator . Generate ( call ) , XML_PRC_USERAGENT ) ) ;
if ( ! response . Contains ( "ERROR:" ) )
{
2019-01-07 23:27:46 +00:00
// No error occur, get and decode the response.
2014-05-05 04:36:45 +00:00
XmlRpcMethodCall [ ] calls = XmlRpcGenerator . DecodeMethodResponse ( response ) ;
if ( calls . Length > 0 )
{
if ( calls [ 0 ] . Parameters . Count > 0 )
{
// We expect Struct of 3 members:
//* the first is status
//* the second is [array of structs, each one includes subtitle file].
//* the third is [double basic value] represent seconds token by server.
2019-01-13 20:37:13 +00:00
var mainStruct = ( XmlRpcValueStruct ) calls [ 0 ] . Parameters [ 0 ] ;
2014-05-05 04:36:45 +00:00
// Create the response, we'll need it later
2019-01-13 20:37:13 +00:00
var R = new MethodResponseSubtitleSearch ( ) ;
2014-05-05 04:36:45 +00:00
// To make sure response is not currepted by server, do it in loop
2019-01-18 15:48:01 +00:00
foreach ( XmlRpcStructMember MEMBER in mainStruct . Members )
2014-05-05 04:36:45 +00:00
{
if ( MEMBER . Name = = "status" )
{
R . Status = ( string ) MEMBER . Data . Data ;
OSHConsole . WriteLine ( "Status= " + R . Status ) ;
}
else if ( MEMBER . Name = = "seconds" )
{
R . Seconds = ( double ) MEMBER . Data . Data ;
OSHConsole . WriteLine ( "Seconds= " + R . Seconds ) ;
}
else if ( MEMBER . Name = = "data" )
{
if ( MEMBER . Data is XmlRpcValueArray )
{
OSHConsole . WriteLine ( "Search results: " ) ;
2019-01-13 20:37:13 +00:00
var rarray = ( XmlRpcValueArray ) MEMBER . Data ;
2019-01-18 15:48:01 +00:00
foreach ( IXmlRpcValue subStruct in rarray . Values )
2014-05-05 04:36:45 +00:00
{
if ( subStruct = = null ) continue ;
if ( ! ( subStruct is XmlRpcValueStruct ) ) continue ;
2019-01-13 20:37:13 +00:00
var result = new SubtitleSearchResult ( ) ;
2019-01-18 15:48:01 +00:00
foreach ( XmlRpcStructMember submember in ( ( XmlRpcValueStruct ) subStruct ) . Members )
2014-05-05 04:36:45 +00:00
{
// To avoid errors of arranged info or missing ones, let's do it with switch..
switch ( submember . Name )
{
case "IDMovie" : result . IDMovie = submember . Data . Data . ToString ( ) ; break ;
case "IDMovieImdb" : result . IDMovieImdb = submember . Data . Data . ToString ( ) ; break ;
case "IDSubMovieFile" : result . IDSubMovieFile = submember . Data . Data . ToString ( ) ; break ;
case "IDSubtitle" : result . IDSubtitle = submember . Data . Data . ToString ( ) ; break ;
case "IDSubtitleFile" : result . IDSubtitleFile = submember . Data . Data . ToString ( ) ; break ;
case "ISO639" : result . ISO639 = submember . Data . Data . ToString ( ) ; break ;
case "LanguageName" : result . LanguageName = submember . Data . Data . ToString ( ) ; break ;
case "MovieByteSize" : result . MovieByteSize = submember . Data . Data . ToString ( ) ; break ;
case "MovieHash" : result . MovieHash = submember . Data . Data . ToString ( ) ; break ;
case "MovieImdbRating" : result . MovieImdbRating = submember . Data . Data . ToString ( ) ; break ;
case "MovieName" : result . MovieName = submember . Data . Data . ToString ( ) ; break ;
case "MovieNameEng" : result . MovieNameEng = submember . Data . Data . ToString ( ) ; break ;
case "MovieReleaseName" : result . MovieReleaseName = submember . Data . Data . ToString ( ) ; break ;
case "MovieTimeMS" : result . MovieTimeMS = submember . Data . Data . ToString ( ) ; break ;
case "MovieYear" : result . MovieYear = submember . Data . Data . ToString ( ) ; break ;
case "SubActualCD" : result . SubActualCD = submember . Data . Data . ToString ( ) ; break ;
case "SubAddDate" : result . SubAddDate = submember . Data . Data . ToString ( ) ; break ;
case "SubAuthorComment" : result . SubAuthorComment = submember . Data . Data . ToString ( ) ; break ;
case "SubBad" : result . SubBad = submember . Data . Data . ToString ( ) ; break ;
case "SubDownloadLink" : result . SubDownloadLink = submember . Data . Data . ToString ( ) ; break ;
case "SubDownloadsCnt" : result . SubDownloadsCnt = submember . Data . Data . ToString ( ) ; break ;
case "SeriesEpisode" : result . SeriesEpisode = submember . Data . Data . ToString ( ) ; break ;
case "SeriesSeason" : result . SeriesSeason = submember . Data . Data . ToString ( ) ; break ;
case "SubFileName" : result . SubFileName = submember . Data . Data . ToString ( ) ; break ;
case "SubFormat" : result . SubFormat = submember . Data . Data . ToString ( ) ; break ;
case "SubHash" : result . SubHash = submember . Data . Data . ToString ( ) ; break ;
case "SubLanguageID" : result . SubLanguageID = submember . Data . Data . ToString ( ) ; break ;
case "SubRating" : result . SubRating = submember . Data . Data . ToString ( ) ; break ;
case "SubSize" : result . SubSize = submember . Data . Data . ToString ( ) ; break ;
case "SubSumCD" : result . SubSumCD = submember . Data . Data . ToString ( ) ; break ;
case "UserID" : result . UserID = submember . Data . Data . ToString ( ) ; break ;
case "UserNickName" : result . UserNickName = submember . Data . Data . ToString ( ) ; break ;
case "ZipDownloadLink" : result . ZipDownloadLink = submember . Data . Data . ToString ( ) ; break ;
}
}
R . Results . Add ( result ) ;
OSHConsole . WriteLine ( ">" + result . ToString ( ) ) ;
}
}
else // Unknown data ?
{
OSHConsole . WriteLine ( "Data= " + MEMBER . Data . Data . ToString ( ) , DebugCode . Warning ) ;
}
}
}
// Return the response to user !!
return R ;
}
}
}
else
{
OSHConsole . WriteLine ( response , DebugCode . Error ) ;
return new MethodResponseError ( "Fail" , response ) ;
}
return new MethodResponseError ( "Fail" , "Search Subtitles call failed !" ) ;
}
2014-05-09 04:38:12 +00:00
public static async Task < IMethodResponse > SearchSubtitlesAsync ( SubtitleSearchParameters [ ] parameters , CancellationToken cancellationToken )
{
if ( TOKEN = = "" )
{
OSHConsole . WriteLine ( "Can't do this call, 'token' value not set. Please use Log In method first." , DebugCode . Error ) ;
return new MethodResponseError ( "Fail" , "Can't do this call, 'token' value not set. Please use Log In method first." ) ;
}
if ( parameters = = null )
{
OSHConsole . UpdateLine ( "No subtitle search parameter passed !!" , DebugCode . Error ) ;
2019-01-06 20:50:43 +00:00
return new MethodResponseError ( "Fail" , "No subtitle search parameter passed" ) ;
2014-05-09 04:38:12 +00:00
}
if ( parameters . Length = = 0 )
{
OSHConsole . UpdateLine ( "No subtitle search parameter passed !!" , DebugCode . Error ) ;
2019-01-06 20:50:43 +00:00
return new MethodResponseError ( "Fail" , "No subtitle search parameter passed" ) ;
2014-05-09 04:38:12 +00:00
}
// Method call ..
2019-01-13 20:37:13 +00:00
var parms = new List < IXmlRpcValue > ( ) ;
2014-05-09 04:38:12 +00:00
// Add token param
parms . Add ( new XmlRpcValueBasic ( TOKEN , XmlRpcBasicValueType . String ) ) ;
// Add subtitle search parameters. Each one will be like 'array' of structs.
2019-01-13 20:37:13 +00:00
var array = new XmlRpcValueArray ( ) ;
2019-01-18 15:48:01 +00:00
foreach ( SubtitleSearchParameters param in parameters )
2014-05-09 04:38:12 +00:00
{
2019-01-13 20:37:13 +00:00
var strct = new XmlRpcValueStruct ( new List < XmlRpcStructMember > ( ) ) ;
2014-05-09 04:38:12 +00:00
// sublanguageid member
2019-01-13 20:37:13 +00:00
var member = new XmlRpcStructMember ( "sublanguageid" ,
2014-05-09 04:38:12 +00:00
new XmlRpcValueBasic ( param . SubLangaugeID , XmlRpcBasicValueType . String ) ) ;
strct . Members . Add ( member ) ;
// moviehash member
if ( param . MovieHash . Length > 0 & & param . MovieByteSize > 0 )
{
member = new XmlRpcStructMember ( "moviehash" ,
new XmlRpcValueBasic ( param . MovieHash , XmlRpcBasicValueType . String ) ) ;
strct . Members . Add ( member ) ;
// moviehash member
member = new XmlRpcStructMember ( "moviebytesize" ,
new XmlRpcValueBasic ( param . MovieByteSize , XmlRpcBasicValueType . Int ) ) ;
strct . Members . Add ( member ) ;
}
if ( param . Query . Length > 0 )
{
member = new XmlRpcStructMember ( "query" ,
new XmlRpcValueBasic ( param . Query , XmlRpcBasicValueType . String ) ) ;
strct . Members . Add ( member ) ;
}
if ( param . Episode . Length > 0 & & param . Season . Length > 0 )
{
member = new XmlRpcStructMember ( "season" ,
new XmlRpcValueBasic ( param . Season , XmlRpcBasicValueType . String ) ) ;
strct . Members . Add ( member ) ;
member = new XmlRpcStructMember ( "episode" ,
new XmlRpcValueBasic ( param . Episode , XmlRpcBasicValueType . String ) ) ;
strct . Members . Add ( member ) ;
}
// imdbid member
if ( param . IMDbID . Length > 0 )
{
member = new XmlRpcStructMember ( "imdbid" ,
new XmlRpcValueBasic ( param . IMDbID , XmlRpcBasicValueType . String ) ) ;
strct . Members . Add ( member ) ;
}
// Add the struct to the array
array . Values . Add ( strct ) ;
}
// Add the array to the parameters
parms . Add ( array ) ;
// Call !
2019-01-13 20:37:13 +00:00
var call = new XmlRpcMethodCall ( "SearchSubtitles" , parms ) ;
2014-05-09 04:38:12 +00:00
OSHConsole . WriteLine ( "Sending SearchSubtitles request to the server ..." , DebugCode . Good ) ;
// Send the request to the server
string response = Utilities . GetStreamString ( await Utilities . SendRequestAsync ( XmlRpcGenerator . Generate ( call ) , XML_PRC_USERAGENT , cancellationToken ) . ConfigureAwait ( false ) ) ;
if ( ! response . Contains ( "ERROR:" ) )
{
2019-01-07 23:27:46 +00:00
// No error occur, get and decode the response.
2014-05-09 04:38:12 +00:00
XmlRpcMethodCall [ ] calls = XmlRpcGenerator . DecodeMethodResponse ( response ) ;
if ( calls . Length > 0 )
{
if ( calls [ 0 ] . Parameters . Count > 0 )
{
// We expect Struct of 3 members:
//* the first is status
//* the second is [array of structs, each one includes subtitle file].
//* the third is [double basic value] represent seconds token by server.
2019-01-13 20:37:13 +00:00
var mainStruct = ( XmlRpcValueStruct ) calls [ 0 ] . Parameters [ 0 ] ;
2014-05-09 04:38:12 +00:00
// Create the response, we'll need it later
2019-01-13 20:37:13 +00:00
var R = new MethodResponseSubtitleSearch ( ) ;
2014-05-09 04:38:12 +00:00
// To make sure response is not currepted by server, do it in loop
2019-01-18 15:48:01 +00:00
foreach ( XmlRpcStructMember MEMBER in mainStruct . Members )
2014-05-09 04:38:12 +00:00
{
if ( MEMBER . Name = = "status" )
{
R . Status = ( string ) MEMBER . Data . Data ;
OSHConsole . WriteLine ( "Status= " + R . Status ) ;
}
else if ( MEMBER . Name = = "seconds" )
{
R . Seconds = ( double ) MEMBER . Data . Data ;
OSHConsole . WriteLine ( "Seconds= " + R . Seconds ) ;
}
else if ( MEMBER . Name = = "data" )
{
if ( MEMBER . Data is XmlRpcValueArray )
{
OSHConsole . WriteLine ( "Search results: " ) ;
2019-01-13 20:37:13 +00:00
var rarray = ( XmlRpcValueArray ) MEMBER . Data ;
2019-01-18 15:48:01 +00:00
foreach ( IXmlRpcValue subStruct in rarray . Values )
2014-05-09 04:38:12 +00:00
{
if ( subStruct = = null ) continue ;
if ( ! ( subStruct is XmlRpcValueStruct ) ) continue ;
2019-01-13 20:37:13 +00:00
var result = new SubtitleSearchResult ( ) ;
2019-01-18 15:48:01 +00:00
foreach ( XmlRpcStructMember submember in ( ( XmlRpcValueStruct ) subStruct ) . Members )
2014-05-09 04:38:12 +00:00
{
// To avoid errors of arranged info or missing ones, let's do it with switch..
switch ( submember . Name )
{
case "IDMovie" : result . IDMovie = submember . Data . Data . ToString ( ) ; break ;
case "IDMovieImdb" : result . IDMovieImdb = submember . Data . Data . ToString ( ) ; break ;
case "IDSubMovieFile" : result . IDSubMovieFile = submember . Data . Data . ToString ( ) ; break ;
case "IDSubtitle" : result . IDSubtitle = submember . Data . Data . ToString ( ) ; break ;
case "IDSubtitleFile" : result . IDSubtitleFile = submember . Data . Data . ToString ( ) ; break ;
case "ISO639" : result . ISO639 = submember . Data . Data . ToString ( ) ; break ;
case "LanguageName" : result . LanguageName = submember . Data . Data . ToString ( ) ; break ;
case "MovieByteSize" : result . MovieByteSize = submember . Data . Data . ToString ( ) ; break ;
case "MovieHash" : result . MovieHash = submember . Data . Data . ToString ( ) ; break ;
case "MovieImdbRating" : result . MovieImdbRating = submember . Data . Data . ToString ( ) ; break ;
case "MovieName" : result . MovieName = submember . Data . Data . ToString ( ) ; break ;
case "MovieNameEng" : result . MovieNameEng = submember . Data . Data . ToString ( ) ; break ;
case "MovieReleaseName" : result . MovieReleaseName = submember . Data . Data . ToString ( ) ; break ;
case "MovieTimeMS" : result . MovieTimeMS = submember . Data . Data . ToString ( ) ; break ;
case "MovieYear" : result . MovieYear = submember . Data . Data . ToString ( ) ; break ;
case "SubActualCD" : result . SubActualCD = submember . Data . Data . ToString ( ) ; break ;
case "SubAddDate" : result . SubAddDate = submember . Data . Data . ToString ( ) ; break ;
case "SubAuthorComment" : result . SubAuthorComment = submember . Data . Data . ToString ( ) ; break ;
case "SubBad" : result . SubBad = submember . Data . Data . ToString ( ) ; break ;
case "SubDownloadLink" : result . SubDownloadLink = submember . Data . Data . ToString ( ) ; break ;
case "SubDownloadsCnt" : result . SubDownloadsCnt = submember . Data . Data . ToString ( ) ; break ;
case "SeriesEpisode" : result . SeriesEpisode = submember . Data . Data . ToString ( ) ; break ;
case "SeriesSeason" : result . SeriesSeason = submember . Data . Data . ToString ( ) ; break ;
case "SubFileName" : result . SubFileName = submember . Data . Data . ToString ( ) ; break ;
case "SubFormat" : result . SubFormat = submember . Data . Data . ToString ( ) ; break ;
case "SubHash" : result . SubHash = submember . Data . Data . ToString ( ) ; break ;
case "SubLanguageID" : result . SubLanguageID = submember . Data . Data . ToString ( ) ; break ;
case "SubRating" : result . SubRating = submember . Data . Data . ToString ( ) ; break ;
case "SubSize" : result . SubSize = submember . Data . Data . ToString ( ) ; break ;
case "SubSumCD" : result . SubSumCD = submember . Data . Data . ToString ( ) ; break ;
case "UserID" : result . UserID = submember . Data . Data . ToString ( ) ; break ;
case "UserNickName" : result . UserNickName = submember . Data . Data . ToString ( ) ; break ;
case "ZipDownloadLink" : result . ZipDownloadLink = submember . Data . Data . ToString ( ) ; break ;
}
}
R . Results . Add ( result ) ;
OSHConsole . WriteLine ( ">" + result . ToString ( ) ) ;
}
}
else // Unknown data ?
{
OSHConsole . WriteLine ( "Data= " + MEMBER . Data . Data . ToString ( ) , DebugCode . Warning ) ;
}
}
}
// Return the response to user !!
return R ;
}
}
}
else
{
OSHConsole . WriteLine ( response , DebugCode . Error ) ;
return new MethodResponseError ( "Fail" , response ) ;
}
return new MethodResponseError ( "Fail" , "Search Subtitles call failed !" ) ;
}
2019-01-07 23:27:46 +00:00
2014-05-05 04:36:45 +00:00
/// <summary>
/// Download subtitle file(s)
/// </summary>
/// <param name="subIDS">The subtitle IDS (an array of IDSubtitleFile value that given by server as SearchSubtiles results)</param>
/// <returns>Status of the call operation. If the call success the response will be 'MethodResponseSubtitleDownload' which will hold downloaded subtitles</returns>
public static IMethodResponse DownloadSubtitles ( int [ ] subIDS )
{
if ( TOKEN = = "" )
{
OSHConsole . WriteLine ( "Can't do this call, 'token' value not set. Please use Log In method first." , DebugCode . Error ) ;
return new MethodResponseError ( "Fail" , "Can't do this call, 'token' value not set. Please use Log In method first." ) ;
}
if ( subIDS = = null )
{
OSHConsole . UpdateLine ( "No subtitle id passed !!" , DebugCode . Error ) ;
2019-01-06 20:50:43 +00:00
return new MethodResponseError ( "Fail" , "No subtitle id passed" ) ;
2014-05-05 04:36:45 +00:00
}
if ( subIDS . Length = = 0 )
{
OSHConsole . UpdateLine ( "No subtitle id passed !!" , DebugCode . Error ) ;
2019-01-06 20:50:43 +00:00
return new MethodResponseError ( "Fail" , "No subtitle id passed" ) ;
2014-05-05 04:36:45 +00:00
}
// Method call ..
2019-01-13 20:37:13 +00:00
var parms = new List < IXmlRpcValue > ( ) ;
2014-05-05 04:36:45 +00:00
// Add token param
parms . Add ( new XmlRpcValueBasic ( TOKEN , XmlRpcBasicValueType . String ) ) ;
// Add subtitle search parameters. Each one will be like 'array' of structs.
2019-01-13 20:37:13 +00:00
var array = new XmlRpcValueArray ( ) ;
2014-05-05 04:36:45 +00:00
foreach ( int id in subIDS )
{
array . Values . Add ( new XmlRpcValueBasic ( id , XmlRpcBasicValueType . Int ) ) ;
}
// Add the array to the parameters
parms . Add ( array ) ;
// Call !
2019-01-13 20:37:13 +00:00
var call = new XmlRpcMethodCall ( "DownloadSubtitles" , parms ) ;
2014-05-05 04:36:45 +00:00
OSHConsole . WriteLine ( "Sending DownloadSubtitles request to the server ..." , DebugCode . Good ) ;
// Send the request to the server
string response = Utilities . GetStreamString ( Utilities . SendRequest ( XmlRpcGenerator . Generate ( call ) , XML_PRC_USERAGENT ) ) ;
if ( ! response . Contains ( "ERROR:" ) )
{
2019-01-07 23:27:46 +00:00
// No error occur, get and decode the response.
2014-05-05 04:36:45 +00:00
XmlRpcMethodCall [ ] calls = XmlRpcGenerator . DecodeMethodResponse ( response ) ;
if ( calls . Length > 0 )
{
if ( calls [ 0 ] . Parameters . Count > 0 )
{
// We expect Struct of 3 members:
//* the first is status
//* the second is [array of structs, each one includes subtitle file].
//* the third is [double basic value] represent seconds token by server.
2019-01-13 20:37:13 +00:00
var mainStruct = ( XmlRpcValueStruct ) calls [ 0 ] . Parameters [ 0 ] ;
2014-05-05 04:36:45 +00:00
// Create the response, we'll need it later
2019-01-13 20:37:13 +00:00
var R = new MethodResponseSubtitleDownload ( ) ;
2014-05-05 04:36:45 +00:00
// To make sure response is not currepted by server, do it in loop
2019-01-18 15:48:01 +00:00
foreach ( XmlRpcStructMember MEMBER in mainStruct . Members )
2014-05-05 04:36:45 +00:00
{
if ( MEMBER . Name = = "status" )
{
R . Status = ( string ) MEMBER . Data . Data ;
OSHConsole . WriteLine ( "Status= " + R . Status ) ;
}
else if ( MEMBER . Name = = "seconds" )
{
R . Seconds = ( double ) MEMBER . Data . Data ;
OSHConsole . WriteLine ( "Seconds= " + R . Seconds ) ;
}
else if ( MEMBER . Name = = "data" )
{
if ( MEMBER . Data is XmlRpcValueArray )
{
OSHConsole . WriteLine ( "Download results:" ) ;
2019-01-13 20:37:13 +00:00
var rarray = ( XmlRpcValueArray ) MEMBER . Data ;
2019-01-18 15:48:01 +00:00
foreach ( IXmlRpcValue subStruct in rarray . Values )
2014-05-05 04:36:45 +00:00
{
if ( subStruct = = null ) continue ;
if ( ! ( subStruct is XmlRpcValueStruct ) ) continue ;
2019-01-13 20:37:13 +00:00
var result = new SubtitleDownloadResult ( ) ;
2019-01-18 15:48:01 +00:00
foreach ( XmlRpcStructMember submember in ( ( XmlRpcValueStruct ) subStruct ) . Members )
2014-05-05 04:36:45 +00:00
{
// To avoid errors of arranged info or missing ones, let's do it with switch..
switch ( submember . Name )
{
case "idsubtitlefile" : result . IdSubtitleFile = ( string ) submember . Data . Data ; break ;
case "data" : result . Data = ( string ) submember . Data . Data ; break ;
}
}
R . Results . Add ( result ) ;
OSHConsole . WriteLine ( "> IDSubtilteFile= " + result . ToString ( ) ) ;
}
}
else // Unknown data ?
{
OSHConsole . WriteLine ( "Data= " + MEMBER . Data . Data . ToString ( ) , DebugCode . Warning ) ;
}
}
}
// Return the response to user !!
return R ;
}
}
}
else
{
OSHConsole . WriteLine ( response , DebugCode . Error ) ;
return new MethodResponseError ( "Fail" , response ) ;
}
return new MethodResponseError ( "Fail" , "DownloadSubtitles call failed !" ) ;
}
2014-05-07 18:38:50 +00:00
public static async Task < IMethodResponse > DownloadSubtitlesAsync ( int [ ] subIDS , CancellationToken cancellationToken )
{
if ( TOKEN = = "" )
{
OSHConsole . WriteLine ( "Can't do this call, 'token' value not set. Please use Log In method first." , DebugCode . Error ) ;
return new MethodResponseError ( "Fail" , "Can't do this call, 'token' value not set. Please use Log In method first." ) ;
}
if ( subIDS = = null )
{
OSHConsole . UpdateLine ( "No subtitle id passed !!" , DebugCode . Error ) ;
2019-01-06 20:50:43 +00:00
return new MethodResponseError ( "Fail" , "No subtitle id passed" ) ;
2014-05-07 18:38:50 +00:00
}
if ( subIDS . Length = = 0 )
{
OSHConsole . UpdateLine ( "No subtitle id passed !!" , DebugCode . Error ) ;
2019-01-06 20:50:43 +00:00
return new MethodResponseError ( "Fail" , "No subtitle id passed" ) ;
2014-05-07 18:38:50 +00:00
}
// Method call ..
2019-01-13 20:37:13 +00:00
var parms = new List < IXmlRpcValue > ( ) ;
2014-05-07 18:38:50 +00:00
// Add token param
parms . Add ( new XmlRpcValueBasic ( TOKEN , XmlRpcBasicValueType . String ) ) ;
// Add subtitle search parameters. Each one will be like 'array' of structs.
2019-01-13 20:37:13 +00:00
var array = new XmlRpcValueArray ( ) ;
2014-05-07 18:38:50 +00:00
foreach ( int id in subIDS )
{
array . Values . Add ( new XmlRpcValueBasic ( id , XmlRpcBasicValueType . Int ) ) ;
}
// Add the array to the parameters
parms . Add ( array ) ;
// Call !
2019-01-13 20:37:13 +00:00
var call = new XmlRpcMethodCall ( "DownloadSubtitles" , parms ) ;
2014-05-07 18:38:50 +00:00
OSHConsole . WriteLine ( "Sending DownloadSubtitles request to the server ..." , DebugCode . Good ) ;
// Send the request to the server
var httpResponse = await Utilities . SendRequestAsync ( XmlRpcGenerator . Generate ( call ) , XML_PRC_USERAGENT , cancellationToken ) . ConfigureAwait ( false ) ;
string response = Utilities . GetStreamString ( httpResponse ) ;
if ( ! response . Contains ( "ERROR:" ) )
{
2019-01-07 23:27:46 +00:00
// No error occur, get and decode the response.
2014-05-07 18:38:50 +00:00
XmlRpcMethodCall [ ] calls = XmlRpcGenerator . DecodeMethodResponse ( response ) ;
if ( calls . Length > 0 )
{
if ( calls [ 0 ] . Parameters . Count > 0 )
{
// We expect Struct of 3 members:
//* the first is status
//* the second is [array of structs, each one includes subtitle file].
//* the third is [double basic value] represent seconds token by server.
2019-01-13 20:37:13 +00:00
var mainStruct = ( XmlRpcValueStruct ) calls [ 0 ] . Parameters [ 0 ] ;
2014-05-07 18:38:50 +00:00
// Create the response, we'll need it later
2019-01-13 20:37:13 +00:00
var R = new MethodResponseSubtitleDownload ( ) ;
2014-05-07 18:38:50 +00:00
// To make sure response is not currepted by server, do it in loop
2019-01-18 15:48:01 +00:00
foreach ( XmlRpcStructMember MEMBER in mainStruct . Members )
2014-05-07 18:38:50 +00:00
{
if ( MEMBER . Name = = "status" )
{
R . Status = ( string ) MEMBER . Data . Data ;
OSHConsole . WriteLine ( "Status= " + R . Status ) ;
}
else if ( MEMBER . Name = = "seconds" )
{
R . Seconds = ( double ) MEMBER . Data . Data ;
OSHConsole . WriteLine ( "Seconds= " + R . Seconds ) ;
}
else if ( MEMBER . Name = = "data" )
{
if ( MEMBER . Data is XmlRpcValueArray )
{
OSHConsole . WriteLine ( "Download results:" ) ;
2019-01-13 20:37:13 +00:00
var rarray = ( XmlRpcValueArray ) MEMBER . Data ;
2019-01-18 15:48:01 +00:00
foreach ( IXmlRpcValue subStruct in rarray . Values )
2014-05-07 18:38:50 +00:00
{
if ( subStruct = = null ) continue ;
if ( ! ( subStruct is XmlRpcValueStruct ) ) continue ;
2019-01-13 20:37:13 +00:00
var result = new SubtitleDownloadResult ( ) ;
2019-01-18 15:48:01 +00:00
foreach ( XmlRpcStructMember submember in ( ( XmlRpcValueStruct ) subStruct ) . Members )
2014-05-07 18:38:50 +00:00
{
// To avoid errors of arranged info or missing ones, let's do it with switch..
switch ( submember . Name )
{
case "idsubtitlefile" : result . IdSubtitleFile = ( string ) submember . Data . Data ; break ;
case "data" : result . Data = ( string ) submember . Data . Data ; break ;
}
}
R . Results . Add ( result ) ;
OSHConsole . WriteLine ( "> IDSubtilteFile= " + result . ToString ( ) ) ;
}
}
else // Unknown data ?
{
OSHConsole . WriteLine ( "Data= " + MEMBER . Data . Data . ToString ( ) , DebugCode . Warning ) ;
}
}
}
// Return the response to user !!
return R ;
}
}
}
else
{
OSHConsole . WriteLine ( response , DebugCode . Error ) ;
return new MethodResponseError ( "Fail" , response ) ;
}
return new MethodResponseError ( "Fail" , "DownloadSubtitles call failed !" ) ;
}
2019-01-07 23:27:46 +00:00
2014-05-05 04:36:45 +00:00
/// <summary>
/// Returns comments for subtitles
/// </summary>
/// <param name="subIDS">The subtitle IDS (an array of IDSubtitleFile value that given by server as SearchSubtiles results)</param>
/// <returns>Status of the call operation. If the call success the response will be 'MethodResponseGetComments'</returns>
public static IMethodResponse GetComments ( int [ ] subIDS )
{
if ( TOKEN = = "" )
{
OSHConsole . WriteLine ( "Can't do this call, 'token' value not set. Please use Log In method first." , DebugCode . Error ) ;
return new MethodResponseError ( "Fail" , "Can't do this call, 'token' value not set. Please use Log In method first." ) ;
}
if ( subIDS = = null )
{
OSHConsole . UpdateLine ( "No subtitle id passed !!" , DebugCode . Error ) ;
2019-01-06 20:50:43 +00:00
return new MethodResponseError ( "Fail" , "No subtitle id passed" ) ;
2014-05-05 04:36:45 +00:00
}
if ( subIDS . Length = = 0 )
{
OSHConsole . UpdateLine ( "No subtitle id passed !!" , DebugCode . Error ) ;
2019-01-06 20:50:43 +00:00
return new MethodResponseError ( "Fail" , "No subtitle id passed" ) ;
2014-05-05 04:36:45 +00:00
}
// Method call ..
2019-01-13 20:37:13 +00:00
var parms = new List < IXmlRpcValue > ( ) ;
2014-05-05 04:36:45 +00:00
// Add token param
parms . Add ( new XmlRpcValueBasic ( TOKEN ) ) ;
// Add subtitle search parameters. Each one will be like 'array' of structs.
2019-01-13 20:37:13 +00:00
var array = new XmlRpcValueArray ( subIDS ) ;
2014-05-05 04:36:45 +00:00
// Add the array to the parameters
parms . Add ( array ) ;
// Call !
2019-01-13 20:37:13 +00:00
var call = new XmlRpcMethodCall ( "GetComments" , parms ) ;
2014-05-05 04:36:45 +00:00
OSHConsole . WriteLine ( "Sending GetComments request to the server ..." , DebugCode . Good ) ;
// Send the request to the server
string response = Utilities . GetStreamString ( Utilities . SendRequest ( XmlRpcGenerator . Generate ( call ) , XML_PRC_USERAGENT ) ) ;
if ( ! response . Contains ( "ERROR:" ) )
{
2019-01-07 23:27:46 +00:00
// No error occur, get and decode the response.
2014-05-05 04:36:45 +00:00
XmlRpcMethodCall [ ] calls = XmlRpcGenerator . DecodeMethodResponse ( response ) ;
if ( calls . Length > 0 )
{
if ( calls [ 0 ] . Parameters . Count > 0 )
{
2019-01-13 20:37:13 +00:00
var mainStruct = ( XmlRpcValueStruct ) calls [ 0 ] . Parameters [ 0 ] ;
2014-05-05 04:36:45 +00:00
// Create the response, we'll need it later
2019-01-13 20:37:13 +00:00
var R = new MethodResponseGetComments ( ) ;
2014-05-05 04:36:45 +00:00
// To make sure response is not currepted by server, do it in loop
2019-01-18 15:48:01 +00:00
foreach ( XmlRpcStructMember MEMBER in mainStruct . Members )
2014-05-05 04:36:45 +00:00
{
if ( MEMBER . Name = = "status" )
{
R . Status = ( string ) MEMBER . Data . Data ;
OSHConsole . WriteLine ( "Status= " + R . Status ) ;
}
else if ( MEMBER . Name = = "seconds" )
{
R . Seconds = ( double ) MEMBER . Data . Data ;
OSHConsole . WriteLine ( "Seconds= " + R . Seconds ) ;
}
else if ( MEMBER . Name = = "data" )
{
if ( MEMBER . Data is XmlRpcValueArray )
{
OSHConsole . WriteLine ( "Comments results:" ) ;
2019-01-13 20:37:13 +00:00
var rarray = ( XmlRpcValueArray ) MEMBER . Data ;
2019-01-18 15:48:01 +00:00
foreach ( IXmlRpcValue commentStruct in rarray . Values )
2014-05-05 04:36:45 +00:00
{
if ( commentStruct = = null ) continue ;
if ( ! ( commentStruct is XmlRpcValueStruct ) ) continue ;
2019-01-13 20:37:13 +00:00
var result = new GetCommentsResult ( ) ;
2019-01-18 15:48:01 +00:00
foreach ( XmlRpcStructMember commentmember in ( ( XmlRpcValueStruct ) commentStruct ) . Members )
2014-05-05 04:36:45 +00:00
{
// To avoid errors of arranged info or missing ones, let's do it with switch..
switch ( commentmember . Name )
{
case "IDSubtitle" : result . IDSubtitle = ( string ) commentmember . Data . Data ; break ;
case "UserID" : result . UserID = ( string ) commentmember . Data . Data ; break ;
case "UserNickName" : result . UserNickName = ( string ) commentmember . Data . Data ; break ;
case "Comment" : result . Comment = ( string ) commentmember . Data . Data ; break ;
case "Created" : result . Created = ( string ) commentmember . Data . Data ; break ;
}
}
R . Results . Add ( result ) ;
OSHConsole . WriteLine ( "> IDSubtitle= " + result . ToString ( ) ) ;
}
}
else // Unknown data ?
{
OSHConsole . WriteLine ( "Data= " + MEMBER . Data . Data . ToString ( ) , DebugCode . Warning ) ;
}
}
}
// Return the response to user !!
return R ;
}
}
}
else
{
OSHConsole . WriteLine ( response , DebugCode . Error ) ;
return new MethodResponseError ( "Fail" , response ) ;
}
return new MethodResponseError ( "Fail" , "GetComments call failed !" ) ;
}
/// <summary>
/// Schedule a periodical search for subtitles matching given video files, send results to user's e-mail address.
/// </summary>
/// <param name="languageIDS">The language 3 lenght ids array</param>
/// <param name="movies">The movies parameters</param>
/// <returns>Status of the call operation. If the call success the response will be 'MethodResponseSearchToMail'</returns>
public static IMethodResponse SearchToMail ( string [ ] languageIDS , SearchToMailMovieParameter [ ] movies )
{
if ( TOKEN = = "" )
{
OSHConsole . WriteLine ( "Can't do this call, 'token' value not set. Please use Log In method first." , DebugCode . Error ) ;
return new MethodResponseError ( "Fail" , "Can't do this call, 'token' value not set. Please use Log In method first." ) ;
}
// Method call ..
2019-01-13 20:37:13 +00:00
var parms = new List < IXmlRpcValue > ( ) ;
2014-05-05 04:36:45 +00:00
parms . Add ( new XmlRpcValueBasic ( TOKEN , XmlRpcBasicValueType . String ) ) ;
// Array of sub langs
2019-01-13 20:37:13 +00:00
var a = new XmlRpcValueArray ( languageIDS ) ;
2014-05-05 04:36:45 +00:00
parms . Add ( a ) ;
// Array of video parameters
a = new XmlRpcValueArray ( ) ;
2019-01-18 15:48:01 +00:00
foreach ( SearchToMailMovieParameter p in movies )
2014-05-05 04:36:45 +00:00
{
2019-01-13 20:37:13 +00:00
var str = new XmlRpcValueStruct ( new List < XmlRpcStructMember > ( ) ) ;
2014-05-05 04:36:45 +00:00
str . Members . Add ( new XmlRpcStructMember ( "moviehash" , new XmlRpcValueBasic ( p . moviehash ) ) ) ;
str . Members . Add ( new XmlRpcStructMember ( "moviesize" , new XmlRpcValueBasic ( p . moviesize ) ) ) ;
a . Values . Add ( str ) ;
}
parms . Add ( a ) ;
2019-01-13 20:37:13 +00:00
var call = new XmlRpcMethodCall ( "SearchToMail" , parms ) ;
2014-05-05 04:36:45 +00:00
OSHConsole . WriteLine ( "Sending SearchToMail request to the server ..." , DebugCode . Good ) ;
// Send the request to the server
string response = Utilities . GetStreamString ( Utilities . SendRequest ( XmlRpcGenerator . Generate ( call ) , XML_PRC_USERAGENT ) ) ;
if ( ! response . Contains ( "ERROR:" ) )
{
2019-01-07 23:27:46 +00:00
// No error occur, get and decode the response.
2014-05-05 04:36:45 +00:00
XmlRpcMethodCall [ ] calls = XmlRpcGenerator . DecodeMethodResponse ( response ) ;
if ( calls . Length > 0 )
{
if ( calls [ 0 ] . Parameters . Count > 0 )
{
2019-01-13 20:37:13 +00:00
var mainStruct = ( XmlRpcValueStruct ) calls [ 0 ] . Parameters [ 0 ] ;
2014-05-05 04:36:45 +00:00
// Create the response, we'll need it later
2019-01-13 20:37:13 +00:00
var R = new MethodResponseSearchToMail ( ) ;
2014-05-05 04:36:45 +00:00
// To make sure response is not currepted by server, do it in loop
2019-01-18 15:48:01 +00:00
foreach ( XmlRpcStructMember MEMBER in mainStruct . Members )
2014-05-05 04:36:45 +00:00
{
switch ( MEMBER . Name )
{
case "status" : R . Status = ( string ) MEMBER . Data . Data ; OSHConsole . WriteLine ( ">" + MEMBER . Name + "= " + MEMBER . Data . Data . ToString ( ) ) ; break ;
case "seconds" : R . Seconds = ( double ) MEMBER . Data . Data ; OSHConsole . WriteLine ( ">" + MEMBER . Name + "= " + MEMBER . Data . Data . ToString ( ) ) ; break ;
}
}
// Return the response to user !!
return R ;
}
}
}
else
{
OSHConsole . WriteLine ( response , DebugCode . Error ) ;
return new MethodResponseError ( "Fail" , response ) ;
}
return new MethodResponseError ( "Fail" , "SearchToMail call failed !" ) ;
}
/*Movies*/
/// <summary>
2019-01-07 23:27:46 +00:00
/// Search for a movie (using movie title)
2014-05-05 04:36:45 +00:00
/// </summary>
/// <param name="query">Movie title user is searching for, this is cleaned-up a bit (remove dvdrip, etc.) before searching </param>
/// <returns>Status of the call operation. If the call success the response will be 'MethodResponseSubtitleSearch'</returns>
public static IMethodResponse SearchMoviesOnIMDB ( string query )
{
if ( TOKEN = = "" )
{
OSHConsole . WriteLine ( "Can't do this call, 'token' value not set. Please use Log In method first." , DebugCode . Error ) ;
return new MethodResponseError ( "Fail" , "Can't do this call, 'token' value not set. Please use Log In method first." ) ;
}
// Method call ..
2019-01-13 20:37:13 +00:00
var parms = new List < IXmlRpcValue > ( ) ;
2014-05-05 04:36:45 +00:00
// Add token param
parms . Add ( new XmlRpcValueBasic ( TOKEN , XmlRpcBasicValueType . String ) ) ;
// Add query param
parms . Add ( new XmlRpcValueBasic ( query , XmlRpcBasicValueType . String ) ) ;
// Call !
2019-01-13 20:37:13 +00:00
var call = new XmlRpcMethodCall ( "SearchMoviesOnIMDB" , parms ) ;
2014-05-05 04:36:45 +00:00
OSHConsole . WriteLine ( "Sending SearchMoviesOnIMDB request to the server ..." , DebugCode . Good ) ;
// Send the request to the server
string response = Utilities . GetStreamString ( Utilities . SendRequest ( XmlRpcGenerator . Generate ( call ) , XML_PRC_USERAGENT ) ) ;
if ( ! response . Contains ( "ERROR:" ) )
{
2019-01-07 23:27:46 +00:00
// No error occur, get and decode the response.
2014-05-05 04:36:45 +00:00
XmlRpcMethodCall [ ] calls = XmlRpcGenerator . DecodeMethodResponse ( response ) ;
if ( calls . Length > 0 )
{
if ( calls [ 0 ] . Parameters . Count > 0 )
{
2019-01-13 20:37:13 +00:00
var mainStruct = ( XmlRpcValueStruct ) calls [ 0 ] . Parameters [ 0 ] ;
2014-05-05 04:36:45 +00:00
// Create the response, we'll need it later
2019-01-13 20:37:13 +00:00
var R = new MethodResponseMovieSearch ( ) ;
2014-05-05 04:36:45 +00:00
// To make sure response is not currepted by server, do it in loop
2019-01-18 15:48:01 +00:00
foreach ( XmlRpcStructMember MEMBER in mainStruct . Members )
2014-05-05 04:36:45 +00:00
{
if ( MEMBER . Name = = "status" )
{
R . Status = ( string ) MEMBER . Data . Data ;
OSHConsole . WriteLine ( "Status= " + R . Status ) ;
}
else if ( MEMBER . Name = = "seconds" )
{
R . Seconds = ( double ) MEMBER . Data . Data ;
OSHConsole . WriteLine ( "Seconds= " + R . Seconds ) ;
}
else if ( MEMBER . Name = = "data" )
{
if ( MEMBER . Data is XmlRpcValueArray )
{
OSHConsole . WriteLine ( "Search results:" ) ;
2019-01-13 20:37:13 +00:00
var rarray = ( XmlRpcValueArray ) MEMBER . Data ;
2019-01-18 15:48:01 +00:00
foreach ( IXmlRpcValue subStruct in rarray . Values )
2014-05-05 04:36:45 +00:00
{
if ( subStruct = = null ) continue ;
if ( ! ( subStruct is XmlRpcValueStruct ) ) continue ;
2019-01-13 20:37:13 +00:00
var result = new MovieSearchResult ( ) ;
2019-01-18 15:48:01 +00:00
foreach ( XmlRpcStructMember submember in ( ( XmlRpcValueStruct ) subStruct ) . Members )
2014-05-05 04:36:45 +00:00
{
// To avoid errors of arranged info or missing ones, let's do it with switch..
switch ( submember . Name )
{
case "id" : result . ID = ( string ) submember . Data . Data ; break ;
case "title" : result . Title = ( string ) submember . Data . Data ; break ;
}
}
R . Results . Add ( result ) ;
OSHConsole . WriteLine ( ">" + result . ToString ( ) ) ;
}
}
else // Unknown data ?
{
OSHConsole . WriteLine ( "Data= " + MEMBER . Data . Data . ToString ( ) , DebugCode . Warning ) ;
}
}
}
// Return the response to user !!
return R ;
}
}
}
else
{
OSHConsole . WriteLine ( response , DebugCode . Error ) ;
return new MethodResponseError ( "Fail" , response ) ;
}
return new MethodResponseError ( "Fail" , "SearchMoviesOnIMDB call failed !" ) ;
}
/// <summary>
2019-01-07 23:27:46 +00:00
/// Get movie details for given IMDb ID
2014-05-05 04:36:45 +00:00
/// </summary>
/// <param name="imdbid">http://www.imdb.com/</param>
/// <returns>Status of the call operation. If the call success the response will be 'MethodResponseMovieDetails'</returns>
public static IMethodResponse GetIMDBMovieDetails ( string imdbid )
{
if ( TOKEN = = "" )
{
OSHConsole . WriteLine ( "Can't do this call, 'token' value not set. Please use Log In method first." , DebugCode . Error ) ;
return new MethodResponseError ( "Fail" , "Can't do this call, 'token' value not set. Please use Log In method first." ) ;
}
// Method call ..
2019-01-13 20:37:13 +00:00
var parms = new List < IXmlRpcValue > ( ) ;
2014-05-05 04:36:45 +00:00
// Add token param
parms . Add ( new XmlRpcValueBasic ( TOKEN ) ) ;
// Add query param
parms . Add ( new XmlRpcValueBasic ( imdbid ) ) ;
// Call !
2019-01-13 20:37:13 +00:00
var call = new XmlRpcMethodCall ( "GetIMDBMovieDetails" , parms ) ;
2014-05-05 04:36:45 +00:00
OSHConsole . WriteLine ( "Sending GetIMDBMovieDetails request to the server ..." , DebugCode . Good ) ;
// Send the request to the server
string response = Utilities . GetStreamString ( Utilities . SendRequest ( XmlRpcGenerator . Generate ( call ) , XML_PRC_USERAGENT ) ) ;
if ( ! response . Contains ( "ERROR:" ) )
{
2019-01-07 23:27:46 +00:00
// No error occur, get and decode the response.
2014-05-05 04:36:45 +00:00
XmlRpcMethodCall [ ] calls = XmlRpcGenerator . DecodeMethodResponse ( response ) ;
if ( calls . Length > 0 )
{
if ( calls [ 0 ] . Parameters . Count > 0 )
{
2019-01-13 20:37:13 +00:00
var mainStruct = ( XmlRpcValueStruct ) calls [ 0 ] . Parameters [ 0 ] ;
2014-05-05 04:36:45 +00:00
// Create the response, we'll need it later
2019-01-13 20:37:13 +00:00
var R = new MethodResponseMovieDetails ( ) ;
2014-05-05 04:36:45 +00:00
// To make sure response is not currepted by server, do it in loop
2019-01-18 15:48:01 +00:00
foreach ( XmlRpcStructMember MEMBER in mainStruct . Members )
2014-05-05 04:36:45 +00:00
{
if ( MEMBER . Name = = "status" )
{
R . Status = ( string ) MEMBER . Data . Data ;
OSHConsole . WriteLine ( "Status= " + R . Status ) ;
}
else if ( MEMBER . Name = = "seconds" )
{
R . Seconds = ( double ) MEMBER . Data . Data ;
OSHConsole . WriteLine ( "Seconds= " + R . Seconds ) ;
}
else if ( MEMBER . Name = = "data" )
{
// We expect struct with details...
if ( MEMBER . Data is XmlRpcValueStruct )
{
OSHConsole . WriteLine ( "Details result:" ) ;
2019-01-13 20:37:13 +00:00
var detailsStruct = ( XmlRpcValueStruct ) MEMBER . Data ;
2019-01-18 15:48:01 +00:00
foreach ( XmlRpcStructMember dmem in detailsStruct . Members )
2014-05-05 04:36:45 +00:00
{
switch ( dmem . Name )
{
case "id" : R . ID = dmem . Data . Data . ToString ( ) ; OSHConsole . WriteLine ( ">" + dmem . Name + "= " + dmem . Data . Data . ToString ( ) ) ; break ;
case "title" : R . Title = dmem . Data . Data . ToString ( ) ; OSHConsole . WriteLine ( ">" + dmem . Name + "= " + dmem . Data . Data . ToString ( ) ) ; break ;
case "year" : R . Year = dmem . Data . Data . ToString ( ) ; OSHConsole . WriteLine ( ">" + dmem . Name + "= " + dmem . Data . Data . ToString ( ) ) ; break ;
case "cover" : R . CoverLink = dmem . Data . Data . ToString ( ) ; OSHConsole . WriteLine ( ">" + dmem . Name + "= " + dmem . Data . Data . ToString ( ) ) ; break ;
case "duration" : R . Duration = dmem . Data . Data . ToString ( ) ; OSHConsole . WriteLine ( ">" + dmem . Name + "= " + dmem . Data . Data . ToString ( ) ) ; break ;
case "tagline" : R . Tagline = dmem . Data . Data . ToString ( ) ; OSHConsole . WriteLine ( ">" + dmem . Name + "= " + dmem . Data . Data . ToString ( ) ) ; break ;
case "plot" : R . Plot = dmem . Data . Data . ToString ( ) ; OSHConsole . WriteLine ( ">" + dmem . Name + "= " + dmem . Data . Data . ToString ( ) ) ; break ;
case "goofs" : R . Goofs = dmem . Data . Data . ToString ( ) ; OSHConsole . WriteLine ( ">" + dmem . Name + "= " + dmem . Data . Data . ToString ( ) ) ; break ;
case "trivia" : R . Trivia = dmem . Data . Data . ToString ( ) ; OSHConsole . WriteLine ( ">" + dmem . Name + "= " + dmem . Data . Data . ToString ( ) ) ; break ;
case "cast" :
// this is another struct with cast members...
OSHConsole . WriteLine ( ">" + dmem . Name + "= " ) ;
2019-01-13 20:37:13 +00:00
var castStruct = ( XmlRpcValueStruct ) dmem . Data ;
2019-01-18 15:48:01 +00:00
foreach ( XmlRpcStructMember castMemeber in castStruct . Members )
2014-05-05 04:36:45 +00:00
{
R . Cast . Add ( castMemeber . Data . Data . ToString ( ) ) ;
OSHConsole . WriteLine ( " >" + castMemeber . Data . Data . ToString ( ) ) ;
}
break ;
case "directors" :
OSHConsole . WriteLine ( ">" + dmem . Name + "= " ) ;
// this is another struct with directors members...
2019-01-13 20:37:13 +00:00
var directorsStruct = ( XmlRpcValueStruct ) dmem . Data ;
2019-01-18 15:48:01 +00:00
foreach ( XmlRpcStructMember directorsMember in directorsStruct . Members )
2014-05-05 04:36:45 +00:00
{
R . Directors . Add ( directorsMember . Data . Data . ToString ( ) ) ;
OSHConsole . WriteLine ( " >" + directorsMember . Data . Data . ToString ( ) ) ;
}
break ;
case "writers" :
OSHConsole . WriteLine ( ">" + dmem . Name + "= " ) ;
// this is another struct with writers members...
2019-01-13 20:37:13 +00:00
var writersStruct = ( XmlRpcValueStruct ) dmem . Data ;
2019-01-18 15:48:01 +00:00
foreach ( XmlRpcStructMember writersMember in writersStruct . Members )
2014-05-05 04:36:45 +00:00
{
R . Writers . Add ( writersMember . Data . Data . ToString ( ) ) ;
OSHConsole . WriteLine ( "+->" + writersMember . Data . Data . ToString ( ) ) ;
}
break ;
case "awards" :
// this is an array of genres...
2019-01-13 20:37:13 +00:00
var awardsArray = ( XmlRpcValueArray ) dmem . Data ;
2014-05-05 04:36:45 +00:00
foreach ( XmlRpcValueBasic award in awardsArray . Values )
{
R . Awards . Add ( award . Data . ToString ( ) ) ;
OSHConsole . WriteLine ( " >" + award . Data . ToString ( ) ) ;
}
break ;
case "genres" :
OSHConsole . WriteLine ( ">" + dmem . Name + "= " ) ;
// this is an array of genres...
2019-01-13 20:37:13 +00:00
var genresArray = ( XmlRpcValueArray ) dmem . Data ;
2014-05-05 04:36:45 +00:00
foreach ( XmlRpcValueBasic genre in genresArray . Values )
{
R . Genres . Add ( genre . Data . ToString ( ) ) ;
OSHConsole . WriteLine ( " >" + genre . Data . ToString ( ) ) ;
}
break ;
case "country" :
OSHConsole . WriteLine ( ">" + dmem . Name + "= " ) ;
// this is an array of country...
2019-01-13 20:37:13 +00:00
var countryArray = ( XmlRpcValueArray ) dmem . Data ;
2014-05-05 04:36:45 +00:00
foreach ( XmlRpcValueBasic country in countryArray . Values )
{
R . Country . Add ( country . Data . ToString ( ) ) ;
OSHConsole . WriteLine ( " >" + country . Data . ToString ( ) ) ;
}
break ;
case "language" :
OSHConsole . WriteLine ( ">" + dmem . Name + "= " ) ;
// this is an array of language...
2019-01-13 20:37:13 +00:00
var languageArray = ( XmlRpcValueArray ) dmem . Data ;
2014-05-05 04:36:45 +00:00
foreach ( XmlRpcValueBasic language in languageArray . Values )
{
R . Language . Add ( language . Data . ToString ( ) ) ;
OSHConsole . WriteLine ( " >" + language . Data . ToString ( ) ) ;
}
break ;
case "certification" :
OSHConsole . WriteLine ( ">" + dmem . Name + "= " ) ;
// this is an array of certification...
2019-01-13 20:37:13 +00:00
var certificationArray = ( XmlRpcValueArray ) dmem . Data ;
2014-05-05 04:36:45 +00:00
foreach ( XmlRpcValueBasic certification in certificationArray . Values )
{
R . Certification . Add ( certification . Data . ToString ( ) ) ;
OSHConsole . WriteLine ( " >" + certification . Data . ToString ( ) ) ;
}
break ;
}
}
}
else // Unknown data ?
{
OSHConsole . WriteLine ( "Data= " + MEMBER . Data . Data . ToString ( ) , DebugCode . Warning ) ;
}
}
}
// Return the response to user !!
return R ;
}
}
}
else
{
OSHConsole . WriteLine ( response , DebugCode . Error ) ;
return new MethodResponseError ( "Fail" , response ) ;
}
return new MethodResponseError ( "Fail" , "GetIMDBMovieDetails call failed !" ) ;
}
/// <summary>
2019-01-07 23:27:46 +00:00
/// Allows registered users to insert new movies (not stored in IMDb) to the database.
2014-05-05 04:36:45 +00:00
/// </summary>
/// <param name="movieName">Movie title </param>
/// <param name="movieyear">Release year </param>
/// <returns>Status of the call operation. If the call success the response will be 'MethodResponseInsertMovie'</returns>
public static IMethodResponse InsertMovie ( string movieName , string movieyear )
{
if ( TOKEN = = "" )
{
OSHConsole . WriteLine ( "Can't do this call, 'token' value not set. Please use Log In method first." , DebugCode . Error ) ;
return new MethodResponseError ( "Fail" , "Can't do this call, 'token' value not set. Please use Log In method first." ) ;
}
// Method call ..
2019-01-13 20:37:13 +00:00
var parms = new List < IXmlRpcValue > ( ) ;
2014-05-05 04:36:45 +00:00
// Add token param
parms . Add ( new XmlRpcValueBasic ( TOKEN , XmlRpcBasicValueType . String ) ) ;
// Add movieinfo struct
2019-01-13 20:37:13 +00:00
var movieinfo = new XmlRpcValueStruct ( new List < XmlRpcStructMember > ( ) ) ;
2014-05-05 04:36:45 +00:00
movieinfo . Members . Add ( new XmlRpcStructMember ( "moviename" , new XmlRpcValueBasic ( movieName ) ) ) ;
movieinfo . Members . Add ( new XmlRpcStructMember ( "movieyear" , new XmlRpcValueBasic ( movieyear ) ) ) ;
parms . Add ( movieinfo ) ;
// Call !
2019-01-13 20:37:13 +00:00
var call = new XmlRpcMethodCall ( "InsertMovie" , parms ) ;
2014-05-05 04:36:45 +00:00
OSHConsole . WriteLine ( "Sending InsertMovie request to the server ..." , DebugCode . Good ) ;
// Send the request to the server
string response = Utilities . GetStreamString ( Utilities . SendRequest ( XmlRpcGenerator . Generate ( call ) , XML_PRC_USERAGENT ) ) ;
if ( ! response . Contains ( "ERROR:" ) )
{
2019-01-07 23:27:46 +00:00
// No error occur, get and decode the response.
2014-05-05 04:36:45 +00:00
XmlRpcMethodCall [ ] calls = XmlRpcGenerator . DecodeMethodResponse ( response ) ;
if ( calls . Length > 0 )
{
if ( calls [ 0 ] . Parameters . Count > 0 )
{
2019-01-13 20:37:13 +00:00
var mainStruct = ( XmlRpcValueStruct ) calls [ 0 ] . Parameters [ 0 ] ;
2014-05-05 04:36:45 +00:00
// Create the response, we'll need it later
2019-01-13 20:37:13 +00:00
var R = new MethodResponseInsertMovie ( ) ;
2014-05-05 04:36:45 +00:00
// To make sure response is not currepted by server, do it in loop
2019-01-18 15:48:01 +00:00
foreach ( XmlRpcStructMember MEMBER in mainStruct . Members )
2014-05-05 04:36:45 +00:00
{
if ( MEMBER . Name = = "status" )
{
R . Status = ( string ) MEMBER . Data . Data ;
OSHConsole . WriteLine ( "Status= " + R . Status ) ;
}
else if ( MEMBER . Name = = "seconds" )
{
R . Seconds = ( double ) MEMBER . Data . Data ;
OSHConsole . WriteLine ( "Seconds= " + R . Seconds ) ;
}
else if ( MEMBER . Name = = "id" )
{
R . ID = ( string ) MEMBER . Data . Data ;
OSHConsole . WriteLine ( "ID= " + R . Seconds ) ;
}
}
// Return the response to user !!
return R ;
}
}
}
else
{
OSHConsole . WriteLine ( response , DebugCode . Error ) ;
return new MethodResponseError ( "Fail" , response ) ;
}
return new MethodResponseError ( "Fail" , "InsertMovie call failed !" ) ;
}
/// <summary>
/// Inserts or updates data to tables, which are used for CheckMovieHash() and !CheckMovieHash2().
/// </summary>
/// <param name="parameters">The parameters</param>
/// <returns>Status of the call operation. If the call success the response will be 'MethodResponseInsertMovieHash'</returns>
public static IMethodResponse InsertMovieHash ( InsertMovieHashParameters [ ] parameters )
{
if ( TOKEN = = "" )
{
OSHConsole . WriteLine ( "Can't do this call, 'token' value not set. Please use Log In method first." , DebugCode . Error ) ;
return new MethodResponseError ( "Fail" , "Can't do this call, 'token' value not set. Please use Log In method first." ) ;
}
// Method call ..
2019-01-13 20:37:13 +00:00
var parms = new List < IXmlRpcValue > ( ) ;
2014-05-05 04:36:45 +00:00
parms . Add ( new XmlRpcValueBasic ( TOKEN , XmlRpcBasicValueType . String ) ) ;
2019-01-18 15:48:01 +00:00
foreach ( InsertMovieHashParameters p in parameters )
2014-05-05 04:36:45 +00:00
{
2019-01-13 20:37:13 +00:00
var pstruct = new XmlRpcValueStruct ( new List < XmlRpcStructMember > ( ) ) ;
2014-05-05 04:36:45 +00:00
pstruct . Members . Add ( new XmlRpcStructMember ( "moviehash" , new XmlRpcValueBasic ( p . moviehash ) ) ) ;
pstruct . Members . Add ( new XmlRpcStructMember ( "moviebytesize" , new XmlRpcValueBasic ( p . moviebytesize ) ) ) ;
pstruct . Members . Add ( new XmlRpcStructMember ( "imdbid" , new XmlRpcValueBasic ( p . imdbid ) ) ) ;
pstruct . Members . Add ( new XmlRpcStructMember ( "movietimems" , new XmlRpcValueBasic ( p . movietimems ) ) ) ;
pstruct . Members . Add ( new XmlRpcStructMember ( "moviefps" , new XmlRpcValueBasic ( p . moviefps ) ) ) ;
pstruct . Members . Add ( new XmlRpcStructMember ( "moviefilename" , new XmlRpcValueBasic ( p . moviefilename ) ) ) ;
parms . Add ( pstruct ) ;
}
2019-01-13 20:37:13 +00:00
var call = new XmlRpcMethodCall ( "InsertMovieHash" , parms ) ;
2014-05-05 04:36:45 +00:00
OSHConsole . WriteLine ( "Sending InsertMovieHash request to the server ..." , DebugCode . Good ) ;
// Send the request to the server
string response = Utilities . GetStreamString ( Utilities . SendRequest ( XmlRpcGenerator . Generate ( call ) , XML_PRC_USERAGENT ) ) ;
if ( ! response . Contains ( "ERROR:" ) )
{
2019-01-07 23:27:46 +00:00
// No error occur, get and decode the response.
2014-05-05 04:36:45 +00:00
XmlRpcMethodCall [ ] calls = XmlRpcGenerator . DecodeMethodResponse ( response ) ;
if ( calls . Length > 0 )
{
if ( calls [ 0 ] . Parameters . Count > 0 )
{
2019-01-13 20:37:13 +00:00
var mainStruct = ( XmlRpcValueStruct ) calls [ 0 ] . Parameters [ 0 ] ;
2014-05-05 04:36:45 +00:00
// Create the response, we'll need it later
2019-01-13 20:37:13 +00:00
var R = new MethodResponseInsertMovieHash ( ) ;
2014-05-05 04:36:45 +00:00
// To make sure response is not currepted by server, do it in loop
2019-01-18 15:48:01 +00:00
foreach ( XmlRpcStructMember MEMBER in mainStruct . Members )
2014-05-05 04:36:45 +00:00
{
switch ( MEMBER . Name )
{
case "status" :
R . Status = ( string ) MEMBER . Data . Data ;
OSHConsole . WriteLine ( ">" + MEMBER . Name + "= " + MEMBER . Data . Data . ToString ( ) ) ;
break ;
case "seconds" :
R . Seconds = ( double ) MEMBER . Data . Data ;
OSHConsole . WriteLine ( ">" + MEMBER . Name + "= " + MEMBER . Data . Data . ToString ( ) ) ;
break ;
case "data" :
2019-01-13 20:37:13 +00:00
var dataStruct = ( XmlRpcValueStruct ) MEMBER . Data ;
2019-01-18 15:48:01 +00:00
foreach ( XmlRpcStructMember dataMember in dataStruct . Members )
2014-05-05 04:36:45 +00:00
{
switch ( dataMember . Name )
{
case "accepted_moviehashes" :
2019-01-13 20:37:13 +00:00
var mh = ( XmlRpcValueArray ) dataMember . Data ;
2019-01-18 15:48:01 +00:00
foreach ( IXmlRpcValue val in mh . Values )
2014-05-05 04:36:45 +00:00
{
if ( val is XmlRpcValueBasic )
{
R . accepted_moviehashes . Add ( val . Data . ToString ( ) ) ;
}
}
break ;
case "new_imdbs" :
2019-01-13 20:37:13 +00:00
var mi = ( XmlRpcValueArray ) dataMember . Data ;
2019-01-18 15:48:01 +00:00
foreach ( IXmlRpcValue val in mi . Values )
2014-05-05 04:36:45 +00:00
{
if ( val is XmlRpcValueBasic )
{
R . new_imdbs . Add ( val . Data . ToString ( ) ) ;
}
}
break ;
}
}
break ;
}
}
// Return the response to user !!
return R ;
}
}
}
else
{
OSHConsole . WriteLine ( response , DebugCode . Error ) ;
return new MethodResponseError ( "Fail" , response ) ;
}
return new MethodResponseError ( "Fail" , "InsertMovieHash call failed !" ) ;
}
/*Reporting and rating*/
/// <summary>
2019-01-07 23:27:46 +00:00
/// Get basic server information and statistics
2014-05-05 04:36:45 +00:00
/// </summary>
/// <returns>Status of the call operation. If the call success the response will be 'MethodResponseServerInfo'</returns>
public static IMethodResponse ServerInfo ( )
{
if ( TOKEN = = "" )
{
OSHConsole . WriteLine ( "Can't do this call, 'token' value not set. Please use Log In method first." , DebugCode . Error ) ;
return new MethodResponseError ( "Fail" , "Can't do this call, 'token' value not set. Please use Log In method first." ) ;
}
// Method call ..
2019-01-13 20:37:13 +00:00
var parms = new List < IXmlRpcValue > ( ) ;
2014-05-05 04:36:45 +00:00
parms . Add ( new XmlRpcValueBasic ( TOKEN , XmlRpcBasicValueType . String ) ) ;
parms . Add ( new XmlRpcValueBasic ( XML_PRC_USERAGENT , XmlRpcBasicValueType . String ) ) ;
2019-01-13 20:37:13 +00:00
var call = new XmlRpcMethodCall ( "ServerInfo" , parms ) ;
2014-05-05 04:36:45 +00:00
OSHConsole . WriteLine ( "Sending ServerInfo request to the server ..." , DebugCode . Good ) ;
// Send the request to the server
string response = Utilities . GetStreamString ( Utilities . SendRequest ( XmlRpcGenerator . Generate ( call ) , XML_PRC_USERAGENT ) ) ;
if ( ! response . Contains ( "ERROR:" ) )
{
2019-01-07 23:27:46 +00:00
// No error occur, get and decode the response.
2014-05-05 04:36:45 +00:00
XmlRpcMethodCall [ ] calls = XmlRpcGenerator . DecodeMethodResponse ( response ) ;
if ( calls . Length > 0 )
{
if ( calls [ 0 ] . Parameters . Count > 0 )
{
2019-01-13 20:37:13 +00:00
var mainStruct = ( XmlRpcValueStruct ) calls [ 0 ] . Parameters [ 0 ] ;
2014-05-05 04:36:45 +00:00
// Create the response, we'll need it later
2019-01-13 20:37:13 +00:00
var R = new MethodResponseServerInfo ( ) ;
2014-05-05 04:36:45 +00:00
// To make sure response is not currepted by server, do it in loop
2019-01-18 15:48:01 +00:00
foreach ( XmlRpcStructMember MEMBER in mainStruct . Members )
2014-05-05 04:36:45 +00:00
{
switch ( MEMBER . Name )
{
case "status" :
R . Status = ( string ) MEMBER . Data . Data ;
OSHConsole . WriteLine ( ">" + MEMBER . Name + "= " + MEMBER . Data . Data . ToString ( ) ) ;
break ;
case "seconds" :
R . Seconds = ( double ) MEMBER . Data . Data ;
OSHConsole . WriteLine ( ">" + MEMBER . Name + "= " + MEMBER . Data . Data . ToString ( ) ) ;
break ;
case "xmlrpc_version" :
R . xmlrpc_version = ( string ) MEMBER . Data . Data ;
OSHConsole . WriteLine ( ">" + MEMBER . Name + "= " + MEMBER . Data . Data . ToString ( ) ) ;
break ;
case "xmlrpc_url" :
R . xmlrpc_url = ( string ) MEMBER . Data . Data ;
OSHConsole . WriteLine ( ">" + MEMBER . Name + "= " + MEMBER . Data . Data . ToString ( ) ) ;
break ;
case "application" :
R . application = ( string ) MEMBER . Data . Data ;
OSHConsole . WriteLine ( ">" + MEMBER . Name + "= " + MEMBER . Data . Data . ToString ( ) ) ;
break ;
case "contact" :
R . contact = ( string ) MEMBER . Data . Data ;
OSHConsole . WriteLine ( ">" + MEMBER . Name + "= " + MEMBER . Data . Data . ToString ( ) ) ;
break ;
case "website_url" :
R . website_url = ( string ) MEMBER . Data . Data ;
OSHConsole . WriteLine ( ">" + MEMBER . Name + "= " + MEMBER . Data . Data . ToString ( ) ) ;
break ;
case "users_online_total" :
R . users_online_total = ( int ) MEMBER . Data . Data ;
OSHConsole . WriteLine ( ">" + MEMBER . Name + "= " + MEMBER . Data . Data . ToString ( ) ) ;
break ;
case "users_online_program" :
R . users_online_program = ( int ) MEMBER . Data . Data ;
OSHConsole . WriteLine ( ">" + MEMBER . Name + "= " + MEMBER . Data . Data . ToString ( ) ) ;
break ;
case "users_loggedin" :
R . users_loggedin = ( int ) MEMBER . Data . Data ;
OSHConsole . WriteLine ( ">" + MEMBER . Name + "= " + MEMBER . Data . Data . ToString ( ) ) ;
break ;
case "users_max_alltime" :
R . users_max_alltime = ( string ) MEMBER . Data . Data ;
OSHConsole . WriteLine ( ">" + MEMBER . Name + "= " + MEMBER . Data . Data . ToString ( ) ) ;
break ;
case "users_registered" :
R . users_registered = ( string ) MEMBER . Data . Data ;
OSHConsole . WriteLine ( ">" + MEMBER . Name + "= " + MEMBER . Data . Data . ToString ( ) ) ;
break ;
case "subs_downloads" :
R . subs_downloads = ( string ) MEMBER . Data . Data ;
OSHConsole . WriteLine ( ">" + MEMBER . Name + "= " + MEMBER . Data . Data . ToString ( ) ) ;
break ;
case "subs_subtitle_files" :
R . subs_subtitle_files = ( string ) MEMBER . Data . Data ;
OSHConsole . WriteLine ( ">" + MEMBER . Name + "= " + MEMBER . Data . Data . ToString ( ) ) ;
break ;
case "movies_total" :
R . movies_total = ( string ) MEMBER . Data . Data ;
OSHConsole . WriteLine ( ">" + MEMBER . Name + "= " + MEMBER . Data . Data . ToString ( ) ) ;
break ;
case "movies_aka" :
R . movies_aka = ( string ) MEMBER . Data . Data ;
OSHConsole . WriteLine ( ">" + MEMBER . Name + "= " + MEMBER . Data . Data . ToString ( ) ) ;
break ;
case "total_subtitles_languages" :
R . total_subtitles_languages = ( string ) MEMBER . Data . Data ;
OSHConsole . WriteLine ( ">" + MEMBER . Name + "= " + MEMBER . Data . Data . ToString ( ) ) ;
break ;
case "last_update_strings" :
//R.total_subtitles_languages = (string)MEMBER.Data.Data;
OSHConsole . WriteLine ( ">" + MEMBER . Name + ":" ) ;
2019-01-13 20:37:13 +00:00
var luStruct = ( XmlRpcValueStruct ) MEMBER . Data ;
2019-01-18 15:48:01 +00:00
foreach ( XmlRpcStructMember luMemeber in luStruct . Members )
2014-05-05 04:36:45 +00:00
{
R . last_update_strings . Add ( luMemeber . Name + " [" + luMemeber . Data . Data . ToString ( ) + "]" ) ;
OSHConsole . WriteLine ( " >" + luMemeber . Name + "= " + luMemeber . Data . Data . ToString ( ) ) ;
}
break ;
}
}
// Return the response to user !!
return R ;
}
}
}
else
{
OSHConsole . WriteLine ( response , DebugCode . Error ) ;
return new MethodResponseError ( "Fail" , response ) ;
}
return new MethodResponseError ( "Fail" , "ServerInfo call failed !" ) ;
}
/// <summary>
/// Report wrong subtitle file <--> video file combination
/// </summary>
/// <param name="IDSubMovieFile">Identifier of the subtitle file <--> video file combination </param>
/// <returns>Status of the call operation. If the call success the response will be 'MethodResponseReportWrongMovieHash'</returns>
public static IMethodResponse ReportWrongMovieHash ( string IDSubMovieFile )
{
if ( TOKEN = = "" )
{
OSHConsole . WriteLine ( "Can't do this call, 'token' value not set. Please use Log In method first." , DebugCode . Error ) ;
return new MethodResponseError ( "Fail" , "Can't do this call, 'token' value not set. Please use Log In method first." ) ;
}
// Method call ..
2019-01-13 20:37:13 +00:00
var parms = new List < IXmlRpcValue > ( ) ;
2014-05-05 04:36:45 +00:00
parms . Add ( new XmlRpcValueBasic ( TOKEN , XmlRpcBasicValueType . String ) ) ;
parms . Add ( new XmlRpcValueBasic ( IDSubMovieFile , XmlRpcBasicValueType . String ) ) ;
2019-01-13 20:37:13 +00:00
var call = new XmlRpcMethodCall ( "ReportWrongMovieHash" , parms ) ;
2014-05-05 04:36:45 +00:00
OSHConsole . WriteLine ( "Sending ReportWrongMovieHash request to the server ..." , DebugCode . Good ) ;
// Send the request to the server
string response = Utilities . GetStreamString ( Utilities . SendRequest ( XmlRpcGenerator . Generate ( call ) , XML_PRC_USERAGENT ) ) ;
if ( ! response . Contains ( "ERROR:" ) )
{
2019-01-07 23:27:46 +00:00
// No error occur, get and decode the response.
2014-05-05 04:36:45 +00:00
XmlRpcMethodCall [ ] calls = XmlRpcGenerator . DecodeMethodResponse ( response ) ;
if ( calls . Length > 0 )
{
if ( calls [ 0 ] . Parameters . Count > 0 )
{
2019-01-13 20:37:13 +00:00
var mainStruct = ( XmlRpcValueStruct ) calls [ 0 ] . Parameters [ 0 ] ;
2014-05-05 04:36:45 +00:00
// Create the response, we'll need it later
2019-01-13 20:37:13 +00:00
var R = new MethodResponseReportWrongMovieHash ( ) ;
2014-05-05 04:36:45 +00:00
// To make sure response is not currepted by server, do it in loop
2019-01-18 15:48:01 +00:00
foreach ( XmlRpcStructMember MEMBER in mainStruct . Members )
2014-05-05 04:36:45 +00:00
{
switch ( MEMBER . Name )
{
case "status" :
R . Status = ( string ) MEMBER . Data . Data ;
OSHConsole . WriteLine ( ">" + MEMBER . Name + "= " + MEMBER . Data . Data . ToString ( ) ) ;
break ;
case "seconds" :
R . Seconds = ( double ) MEMBER . Data . Data ;
OSHConsole . WriteLine ( ">" + MEMBER . Name + "= " + MEMBER . Data . Data . ToString ( ) ) ;
break ;
}
}
// Return the response to user !!
return R ;
}
}
}
else
{
OSHConsole . WriteLine ( response , DebugCode . Error ) ;
return new MethodResponseError ( "Fail" , response ) ;
}
return new MethodResponseError ( "Fail" , "ReportWrongMovieHash call failed !" ) ;
}
/// <summary>
2019-01-07 23:27:46 +00:00
/// This method is needed to report bad movie hash for imdbid. This method should be used for correcting wrong entries,
/// when using CheckMovieHash2. Pass moviehash and moviebytesize for file, and imdbid as new, corrected one IMDBID
/// (id number without trailing zeroes). After some reports, moviehash will be linked to new imdbid.
2014-05-05 04:36:45 +00:00
/// </summary>
/// <param name="moviehash">The movie hash</param>
/// <param name="moviebytesize">The movie size in bytes</param>
/// <param name="imdbid">The movie imbid</param>
/// <returns>Status of the call operation. If the call success the response will be 'MethodResponseReportWrongImdbMovie'</returns>
public static IMethodResponse ReportWrongImdbMovie ( string moviehash , string moviebytesize , string imdbid )
{
if ( TOKEN = = "" )
{
OSHConsole . WriteLine ( "Can't do this call, 'token' value not set. Please use Log In method first." , DebugCode . Error ) ;
return new MethodResponseError ( "Fail" , "Can't do this call, 'token' value not set. Please use Log In method first." ) ;
}
// Method call ..
2019-01-13 20:37:13 +00:00
var parms = new List < IXmlRpcValue > ( ) ;
2014-05-05 04:36:45 +00:00
parms . Add ( new XmlRpcValueBasic ( TOKEN , XmlRpcBasicValueType . String ) ) ;
2019-01-13 20:37:13 +00:00
var s = new XmlRpcValueStruct ( new List < XmlRpcStructMember > ( ) ) ;
2014-05-05 04:36:45 +00:00
s . Members . Add ( new XmlRpcStructMember ( "moviehash" , new XmlRpcValueBasic ( moviehash ) ) ) ;
s . Members . Add ( new XmlRpcStructMember ( "moviebytesize" , new XmlRpcValueBasic ( moviebytesize ) ) ) ;
s . Members . Add ( new XmlRpcStructMember ( "imdbid" , new XmlRpcValueBasic ( imdbid ) ) ) ;
parms . Add ( s ) ;
2019-01-13 20:37:13 +00:00
var call = new XmlRpcMethodCall ( "ReportWrongImdbMovie" , parms ) ;
2014-05-05 04:36:45 +00:00
OSHConsole . WriteLine ( "Sending ReportWrongImdbMovie request to the server ..." , DebugCode . Good ) ;
// Send the request to the server
string response = Utilities . GetStreamString ( Utilities . SendRequest ( XmlRpcGenerator . Generate ( call ) , XML_PRC_USERAGENT ) ) ;
if ( ! response . Contains ( "ERROR:" ) )
{
2019-01-07 23:27:46 +00:00
// No error occur, get and decode the response.
2014-05-05 04:36:45 +00:00
XmlRpcMethodCall [ ] calls = XmlRpcGenerator . DecodeMethodResponse ( response ) ;
if ( calls . Length > 0 )
{
if ( calls [ 0 ] . Parameters . Count > 0 )
{
2019-01-13 20:37:13 +00:00
var mainStruct = ( XmlRpcValueStruct ) calls [ 0 ] . Parameters [ 0 ] ;
2014-05-05 04:36:45 +00:00
// Create the response, we'll need it later
2019-01-13 20:37:13 +00:00
var R = new MethodResponseAddComment ( ) ;
2014-05-05 04:36:45 +00:00
// To make sure response is not currepted by server, do it in loop
2019-01-18 15:48:01 +00:00
foreach ( XmlRpcStructMember MEMBER in mainStruct . Members )
2014-05-05 04:36:45 +00:00
{
switch ( MEMBER . Name )
{
case "status" : R . Status = ( string ) MEMBER . Data . Data ; OSHConsole . WriteLine ( ">" + MEMBER . Name + "= " + MEMBER . Data . Data . ToString ( ) ) ; break ;
case "seconds" : R . Seconds = ( double ) MEMBER . Data . Data ; OSHConsole . WriteLine ( ">" + MEMBER . Name + "= " + MEMBER . Data . Data . ToString ( ) ) ; break ;
}
}
// Return the response to user !!
return R ;
}
}
}
else
{
OSHConsole . WriteLine ( response , DebugCode . Error ) ;
return new MethodResponseError ( "Fail" , response ) ;
}
return new MethodResponseError ( "Fail" , "ReportWrongImdbMovie call failed !" ) ;
}
/// <summary>
2019-01-07 23:27:46 +00:00
/// Rate subtitles
2014-05-05 04:36:45 +00:00
/// </summary>
/// <param name="idsubtitle">Id of subtitle (NOT subtitle file) user wants to rate </param>
/// <param name="score">Subtitle rating, must be in interval 1 (worst) to 10 (best). </param>
/// <returns>Status of the call operation. If the call success the response will be 'MethodResponseSubtitlesVote'</returns>
public static IMethodResponse SubtitlesVote ( int idsubtitle , int score )
{
if ( TOKEN = = "" )
{
OSHConsole . WriteLine ( "Can't do this call, 'token' value not set. Please use Log In method first." , DebugCode . Error ) ;
return new MethodResponseError ( "Fail" , "Can't do this call, 'token' value not set. Please use Log In method first." ) ;
}
// Method call ..
2019-01-13 20:37:13 +00:00
var parms = new List < IXmlRpcValue > ( ) ;
2014-05-05 04:36:45 +00:00
parms . Add ( new XmlRpcValueBasic ( TOKEN , XmlRpcBasicValueType . String ) ) ;
2019-01-13 20:37:13 +00:00
var s = new XmlRpcValueStruct ( new List < XmlRpcStructMember > ( ) ) ;
2014-05-05 04:36:45 +00:00
s . Members . Add ( new XmlRpcStructMember ( "idsubtitle" , new XmlRpcValueBasic ( idsubtitle ) ) ) ;
s . Members . Add ( new XmlRpcStructMember ( "score" , new XmlRpcValueBasic ( score ) ) ) ;
parms . Add ( s ) ;
2019-01-13 20:37:13 +00:00
var call = new XmlRpcMethodCall ( "SubtitlesVote" , parms ) ;
2014-05-05 04:36:45 +00:00
OSHConsole . WriteLine ( "Sending SubtitlesVote request to the server ..." , DebugCode . Good ) ;
// Send the request to the server
string response = Utilities . GetStreamString ( Utilities . SendRequest ( XmlRpcGenerator . Generate ( call ) , XML_PRC_USERAGENT ) ) ;
if ( ! response . Contains ( "ERROR:" ) )
{
2019-01-07 23:27:46 +00:00
// No error occur, get and decode the response.
2014-05-05 04:36:45 +00:00
XmlRpcMethodCall [ ] calls = XmlRpcGenerator . DecodeMethodResponse ( response ) ;
if ( calls . Length > 0 )
{
if ( calls [ 0 ] . Parameters . Count > 0 )
{
2019-01-13 20:37:13 +00:00
var mainStruct = ( XmlRpcValueStruct ) calls [ 0 ] . Parameters [ 0 ] ;
2014-05-05 04:36:45 +00:00
// Create the response, we'll need it later
2019-01-13 20:37:13 +00:00
var R = new MethodResponseSubtitlesVote ( ) ;
2014-05-05 04:36:45 +00:00
// To make sure response is not currepted by server, do it in loop
2019-01-18 15:48:01 +00:00
foreach ( XmlRpcStructMember MEMBER in mainStruct . Members )
2014-05-05 04:36:45 +00:00
{
switch ( MEMBER . Name )
{
case "status" : R . Status = ( string ) MEMBER . Data . Data ; OSHConsole . WriteLine ( ">" + MEMBER . Name + "= " + MEMBER . Data . Data . ToString ( ) ) ; break ;
case "seconds" : R . Seconds = ( double ) MEMBER . Data . Data ; OSHConsole . WriteLine ( ">" + MEMBER . Name + "= " + MEMBER . Data . Data . ToString ( ) ) ; break ;
case "data" :
2019-01-13 20:37:13 +00:00
var dataStruct = ( XmlRpcValueStruct ) MEMBER . Data ;
2019-01-18 15:48:01 +00:00
foreach ( XmlRpcStructMember dataMemeber in dataStruct . Members )
2014-05-05 04:36:45 +00:00
{
OSHConsole . WriteLine ( " >" + dataMemeber . Name + "= " + dataMemeber . Data . Data . ToString ( ) ) ;
switch ( dataMemeber . Name )
{
case "SubRating" : R . SubRating = dataMemeber . Data . Data . ToString ( ) ; break ;
case "SubSumVotes" : R . SubSumVotes = dataMemeber . Data . Data . ToString ( ) ; break ;
case "IDSubtitle" : R . IDSubtitle = dataMemeber . Data . Data . ToString ( ) ; break ;
}
}
break ;
}
}
// Return the response to user !!
return R ;
}
}
}
else
{
OSHConsole . WriteLine ( response , DebugCode . Error ) ;
return new MethodResponseError ( "Fail" , response ) ;
}
return new MethodResponseError ( "Fail" , "SubtitlesVote call failed !" ) ;
}
/// <summary>
2019-01-07 23:27:46 +00:00
/// Add comment to a subtitle
2014-05-05 04:36:45 +00:00
/// </summary>
/// <param name="idsubtitle">Subtitle identifier (BEWARE! this is not the ID of subtitle file but of the whole subtitle (a subtitle can contain multiple subtitle files))</param>
/// <param name="comment">User's comment</param>
/// <param name="badsubtitle">Optional parameter. If set to 1, subtitles are marked as bad.</param>
/// <returns>Status of the call operation. If the call success the response will be 'MethodResponseAddComment'</returns>
public static IMethodResponse AddComment ( int idsubtitle , string comment , int badsubtitle )
{
if ( TOKEN = = "" )
{
OSHConsole . WriteLine ( "Can't do this call, 'token' value not set. Please use Log In method first." , DebugCode . Error ) ;
return new MethodResponseError ( "Fail" , "Can't do this call, 'token' value not set. Please use Log In method first." ) ;
}
// Method call ..
2019-01-13 20:37:13 +00:00
var parms = new List < IXmlRpcValue > ( ) ;
2014-05-05 04:36:45 +00:00
parms . Add ( new XmlRpcValueBasic ( TOKEN , XmlRpcBasicValueType . String ) ) ;
2019-01-13 20:37:13 +00:00
var s = new XmlRpcValueStruct ( new List < XmlRpcStructMember > ( ) ) ;
2014-05-05 04:36:45 +00:00
s . Members . Add ( new XmlRpcStructMember ( "idsubtitle" , new XmlRpcValueBasic ( idsubtitle ) ) ) ;
s . Members . Add ( new XmlRpcStructMember ( "comment" , new XmlRpcValueBasic ( comment ) ) ) ;
s . Members . Add ( new XmlRpcStructMember ( "badsubtitle" , new XmlRpcValueBasic ( badsubtitle ) ) ) ;
parms . Add ( s ) ;
2019-01-13 20:37:13 +00:00
var call = new XmlRpcMethodCall ( "AddComment" , parms ) ;
2014-05-05 04:36:45 +00:00
OSHConsole . WriteLine ( "Sending AddComment request to the server ..." , DebugCode . Good ) ;
// Send the request to the server
string response = Utilities . GetStreamString ( Utilities . SendRequest ( XmlRpcGenerator . Generate ( call ) , XML_PRC_USERAGENT ) ) ;
if ( ! response . Contains ( "ERROR:" ) )
{
2019-01-07 23:27:46 +00:00
// No error occur, get and decode the response.
2014-05-05 04:36:45 +00:00
XmlRpcMethodCall [ ] calls = XmlRpcGenerator . DecodeMethodResponse ( response ) ;
if ( calls . Length > 0 )
{
if ( calls [ 0 ] . Parameters . Count > 0 )
{
2019-01-13 20:37:13 +00:00
var mainStruct = ( XmlRpcValueStruct ) calls [ 0 ] . Parameters [ 0 ] ;
2014-05-05 04:36:45 +00:00
// Create the response, we'll need it later
2019-01-13 20:37:13 +00:00
var R = new MethodResponseAddComment ( ) ;
2014-05-05 04:36:45 +00:00
// To make sure response is not currepted by server, do it in loop
2019-01-13 20:37:13 +00:00
foreach ( var MEMBER in mainStruct . Members )
2014-05-05 04:36:45 +00:00
{
switch ( MEMBER . Name )
{
case "status" : R . Status = ( string ) MEMBER . Data . Data ; OSHConsole . WriteLine ( ">" + MEMBER . Name + "= " + MEMBER . Data . Data . ToString ( ) ) ; break ;
case "seconds" : R . Seconds = ( double ) MEMBER . Data . Data ; OSHConsole . WriteLine ( ">" + MEMBER . Name + "= " + MEMBER . Data . Data . ToString ( ) ) ; break ;
}
}
// Return the response to user !!
return R ;
}
}
}
else
{
OSHConsole . WriteLine ( response , DebugCode . Error ) ;
return new MethodResponseError ( "Fail" , response ) ;
}
return new MethodResponseError ( "Fail" , "AddComment call failed !" ) ;
}
/// <summary>
/// Add new request for subtitles, user must be logged in
/// </summary>
/// <param name="sublanguageid">The subtitle language id 3 length</param>
/// <param name="idmovieimdb">http://www.imdb.com/</param>
/// <param name="comment">The comment</param>
/// <returns>Status of the call operation. If the call success the response will be 'MethodResponseAddRequest'</returns>
public static IMethodResponse AddRequest ( string sublanguageid , string idmovieimdb , string comment )
{
if ( TOKEN = = "" )
{
OSHConsole . WriteLine ( "Can't do this call, 'token' value not set. Please use Log In method first." , DebugCode . Error ) ;
return new MethodResponseError ( "Fail" , "Can't do this call, 'token' value not set. Please use Log In method first." ) ;
}
// Method call ..
2019-01-13 20:37:13 +00:00
var parms = new List < IXmlRpcValue > ( ) ;
2014-05-05 04:36:45 +00:00
parms . Add ( new XmlRpcValueBasic ( TOKEN , XmlRpcBasicValueType . String ) ) ;
2019-01-13 20:37:13 +00:00
var s = new XmlRpcValueStruct ( new List < XmlRpcStructMember > ( ) ) ;
2014-05-05 04:36:45 +00:00
s . Members . Add ( new XmlRpcStructMember ( "sublanguageid" , new XmlRpcValueBasic ( sublanguageid ) ) ) ;
s . Members . Add ( new XmlRpcStructMember ( "idmovieimdb" , new XmlRpcValueBasic ( idmovieimdb ) ) ) ;
s . Members . Add ( new XmlRpcStructMember ( "comment" , new XmlRpcValueBasic ( comment ) ) ) ;
parms . Add ( s ) ;
2019-01-13 20:37:13 +00:00
var call = new XmlRpcMethodCall ( "AddRequest" , parms ) ;
2014-05-05 04:36:45 +00:00
OSHConsole . WriteLine ( "Sending AddRequest request to the server ..." , DebugCode . Good ) ;
// Send the request to the server
string response = Utilities . GetStreamString ( Utilities . SendRequest ( XmlRpcGenerator . Generate ( call ) , XML_PRC_USERAGENT ) ) ;
if ( ! response . Contains ( "ERROR:" ) )
{
2019-01-07 23:27:46 +00:00
// No error occur, get and decode the response.
2014-05-05 04:36:45 +00:00
XmlRpcMethodCall [ ] calls = XmlRpcGenerator . DecodeMethodResponse ( response ) ;
if ( calls . Length > 0 )
{
if ( calls [ 0 ] . Parameters . Count > 0 )
{
2019-01-13 20:37:13 +00:00
var mainStruct = ( XmlRpcValueStruct ) calls [ 0 ] . Parameters [ 0 ] ;
2014-05-05 04:36:45 +00:00
// Create the response, we'll need it later
2019-01-13 20:37:13 +00:00
var R = new MethodResponseAddRequest ( ) ;
2014-05-05 04:36:45 +00:00
// To make sure response is not currepted by server, do it in loop
2019-01-18 15:48:01 +00:00
foreach ( XmlRpcStructMember MEMBER in mainStruct . Members )
2014-05-05 04:36:45 +00:00
{
switch ( MEMBER . Name )
{
case "status" : R . Status = ( string ) MEMBER . Data . Data ; OSHConsole . WriteLine ( ">" + MEMBER . Name + "= " + MEMBER . Data . Data . ToString ( ) ) ; break ;
case "seconds" : R . Seconds = ( double ) MEMBER . Data . Data ; OSHConsole . WriteLine ( ">" + MEMBER . Name + "= " + MEMBER . Data . Data . ToString ( ) ) ; break ;
case "data" :
2019-01-13 20:37:13 +00:00
var dataStruct = ( XmlRpcValueStruct ) MEMBER . Data ;
2019-01-18 15:48:01 +00:00
foreach ( XmlRpcStructMember dataMemeber in dataStruct . Members )
2014-05-05 04:36:45 +00:00
{
switch ( dataMemeber . Name )
{
case "request_url" : R . request_url = dataMemeber . Data . Data . ToString ( ) ; OSHConsole . WriteLine ( ">" + dataMemeber . Name + "= " + dataMemeber . Data . Data . ToString ( ) ) ; break ;
}
}
break ;
}
}
// Return the response to user !!
return R ;
}
}
}
else
{
OSHConsole . WriteLine ( response , DebugCode . Error ) ;
return new MethodResponseError ( "Fail" , response ) ;
}
return new MethodResponseError ( "Fail" , "AddRequest call failed !" ) ;
}
/*User interface*/
/// <summary>
/// Get list of supported subtitle languages
/// </summary>
/// <param name="language">ISO639-1 2-letter language code of user's interface language. </param>
/// <returns>Status of the call operation. If the call success the response will be 'MethodResponseGetSubLanguages'</returns>
public static IMethodResponse GetSubLanguages ( string language )
{
if ( TOKEN = = "" )
{
OSHConsole . WriteLine ( "Can't do this call, 'token' value not set. Please use Log In method first." , DebugCode . Error ) ;
return new MethodResponseError ( "Fail" , "Can't do this call, 'token' value not set. Please use Log In method first." ) ;
}
// Method call ..
2019-01-13 20:37:13 +00:00
var parms = new List < IXmlRpcValue > ( ) ;
2014-05-05 04:36:45 +00:00
parms . Add ( new XmlRpcValueBasic ( TOKEN ) ) ;
parms . Add ( new XmlRpcValueBasic ( language ) ) ;
2019-01-13 20:37:13 +00:00
var call = new XmlRpcMethodCall ( "GetSubLanguages" , parms ) ;
2014-05-05 04:36:45 +00:00
OSHConsole . WriteLine ( "Sending GetSubLanguages request to the server ..." , DebugCode . Good ) ;
// Send the request to the server
string response = Utilities . GetStreamString ( Utilities . SendRequest ( XmlRpcGenerator . Generate ( call ) , XML_PRC_USERAGENT ) ) ;
if ( ! response . Contains ( "ERROR:" ) )
{
2019-01-07 23:27:46 +00:00
// No error occur, get and decode the response.
2014-05-05 04:36:45 +00:00
XmlRpcMethodCall [ ] calls = XmlRpcGenerator . DecodeMethodResponse ( response ) ;
if ( calls . Length > 0 )
{
if ( calls [ 0 ] . Parameters . Count > 0 )
{
2019-01-13 20:37:13 +00:00
var mainStruct = ( XmlRpcValueStruct ) calls [ 0 ] . Parameters [ 0 ] ;
2014-05-05 04:36:45 +00:00
// Create the response, we'll need it later
2019-01-13 20:37:13 +00:00
var R = new MethodResponseGetSubLanguages ( ) ;
2014-05-05 04:36:45 +00:00
// To make sure response is not currepted by server, do it in loop
2019-01-18 15:48:01 +00:00
foreach ( XmlRpcStructMember MEMBER in mainStruct . Members )
2014-05-05 04:36:45 +00:00
{
switch ( MEMBER . Name )
{
case "status" : R . Status = ( string ) MEMBER . Data . Data ; OSHConsole . WriteLine ( ">" + MEMBER . Name + "= " + MEMBER . Data . Data . ToString ( ) ) ; break ;
case "seconds" : R . Seconds = ( double ) MEMBER . Data . Data ; OSHConsole . WriteLine ( ">" + MEMBER . Name + "= " + MEMBER . Data . Data . ToString ( ) ) ; break ;
case "data" : // array of structs
2019-01-13 20:37:13 +00:00
var array = ( XmlRpcValueArray ) MEMBER . Data ;
2019-01-18 15:48:01 +00:00
foreach ( IXmlRpcValue value in array . Values )
2014-05-05 04:36:45 +00:00
{
if ( value is XmlRpcValueStruct )
{
2019-01-13 20:37:13 +00:00
var valueStruct = ( XmlRpcValueStruct ) value ;
var lang = new SubtitleLanguage ( ) ;
2014-05-05 04:36:45 +00:00
OSHConsole . WriteLine ( ">SubLanguage:" ) ;
2019-01-18 15:48:01 +00:00
foreach ( XmlRpcStructMember langMemeber in valueStruct . Members )
2014-05-05 04:36:45 +00:00
{
OSHConsole . WriteLine ( " >" + langMemeber . Name + "= " + langMemeber . Data . Data . ToString ( ) ) ;
switch ( langMemeber . Name )
{
case "SubLanguageID" : lang . SubLanguageID = langMemeber . Data . Data . ToString ( ) ; break ;
case "LanguageName" : lang . LanguageName = langMemeber . Data . Data . ToString ( ) ; break ;
case "ISO639" : lang . ISO639 = langMemeber . Data . Data . ToString ( ) ; break ;
}
}
R . Languages . Add ( lang ) ;
}
else
{
OSHConsole . WriteLine ( ">" + MEMBER . Name + "= " +
MEMBER . Data . Data . ToString ( ) + " [Struct expected !]" , DebugCode . Warning ) ;
}
}
break ;
}
}
// Return the response to user !!
return R ;
}
}
}
else
{
OSHConsole . WriteLine ( response , DebugCode . Error ) ;
return new MethodResponseError ( "Fail" , response ) ;
}
return new MethodResponseError ( "Fail" , "GetSubLanguages call failed !" ) ;
}
/// <summary>
2019-01-07 23:27:46 +00:00
/// Detect language for given strings
2014-05-05 04:36:45 +00:00
/// </summary>
/// <param name="texts">Array of strings you want language detected for</param>
/// <param name="encodingUsed">The encoding that will be used to get buffer of given strings. (this is not OS official parameter)</param>
/// <returns>Status of the call operation. If the call success the response will be 'MethodResponseDetectLanguage'</returns>
public static IMethodResponse DetectLanguage ( string [ ] texts , Encoding encodingUsed )
{
if ( TOKEN = = "" )
{
OSHConsole . WriteLine ( "Can't do this call, 'token' value not set. Please use Log In method first." , DebugCode . Error ) ;
return new MethodResponseError ( "Fail" , "Can't do this call, 'token' value not set. Please use Log In method first." ) ;
}
// Method call ..
2019-01-13 20:37:13 +00:00
var parms = new List < IXmlRpcValue > ( ) ;
2014-05-05 04:36:45 +00:00
parms . Add ( new XmlRpcValueBasic ( TOKEN , XmlRpcBasicValueType . String ) ) ;
// We need to gzip texts then code them with base 24
2019-01-13 20:37:13 +00:00
var decodedTexts = new List < string > ( ) ;
2014-05-05 04:36:45 +00:00
foreach ( string text in texts )
{
// compress
Stream str = new MemoryStream ( ) ;
byte [ ] stringData = encodingUsed . GetBytes ( text ) ;
str . Write ( stringData , 0 , stringData . Length ) ;
str . Position = 0 ;
byte [ ] data = Utilities . Compress ( str ) ;
//base 64
decodedTexts . Add ( Convert . ToBase64String ( data ) ) ;
}
parms . Add ( new XmlRpcValueArray ( decodedTexts . ToArray ( ) ) ) ;
2019-01-13 20:37:13 +00:00
var call = new XmlRpcMethodCall ( "DetectLanguage" , parms ) ;
2014-05-05 04:36:45 +00:00
OSHConsole . WriteLine ( "Sending DetectLanguage request to the server ..." , DebugCode . Good ) ;
// Send the request to the server
string response = Utilities . GetStreamString ( Utilities . SendRequest ( XmlRpcGenerator . Generate ( call ) , XML_PRC_USERAGENT ) ) ;
if ( ! response . Contains ( "ERROR:" ) )
{
2019-01-07 23:27:46 +00:00
// No error occur, get and decode the response.
2014-05-05 04:36:45 +00:00
XmlRpcMethodCall [ ] calls = XmlRpcGenerator . DecodeMethodResponse ( response ) ;
if ( calls . Length > 0 )
{
if ( calls [ 0 ] . Parameters . Count > 0 )
{
2019-01-13 20:37:13 +00:00
var mainStruct = ( XmlRpcValueStruct ) calls [ 0 ] . Parameters [ 0 ] ;
2014-05-05 04:36:45 +00:00
// Create the response, we'll need it later
2019-01-13 20:37:13 +00:00
var R = new MethodResponseDetectLanguage ( ) ;
2014-05-05 04:36:45 +00:00
// To make sure response is not currepted by server, do it in loop
2019-01-18 15:48:01 +00:00
foreach ( XmlRpcStructMember MEMBER in mainStruct . Members )
2014-05-05 04:36:45 +00:00
{
switch ( MEMBER . Name )
{
case "status" : R . Status = ( string ) MEMBER . Data . Data ; OSHConsole . WriteLine ( ">" + MEMBER . Name + "= " + MEMBER . Data . Data . ToString ( ) ) ; break ;
case "seconds" : R . Seconds = ( double ) MEMBER . Data . Data ; OSHConsole . WriteLine ( ">" + MEMBER . Name + "= " + MEMBER . Data . Data . ToString ( ) ) ; break ;
case "data" :
if ( MEMBER . Data is XmlRpcValueStruct )
{
OSHConsole . WriteLine ( ">Languages:" ) ;
2019-01-13 20:37:13 +00:00
var dataStruct = ( XmlRpcValueStruct ) MEMBER . Data ;
2019-01-18 15:48:01 +00:00
foreach ( XmlRpcStructMember dataMember in dataStruct . Members )
2014-05-05 04:36:45 +00:00
{
2019-01-13 20:37:13 +00:00
var lang = new DetectLanguageResult ( ) ;
2014-05-05 04:36:45 +00:00
lang . InputSample = dataMember . Name ;
lang . LanguageID = dataMember . Data . Data . ToString ( ) ;
R . Results . Add ( lang ) ;
OSHConsole . WriteLine ( " >" + dataMember . Name + " (" + dataMember . Data . Data . ToString ( ) + ")" ) ;
}
}
else
{
OSHConsole . WriteLine ( ">Languages ?? Struct expected but server return another type!!" , DebugCode . Warning ) ;
}
break ;
}
}
// Return the response to user !!
return R ;
}
}
}
else
{
OSHConsole . WriteLine ( response , DebugCode . Error ) ;
return new MethodResponseError ( "Fail" , response ) ;
}
return new MethodResponseError ( "Fail" , "DetectLanguage call failed !" ) ;
}
/// <summary>
/// Get available translations for given program
/// </summary>
/// <param name="program">Name of the program/client application you want translations for. Currently supported values: subdownloader, oscar</param>
/// <returns>Status of the call operation. If the call success the response will be 'MethodResponseGetAvailableTranslations'</returns>
public static IMethodResponse GetAvailableTranslations ( string program )
{
if ( TOKEN = = "" )
{
OSHConsole . WriteLine ( "Can't do this call, 'token' value not set. Please use Log In method first." , DebugCode . Error ) ;
return new MethodResponseError ( "Fail" , "Can't do this call, 'token' value not set. Please use Log In method first." ) ;
}
// Method call ..
2019-01-13 20:37:13 +00:00
var parms = new List < IXmlRpcValue > ( ) ;
2014-05-05 04:36:45 +00:00
parms . Add ( new XmlRpcValueBasic ( TOKEN ) ) ;
parms . Add ( new XmlRpcValueBasic ( program ) ) ;
2019-01-13 20:37:13 +00:00
var call = new XmlRpcMethodCall ( "GetAvailableTranslations" , parms ) ;
2014-05-05 04:36:45 +00:00
OSHConsole . WriteLine ( "Sending GetAvailableTranslations request to the server ..." , DebugCode . Good ) ;
// Send the request to the server
string response = Utilities . GetStreamString ( Utilities . SendRequest ( XmlRpcGenerator . Generate ( call ) , XML_PRC_USERAGENT ) ) ;
if ( ! response . Contains ( "ERROR:" ) )
{
2019-01-07 23:27:46 +00:00
// No error occur, get and decode the response.
2014-05-05 04:36:45 +00:00
XmlRpcMethodCall [ ] calls = XmlRpcGenerator . DecodeMethodResponse ( response ) ;
if ( calls . Length > 0 )
{
if ( calls [ 0 ] . Parameters . Count > 0 )
{
2019-01-13 20:37:13 +00:00
var mainStruct = ( XmlRpcValueStruct ) calls [ 0 ] . Parameters [ 0 ] ;
2014-05-05 04:36:45 +00:00
// Create the response, we'll need it later
2019-01-13 20:37:13 +00:00
var R = new MethodResponseGetAvailableTranslations ( ) ;
2014-05-05 04:36:45 +00:00
// To make sure response is not currepted by server, do it in loop
2019-01-18 15:48:01 +00:00
foreach ( XmlRpcStructMember MEMBER in mainStruct . Members )
2014-05-05 04:36:45 +00:00
{
switch ( MEMBER . Name )
{
case "status" : R . Status = ( string ) MEMBER . Data . Data ; OSHConsole . WriteLine ( ">" + MEMBER . Name + "= " + MEMBER . Data . Data . ToString ( ) ) ; break ;
case "seconds" : R . Seconds = ( double ) MEMBER . Data . Data ; OSHConsole . WriteLine ( ">" + MEMBER . Name + "= " + MEMBER . Data . Data . ToString ( ) ) ; break ;
case "data" :
2019-01-13 20:37:13 +00:00
var dataStruct = ( XmlRpcValueStruct ) MEMBER . Data ;
2014-05-05 04:36:45 +00:00
OSHConsole . WriteLine ( ">data:" ) ;
2019-01-18 15:48:01 +00:00
foreach ( XmlRpcStructMember dataMember in dataStruct . Members )
2014-05-05 04:36:45 +00:00
{
if ( dataMember . Data is XmlRpcValueStruct )
{
2019-01-13 20:37:13 +00:00
var resStruct = ( XmlRpcValueStruct ) dataMember . Data ;
var res = new GetAvailableTranslationsResult ( ) ;
2014-05-05 04:36:45 +00:00
res . LanguageID = dataMember . Name ;
OSHConsole . WriteLine ( " >LanguageID: " + dataMember . Name ) ;
2019-01-18 15:48:01 +00:00
foreach ( XmlRpcStructMember resMember in resStruct . Members )
2014-05-05 04:36:45 +00:00
{
switch ( resMember . Name )
{
case "LastCreated" : res . LastCreated = resMember . Data . Data . ToString ( ) ; OSHConsole . WriteLine ( " >" + resMember . Name + "= " + resMember . Data . Data . ToString ( ) ) ; break ;
case "StringsNo" : res . StringsNo = resMember . Data . Data . ToString ( ) ; OSHConsole . WriteLine ( " >" + resMember . Name + "= " + resMember . Data . Data . ToString ( ) ) ; break ;
}
R . Results . Add ( res ) ;
}
}
else
{
OSHConsole . WriteLine ( " >Struct expected !!" , DebugCode . Warning ) ;
}
}
break ;
}
}
// Return the response to user !!
return R ;
}
}
}
else
{
OSHConsole . WriteLine ( response , DebugCode . Error ) ;
return new MethodResponseError ( "Fail" , response ) ;
}
return new MethodResponseError ( "Fail" , "GetAvailableTranslations call failed !" ) ;
}
/// <summary>
2019-01-07 23:27:46 +00:00
/// Get a translation for given program and language
2014-05-05 04:36:45 +00:00
/// </summary>
/// <param name="iso639">language ISO639-1 2-letter code </param>
/// <param name="format">available formats: [gnugettext compatible: mo, po] and [additional: txt, xml]</param>
/// <param name="program">Name of the program/client application you want translations for. (currently supported values: subdownloader, oscar)</param>
/// <returns>Status of the call operation. If the call success the response will be 'MethodResponseGetTranslation'</returns>
public static IMethodResponse GetTranslation ( string iso639 , string format , string program )
{
if ( TOKEN = = "" )
{
OSHConsole . WriteLine ( "Can't do this call, 'token' value not set. Please use Log In method first." , DebugCode . Error ) ;
return new MethodResponseError ( "Fail" , "Can't do this call, 'token' value not set. Please use Log In method first." ) ;
}
// Method call ..
2019-01-13 20:37:13 +00:00
var parms = new List < IXmlRpcValue > ( ) ;
2014-05-05 04:36:45 +00:00
parms . Add ( new XmlRpcValueBasic ( TOKEN ) ) ;
parms . Add ( new XmlRpcValueBasic ( iso639 ) ) ;
parms . Add ( new XmlRpcValueBasic ( format ) ) ;
parms . Add ( new XmlRpcValueBasic ( program ) ) ;
2019-01-13 20:37:13 +00:00
var call = new XmlRpcMethodCall ( "GetTranslation" , parms ) ;
2014-05-05 04:36:45 +00:00
OSHConsole . WriteLine ( "Sending GetTranslation request to the server ..." , DebugCode . Good ) ;
// Send the request to the server
//File.WriteAllText(".\\REQUEST_GetTranslation.xml", Encoding.ASCII.GetString(XmlRpcGenerator.Generate(call)));
string response = Utilities . GetStreamString ( Utilities . SendRequest ( XmlRpcGenerator . Generate ( call ) , XML_PRC_USERAGENT ) ) ;
if ( ! response . Contains ( "ERROR:" ) )
{
2019-01-07 23:27:46 +00:00
// No error occur, get and decode the response.
2014-05-05 04:36:45 +00:00
XmlRpcMethodCall [ ] calls = XmlRpcGenerator . DecodeMethodResponse ( response ) ;
if ( calls . Length > 0 )
{
if ( calls [ 0 ] . Parameters . Count > 0 )
{
2019-01-13 20:37:13 +00:00
var mainStruct = ( XmlRpcValueStruct ) calls [ 0 ] . Parameters [ 0 ] ;
2014-05-05 04:36:45 +00:00
// Create the response, we'll need it later
2019-01-13 20:37:13 +00:00
var R = new MethodResponseGetTranslation ( ) ;
2014-05-05 04:36:45 +00:00
// To make sure response is not currepted by server, do it in loop
2019-01-18 15:48:01 +00:00
foreach ( XmlRpcStructMember MEMBER in mainStruct . Members )
2014-05-05 04:36:45 +00:00
{
switch ( MEMBER . Name )
{
case "status" : R . Status = ( string ) MEMBER . Data . Data ; OSHConsole . WriteLine ( ">" + MEMBER . Name + "= " + MEMBER . Data . Data . ToString ( ) ) ; break ;
case "seconds" : R . Seconds = ( double ) MEMBER . Data . Data ; OSHConsole . WriteLine ( ">" + MEMBER . Name + "= " + MEMBER . Data . Data . ToString ( ) ) ; break ;
case "data" : R . ContentData = ( string ) MEMBER . Data . Data ; OSHConsole . WriteLine ( ">" + MEMBER . Name + "= " + MEMBER . Data . Data . ToString ( ) ) ; break ;
}
}
// Return the response to user !!
return R ;
}
}
}
else
{
OSHConsole . WriteLine ( response , DebugCode . Error ) ;
return new MethodResponseError ( "Fail" , response ) ;
}
return new MethodResponseError ( "Fail" , "GetTranslation call failed !" ) ;
}
/// <summary>
2019-01-07 23:27:46 +00:00
/// Check for the latest version of given application
2014-05-05 04:36:45 +00:00
/// </summary>
/// <param name="program">name of the program/client application you want to check. (Currently supported values: subdownloader, oscar)</param>
/// <returns>Status of the call operation. If the call success the response will be 'MethodResponseAutoUpdate'</returns>
public static IMethodResponse AutoUpdate ( string program )
{
/ * if ( TOKEN = = "" )
{
OSHConsole . WriteLine ( "Can't do this call, 'token' value not set. Please use Log In method first." , DebugCode . Error ) ;
return new MethodResponseError ( "Fail" , "Can't do this call, 'token' value not set. Please use Log In method first." ) ;
} * /
// Method call ..
2019-01-13 20:37:13 +00:00
var parms = new List < IXmlRpcValue > ( ) ;
2014-05-05 04:36:45 +00:00
// parms.Add(new XmlRpcValueBasic(TOKEN));
parms . Add ( new XmlRpcValueBasic ( program ) ) ;
// parms.Add(new XmlRpcValueBasic(XML_PRC_USERAGENT));
2019-01-13 20:37:13 +00:00
var call = new XmlRpcMethodCall ( "AutoUpdate" , parms ) ;
2014-05-05 04:36:45 +00:00
OSHConsole . WriteLine ( "Sending AutoUpdate request to the server ..." , DebugCode . Good ) ;
// Send the request to the server
string response = Utilities . GetStreamString ( Utilities . SendRequest ( XmlRpcGenerator . Generate ( call ) , XML_PRC_USERAGENT ) ) ;
if ( ! response . Contains ( "ERROR:" ) )
{
2019-01-07 23:27:46 +00:00
// No error occur, get and decode the response.
2014-05-05 04:36:45 +00:00
XmlRpcMethodCall [ ] calls = XmlRpcGenerator . DecodeMethodResponse ( response ) ;
if ( calls . Length > 0 )
{
if ( calls [ 0 ] . Parameters . Count > 0 )
{
2019-01-13 20:37:13 +00:00
var mainStruct = ( XmlRpcValueStruct ) calls [ 0 ] . Parameters [ 0 ] ;
2014-05-05 04:36:45 +00:00
// Create the response, we'll need it later
2019-01-13 20:37:13 +00:00
var R = new MethodResponseAutoUpdate ( ) ;
2014-05-05 04:36:45 +00:00
// To make sure response is not currepted by server, do it in loop
2019-01-18 15:48:01 +00:00
foreach ( XmlRpcStructMember MEMBER in mainStruct . Members )
2014-05-05 04:36:45 +00:00
{
switch ( MEMBER . Name )
{
case "status" : R . Status = ( string ) MEMBER . Data . Data ; OSHConsole . WriteLine ( ">" + MEMBER . Name + "= " + MEMBER . Data . Data . ToString ( ) ) ; break ;
case "seconds" : R . Seconds = ( double ) MEMBER . Data . Data ; OSHConsole . WriteLine ( ">" + MEMBER . Name + "= " + MEMBER . Data . Data . ToString ( ) ) ; break ;
case "version" : R . version = ( string ) MEMBER . Data . Data ; OSHConsole . WriteLine ( ">" + MEMBER . Name + "= " + MEMBER . Data . Data . ToString ( ) ) ; break ;
case "url_windows" : R . url_windows = ( string ) MEMBER . Data . Data ; OSHConsole . WriteLine ( ">" + MEMBER . Name + "= " + MEMBER . Data . Data . ToString ( ) ) ; break ;
case "url_linux" : R . url_linux = ( string ) MEMBER . Data . Data ; OSHConsole . WriteLine ( ">" + MEMBER . Name + "= " + MEMBER . Data . Data . ToString ( ) ) ; break ;
case "comments" : R . comments = ( string ) MEMBER . Data . Data ; OSHConsole . WriteLine ( ">" + MEMBER . Name + "= " + MEMBER . Data . Data . ToString ( ) ) ; break ;
}
}
// Return the response to user !!
return R ;
}
}
}
else
{
OSHConsole . WriteLine ( response , DebugCode . Error ) ;
return new MethodResponseError ( "Fail" , response ) ;
}
return new MethodResponseError ( "Fail" , "AutoUpdate call failed !" ) ;
}
/*Checking*/
/// <summary>
/// Check if video file hashes are already stored in the database
/// </summary>
/// <param name="hashes">Array of video file hashes</param>
/// <returns>Status of the call operation. If the call success the response will be 'MethodResponseCheckMovieHash'</returns>
public static IMethodResponse CheckMovieHash ( string [ ] hashes )
{
if ( TOKEN = = "" )
{
OSHConsole . WriteLine ( "Can't do this call, 'token' value not set. Please use Log In method first." , DebugCode . Error ) ;
return new MethodResponseError ( "Fail" , "Can't do this call, 'token' value not set. Please use Log In method first." ) ;
}
// Method call ..
2019-01-13 20:37:13 +00:00
var parms = new List < IXmlRpcValue > ( ) ;
2014-05-05 04:36:45 +00:00
parms . Add ( new XmlRpcValueBasic ( TOKEN ) ) ;
parms . Add ( new XmlRpcValueArray ( hashes ) ) ;
2019-01-13 20:37:13 +00:00
var call = new XmlRpcMethodCall ( "CheckMovieHash" , parms ) ;
2014-05-05 04:36:45 +00:00
OSHConsole . WriteLine ( "Sending CheckMovieHash request to the server ..." , DebugCode . Good ) ;
// Send the request to the server
string response = Utilities . GetStreamString ( Utilities . SendRequest ( XmlRpcGenerator . Generate ( call ) , XML_PRC_USERAGENT ) ) ;
if ( ! response . Contains ( "ERROR:" ) )
{
2019-01-07 23:27:46 +00:00
// No error occur, get and decode the response.
2014-05-05 04:36:45 +00:00
XmlRpcMethodCall [ ] calls = XmlRpcGenerator . DecodeMethodResponse ( response ) ;
if ( calls . Length > 0 )
{
if ( calls [ 0 ] . Parameters . Count > 0 )
{
2019-01-13 20:37:13 +00:00
var mainStruct = ( XmlRpcValueStruct ) calls [ 0 ] . Parameters [ 0 ] ;
2014-05-05 04:36:45 +00:00
// Create the response, we'll need it later
2019-01-13 20:37:13 +00:00
var R = new MethodResponseCheckMovieHash ( ) ;
2014-05-05 04:36:45 +00:00
// To make sure response is not currepted by server, do it in loop
2019-01-18 15:48:01 +00:00
foreach ( XmlRpcStructMember MEMBER in mainStruct . Members )
2014-05-05 04:36:45 +00:00
{
switch ( MEMBER . Name )
{
case "status" : R . Status = ( string ) MEMBER . Data . Data ; OSHConsole . WriteLine ( ">" + MEMBER . Name + "= " + MEMBER . Data . Data . ToString ( ) ) ; break ;
case "seconds" : R . Seconds = ( double ) MEMBER . Data . Data ; OSHConsole . WriteLine ( ">" + MEMBER . Name + "= " + MEMBER . Data . Data . ToString ( ) ) ; break ;
case "data" :
2019-01-13 20:37:13 +00:00
var dataStruct = ( XmlRpcValueStruct ) MEMBER . Data ;
2014-05-05 04:36:45 +00:00
OSHConsole . WriteLine ( ">Data:" ) ;
2019-01-18 15:48:01 +00:00
foreach ( XmlRpcStructMember dataMember in dataStruct . Members )
2014-05-05 04:36:45 +00:00
{
2019-01-13 20:37:13 +00:00
var res = new CheckMovieHashResult ( ) ;
2014-05-05 04:36:45 +00:00
res . Name = dataMember . Name ;
OSHConsole . WriteLine ( " >" + res . Name + ":" ) ;
2019-01-13 20:37:13 +00:00
var movieStruct = ( XmlRpcValueStruct ) dataMember . Data ;
2019-01-18 15:48:01 +00:00
foreach ( XmlRpcStructMember movieMember in movieStruct . Members )
2014-05-05 04:36:45 +00:00
{
switch ( movieMember . Name )
{
case "MovieHash" : res . MovieHash = movieMember . Data . Data . ToString ( ) ; OSHConsole . WriteLine ( " >" + movieMember . Name + "= " + movieMember . Data . Data . ToString ( ) ) ; break ;
case "MovieImdbID" : res . MovieImdbID = movieMember . Data . Data . ToString ( ) ; OSHConsole . WriteLine ( " >" + movieMember . Name + "= " + movieMember . Data . Data . ToString ( ) ) ; break ;
case "MovieName" : res . MovieName = movieMember . Data . Data . ToString ( ) ; OSHConsole . WriteLine ( " >" + movieMember . Name + "= " + movieMember . Data . Data . ToString ( ) ) ; break ;
case "MovieYear" : res . MovieYear = movieMember . Data . Data . ToString ( ) ; OSHConsole . WriteLine ( " >" + movieMember . Name + "= " + movieMember . Data . Data . ToString ( ) ) ; break ;
}
}
R . Results . Add ( res ) ;
}
break ;
}
}
// Return the response to user !!
return R ;
}
}
}
else
{
OSHConsole . WriteLine ( response , DebugCode . Error ) ;
return new MethodResponseError ( "Fail" , response ) ;
}
return new MethodResponseError ( "Fail" , "CheckMovieHash call failed !" ) ;
}
/// <summary>
2019-01-07 23:27:46 +00:00
/// Check if video file hashes are already stored in the database. This method returns matching !MovieImdbID, MovieName, MovieYear, SeriesSeason, SeriesEpisode,
2014-05-05 04:36:45 +00:00
/// MovieKind if available for each $moviehash, always sorted by SeenCount DESC.
/// </summary>
/// <param name="hashes">Array of video file hashes</param>
/// <returns>Status of the call operation. If the call success the response will be 'MethodResponseCheckMovieHash2'</returns>
public static IMethodResponse CheckMovieHash2 ( string [ ] hashes )
{
if ( TOKEN = = "" )
{
OSHConsole . WriteLine ( "Can't do this call, 'token' value not set. Please use Log In method first." , DebugCode . Error ) ;
return new MethodResponseError ( "Fail" , "Can't do this call, 'token' value not set. Please use Log In method first." ) ;
}
// Method call ..
2019-01-13 20:37:13 +00:00
var parms = new List < IXmlRpcValue > ( ) ;
2014-05-05 04:36:45 +00:00
parms . Add ( new XmlRpcValueBasic ( TOKEN ) ) ;
parms . Add ( new XmlRpcValueArray ( hashes ) ) ;
2019-01-13 20:37:13 +00:00
var call = new XmlRpcMethodCall ( "CheckMovieHash2" , parms ) ;
2014-05-05 04:36:45 +00:00
OSHConsole . WriteLine ( "Sending CheckMovieHash2 request to the server ..." , DebugCode . Good ) ;
// Send the request to the server
string response = Utilities . GetStreamString ( Utilities . SendRequest ( XmlRpcGenerator . Generate ( call ) , XML_PRC_USERAGENT ) ) ;
if ( ! response . Contains ( "ERROR:" ) )
{
2019-01-07 23:27:46 +00:00
// No error occur, get and decode the response.
2014-05-05 04:36:45 +00:00
XmlRpcMethodCall [ ] calls = XmlRpcGenerator . DecodeMethodResponse ( response ) ;
if ( calls . Length > 0 )
{
if ( calls [ 0 ] . Parameters . Count > 0 )
{
2019-01-13 20:37:13 +00:00
var mainStruct = ( XmlRpcValueStruct ) calls [ 0 ] . Parameters [ 0 ] ;
2014-05-05 04:36:45 +00:00
// Create the response, we'll need it later
2019-01-13 20:37:13 +00:00
var R = new MethodResponseCheckMovieHash2 ( ) ;
2014-05-05 04:36:45 +00:00
// To make sure response is not currepted by server, do it in loop
2019-01-18 15:48:01 +00:00
foreach ( XmlRpcStructMember MEMBER in mainStruct . Members )
2014-05-05 04:36:45 +00:00
{
switch ( MEMBER . Name )
{
case "status" : R . Status = ( string ) MEMBER . Data . Data ; OSHConsole . WriteLine ( ">" + MEMBER . Name + "= " + MEMBER . Data . Data . ToString ( ) ) ; break ;
case "seconds" : R . Seconds = ( double ) MEMBER . Data . Data ; OSHConsole . WriteLine ( ">" + MEMBER . Name + "= " + MEMBER . Data . Data . ToString ( ) ) ; break ;
case "data" :
2019-01-13 20:37:13 +00:00
var dataStruct = ( XmlRpcValueStruct ) MEMBER . Data ;
2014-05-05 04:36:45 +00:00
OSHConsole . WriteLine ( ">Data:" ) ;
2019-01-18 15:48:01 +00:00
foreach ( XmlRpcStructMember dataMember in dataStruct . Members )
2014-05-05 04:36:45 +00:00
{
2019-01-13 20:37:13 +00:00
var res = new CheckMovieHash2Result ( ) ;
2014-05-05 04:36:45 +00:00
res . Name = dataMember . Name ;
OSHConsole . WriteLine ( " >" + res . Name + ":" ) ;
2019-01-13 20:37:13 +00:00
var dataArray = ( XmlRpcValueArray ) dataMember . Data ;
2014-05-05 04:36:45 +00:00
foreach ( XmlRpcValueStruct movieStruct in dataArray . Values )
{
2019-01-13 20:37:13 +00:00
var d = new CheckMovieHash2Data ( ) ;
2019-01-18 15:48:01 +00:00
foreach ( XmlRpcStructMember movieMember in movieStruct . Members )
2014-05-05 04:36:45 +00:00
{
switch ( movieMember . Name )
{
case "MovieHash" : d . MovieHash = movieMember . Data . Data . ToString ( ) ; OSHConsole . WriteLine ( " >" + movieMember . Name + "= " + movieMember . Data . Data . ToString ( ) ) ; break ;
case "MovieImdbID" : d . MovieImdbID = movieMember . Data . Data . ToString ( ) ; OSHConsole . WriteLine ( " >" + movieMember . Name + "= " + movieMember . Data . Data . ToString ( ) ) ; break ;
case "MovieName" : d . MovieName = movieMember . Data . Data . ToString ( ) ; OSHConsole . WriteLine ( " >" + movieMember . Name + "= " + movieMember . Data . Data . ToString ( ) ) ; break ;
case "MovieYear" : d . MovieYear = movieMember . Data . Data . ToString ( ) ; OSHConsole . WriteLine ( " >" + movieMember . Name + "= " + movieMember . Data . Data . ToString ( ) ) ; break ;
case "MovieKind" : d . MovieKind = movieMember . Data . Data . ToString ( ) ; OSHConsole . WriteLine ( " >" + movieMember . Name + "= " + movieMember . Data . Data . ToString ( ) ) ; break ;
case "SeriesSeason" : d . SeriesSeason = movieMember . Data . Data . ToString ( ) ; OSHConsole . WriteLine ( " >" + movieMember . Name + "= " + movieMember . Data . Data . ToString ( ) ) ; break ;
case "SeriesEpisode" : d . SeriesEpisode = movieMember . Data . Data . ToString ( ) ; OSHConsole . WriteLine ( " >" + movieMember . Name + "= " + movieMember . Data . Data . ToString ( ) ) ; break ;
case "SeenCount" : d . MovieYear = movieMember . Data . Data . ToString ( ) ; OSHConsole . WriteLine ( " >" + movieMember . Name + "= " + movieMember . Data . Data . ToString ( ) ) ; break ;
}
}
res . Items . Add ( d ) ;
}
R . Results . Add ( res ) ;
}
break ;
}
}
// Return the response to user !!
return R ;
}
}
}
else
{
OSHConsole . WriteLine ( response , DebugCode . Error ) ;
return new MethodResponseError ( "Fail" , response ) ;
}
return new MethodResponseError ( "Fail" , "CheckMovieHash2 call failed !" ) ;
}
/// <summary>
2019-01-07 23:27:46 +00:00
/// Check if given subtitle files are already stored in the database
2014-05-05 04:36:45 +00:00
/// </summary>
/// <param name="hashes">Array of subtitle file hashes (MD5 hashes of subtitle file contents) </param>
/// <returns>Status of the call operation. If the call success the response will be 'MethodResponseCheckSubHash'</returns>
public static IMethodResponse CheckSubHash ( string [ ] hashes )
{
if ( TOKEN = = "" )
{
OSHConsole . WriteLine ( "Can't do this call, 'token' value not set. Please use Log In method first." , DebugCode . Error ) ;
return new MethodResponseError ( "Fail" , "Can't do this call, 'token' value not set. Please use Log In method first." ) ;
}
// Method call ..
2019-01-13 20:37:13 +00:00
var parms = new List < IXmlRpcValue > ( ) ;
2014-05-05 04:36:45 +00:00
parms . Add ( new XmlRpcValueBasic ( TOKEN ) ) ;
parms . Add ( new XmlRpcValueArray ( hashes ) ) ;
2019-01-13 20:37:13 +00:00
var call = new XmlRpcMethodCall ( "CheckSubHash" , parms ) ;
2014-05-05 04:36:45 +00:00
OSHConsole . WriteLine ( "Sending CheckSubHash request to the server ..." , DebugCode . Good ) ;
// Send the request to the server
string response = Utilities . GetStreamString ( Utilities . SendRequest ( XmlRpcGenerator . Generate ( call ) , XML_PRC_USERAGENT ) ) ;
if ( ! response . Contains ( "ERROR:" ) )
{
2019-01-07 23:27:46 +00:00
// No error occur, get and decode the response.
2014-05-05 04:36:45 +00:00
XmlRpcMethodCall [ ] calls = XmlRpcGenerator . DecodeMethodResponse ( response ) ;
if ( calls . Length > 0 )
{
if ( calls [ 0 ] . Parameters . Count > 0 )
{
2019-01-13 20:37:13 +00:00
var mainStruct = ( XmlRpcValueStruct ) calls [ 0 ] . Parameters [ 0 ] ;
2014-05-05 04:36:45 +00:00
// Create the response, we'll need it later
2019-01-13 20:37:13 +00:00
var R = new MethodResponseCheckSubHash ( ) ;
2014-05-05 04:36:45 +00:00
// To make sure response is not currepted by server, do it in loop
2019-01-18 15:48:01 +00:00
foreach ( XmlRpcStructMember MEMBER in mainStruct . Members )
2014-05-05 04:36:45 +00:00
{
switch ( MEMBER . Name )
{
case "status" : R . Status = ( string ) MEMBER . Data . Data ; OSHConsole . WriteLine ( ">" + MEMBER . Name + "= " + MEMBER . Data . Data . ToString ( ) ) ; break ;
case "seconds" : R . Seconds = ( double ) MEMBER . Data . Data ; OSHConsole . WriteLine ( ">" + MEMBER . Name + "= " + MEMBER . Data . Data . ToString ( ) ) ; break ;
case "data" :
OSHConsole . WriteLine ( ">Data:" ) ;
2019-01-13 20:37:13 +00:00
var dataStruct = ( XmlRpcValueStruct ) MEMBER . Data ;
2019-01-18 15:48:01 +00:00
foreach ( XmlRpcStructMember dataMember in dataStruct . Members )
2014-05-05 04:36:45 +00:00
{
OSHConsole . WriteLine ( " >" + dataMember . Name + "= " + dataMember . Data . Data . ToString ( ) ) ;
2019-01-13 20:37:13 +00:00
var r = new CheckSubHashResult ( ) ;
2014-05-05 04:36:45 +00:00
r . Hash = dataMember . Name ;
r . SubID = dataMember . Data . Data . ToString ( ) ;
R . Results . Add ( r ) ;
}
break ;
}
}
// Return the response to user !!
return R ;
}
}
}
else
{
OSHConsole . WriteLine ( response , DebugCode . Error ) ;
return new MethodResponseError ( "Fail" , response ) ;
}
return new MethodResponseError ( "Fail" , "CheckSubHash call failed !" ) ;
}
/*Upload*/
/// <summary>
2019-01-07 23:27:46 +00:00
/// Try to upload subtitles, perform pre-upload checking (i.e. check if subtitles already exist on server)
2014-05-05 04:36:45 +00:00
/// </summary>
/// <param name="subs">The subtitle parameters collection to try to upload</param>
/// <returns>Status of the call operation. If the call success the response will be 'MethodResponseTryUploadSubtitles'</returns>
public static IMethodResponse TryUploadSubtitles ( TryUploadSubtitlesParameters [ ] subs )
{
if ( TOKEN = = "" )
{
OSHConsole . WriteLine ( "Can't do this call, 'token' value not set. Please use Log In method first." , DebugCode . Error ) ;
return new MethodResponseError ( "Fail" , "Can't do this call, 'token' value not set. Please use Log In method first." ) ;
}
// Method call ..
2019-01-13 20:37:13 +00:00
var parms = new List < IXmlRpcValue > ( ) ;
2014-05-05 04:36:45 +00:00
parms . Add ( new XmlRpcValueBasic ( TOKEN , XmlRpcBasicValueType . String ) ) ;
2019-01-13 20:37:13 +00:00
var s = new XmlRpcValueStruct ( new List < XmlRpcStructMember > ( ) ) ;
2014-05-05 04:36:45 +00:00
int i = 1 ;
2019-01-13 20:37:13 +00:00
foreach ( var cd in subs )
2014-05-05 04:36:45 +00:00
{
2019-01-13 20:37:13 +00:00
var member = new XmlRpcStructMember ( "cd" + i , null ) ;
var memberStruct = new XmlRpcValueStruct ( new List < XmlRpcStructMember > ( ) ) ;
2014-05-05 04:36:45 +00:00
memberStruct . Members . Add ( new XmlRpcStructMember ( "subhash" , new XmlRpcValueBasic ( cd . subhash ) ) ) ;
memberStruct . Members . Add ( new XmlRpcStructMember ( "subfilename" , new XmlRpcValueBasic ( cd . subfilename ) ) ) ;
memberStruct . Members . Add ( new XmlRpcStructMember ( "moviehash" , new XmlRpcValueBasic ( cd . moviehash ) ) ) ;
memberStruct . Members . Add ( new XmlRpcStructMember ( "moviebytesize" , new XmlRpcValueBasic ( cd . moviebytesize ) ) ) ;
memberStruct . Members . Add ( new XmlRpcStructMember ( "moviefps" , new XmlRpcValueBasic ( cd . moviefps ) ) ) ;
memberStruct . Members . Add ( new XmlRpcStructMember ( "movietimems" , new XmlRpcValueBasic ( cd . movietimems ) ) ) ;
memberStruct . Members . Add ( new XmlRpcStructMember ( "movieframes" , new XmlRpcValueBasic ( cd . movieframes ) ) ) ;
memberStruct . Members . Add ( new XmlRpcStructMember ( "moviefilename" , new XmlRpcValueBasic ( cd . moviefilename ) ) ) ;
member . Data = memberStruct ;
s . Members . Add ( member ) ;
i + + ;
}
parms . Add ( s ) ;
2019-01-13 20:37:13 +00:00
var call = new XmlRpcMethodCall ( "TryUploadSubtitles" , parms ) ;
2014-05-05 04:36:45 +00:00
OSHConsole . WriteLine ( "Sending TryUploadSubtitles request to the server ..." , DebugCode . Good ) ;
// Send the request to the server
string response = Utilities . GetStreamString ( Utilities . SendRequest ( XmlRpcGenerator . Generate ( call ) , XML_PRC_USERAGENT ) ) ;
if ( ! response . Contains ( "ERROR:" ) )
{
2019-01-07 23:27:46 +00:00
// No error occur, get and decode the response.
2014-05-05 04:36:45 +00:00
XmlRpcMethodCall [ ] calls = XmlRpcGenerator . DecodeMethodResponse ( response ) ;
if ( calls . Length > 0 )
{
if ( calls [ 0 ] . Parameters . Count > 0 )
{
2019-01-13 20:37:13 +00:00
var mainStruct = ( XmlRpcValueStruct ) calls [ 0 ] . Parameters [ 0 ] ;
2014-05-05 04:36:45 +00:00
// Create the response, we'll need it later
2019-01-13 20:37:13 +00:00
var R = new MethodResponseTryUploadSubtitles ( ) ;
2014-05-05 04:36:45 +00:00
// To make sure response is not currepted by server, do it in loop
2019-01-18 15:48:01 +00:00
foreach ( XmlRpcStructMember MEMBER in mainStruct . Members )
2014-05-05 04:36:45 +00:00
{
switch ( MEMBER . Name )
{
case "status" : R . Status = ( string ) MEMBER . Data . Data ; OSHConsole . WriteLine ( ">" + MEMBER . Name + "= " + MEMBER . Data . Data . ToString ( ) ) ; break ;
case "seconds" : R . Seconds = ( double ) MEMBER . Data . Data ; OSHConsole . WriteLine ( ">" + MEMBER . Name + "= " + MEMBER . Data . Data . ToString ( ) ) ; break ;
case "alreadyindb" : R . AlreadyInDB = ( int ) MEMBER . Data . Data ; OSHConsole . WriteLine ( ">" + MEMBER . Name + "= " + MEMBER . Data . Data . ToString ( ) ) ; break ;
case "data" :
if ( MEMBER . Data is XmlRpcValueArray )
{
OSHConsole . WriteLine ( "Results: " ) ;
2019-01-13 20:37:13 +00:00
var rarray = ( XmlRpcValueArray ) MEMBER . Data ;
2019-01-18 15:48:01 +00:00
foreach ( IXmlRpcValue subStruct in rarray . Values )
2014-05-05 04:36:45 +00:00
{
if ( subStruct = = null ) continue ;
if ( ! ( subStruct is XmlRpcValueStruct ) ) continue ;
2019-01-13 20:37:13 +00:00
var result = new SubtitleSearchResult ( ) ;
2019-01-18 15:48:01 +00:00
foreach ( XmlRpcStructMember submember in ( ( XmlRpcValueStruct ) subStruct ) . Members )
2014-05-05 04:36:45 +00:00
{
// To avoid errors of arranged info or missing ones, let's do it with switch..
switch ( submember . Name )
{
case "IDMovie" : result . IDMovie = submember . Data . Data . ToString ( ) ; break ;
case "IDMovieImdb" : result . IDMovieImdb = submember . Data . Data . ToString ( ) ; break ;
case "IDSubMovieFile" : result . IDSubMovieFile = submember . Data . Data . ToString ( ) ; break ;
case "IDSubtitle" : result . IDSubtitle = submember . Data . Data . ToString ( ) ; break ;
case "IDSubtitleFile" : result . IDSubtitleFile = submember . Data . Data . ToString ( ) ; break ;
case "ISO639" : result . ISO639 = submember . Data . Data . ToString ( ) ; break ;
case "LanguageName" : result . LanguageName = submember . Data . Data . ToString ( ) ; break ;
case "MovieByteSize" : result . MovieByteSize = submember . Data . Data . ToString ( ) ; break ;
case "MovieHash" : result . MovieHash = submember . Data . Data . ToString ( ) ; break ;
case "MovieImdbRating" : result . MovieImdbRating = submember . Data . Data . ToString ( ) ; break ;
case "MovieName" : result . MovieName = submember . Data . Data . ToString ( ) ; break ;
case "MovieNameEng" : result . MovieNameEng = submember . Data . Data . ToString ( ) ; break ;
case "MovieReleaseName" : result . MovieReleaseName = submember . Data . Data . ToString ( ) ; break ;
case "MovieTimeMS" : result . MovieTimeMS = submember . Data . Data . ToString ( ) ; break ;
case "MovieYear" : result . MovieYear = submember . Data . Data . ToString ( ) ; break ;
case "SubActualCD" : result . SubActualCD = submember . Data . Data . ToString ( ) ; break ;
case "SubAddDate" : result . SubAddDate = submember . Data . Data . ToString ( ) ; break ;
case "SubAuthorComment" : result . SubAuthorComment = submember . Data . Data . ToString ( ) ; break ;
case "SubBad" : result . SubBad = submember . Data . Data . ToString ( ) ; break ;
case "SubDownloadLink" : result . SubDownloadLink = submember . Data . Data . ToString ( ) ; break ;
case "SubDownloadsCnt" : result . SubDownloadsCnt = submember . Data . Data . ToString ( ) ; break ;
case "SubFileName" : result . SubFileName = submember . Data . Data . ToString ( ) ; break ;
case "SubFormat" : result . SubFormat = submember . Data . Data . ToString ( ) ; break ;
case "SubHash" : result . SubHash = submember . Data . Data . ToString ( ) ; break ;
case "SubLanguageID" : result . SubLanguageID = submember . Data . Data . ToString ( ) ; break ;
case "SubRating" : result . SubRating = submember . Data . Data . ToString ( ) ; break ;
case "SubSize" : result . SubSize = submember . Data . Data . ToString ( ) ; break ;
case "SubSumCD" : result . SubSumCD = submember . Data . Data . ToString ( ) ; break ;
case "UserID" : result . UserID = submember . Data . Data . ToString ( ) ; break ;
case "UserNickName" : result . UserNickName = submember . Data . Data . ToString ( ) ; break ;
case "ZipDownloadLink" : result . ZipDownloadLink = submember . Data . Data . ToString ( ) ; break ;
}
}
R . Results . Add ( result ) ;
OSHConsole . WriteLine ( ">" + result . ToString ( ) ) ;
}
}
else // Unknown data ?
{
OSHConsole . WriteLine ( "Data= " + MEMBER . Data . Data . ToString ( ) , DebugCode . Warning ) ;
}
break ;
}
}
// Return the response to user !!
return R ;
}
}
}
else
{
OSHConsole . WriteLine ( response , DebugCode . Error ) ;
return new MethodResponseError ( "Fail" , response ) ;
}
return new MethodResponseError ( "Fail" , "TryUploadSubtitles call failed !" ) ;
}
/// <summary>
2019-01-07 23:27:46 +00:00
/// Upload given subtitles to OSDb server
2014-05-05 04:36:45 +00:00
/// </summary>
/// <param name="info">The pamaters of upload method</param>
/// <returns>Status of the call operation. If the call success the response will be 'MethodResponseUploadSubtitles'</returns>
public static IMethodResponse UploadSubtitles ( UploadSubtitleInfoParameters info )
{
if ( TOKEN = = "" )
{
OSHConsole . WriteLine ( "Can't do this call, 'token' value not set. Please use Log In method first." , DebugCode . Error ) ;
return new MethodResponseError ( "Fail" , "Can't do this call, 'token' value not set. Please use Log In method first." ) ;
}
// Method call ..
2019-01-13 20:37:13 +00:00
var parms = new List < IXmlRpcValue > ( ) ;
2014-05-05 04:36:45 +00:00
parms . Add ( new XmlRpcValueBasic ( TOKEN ) ) ;
// Main struct
2019-01-13 20:37:13 +00:00
var s = new XmlRpcValueStruct ( new List < XmlRpcStructMember > ( ) ) ;
2014-05-05 04:36:45 +00:00
// Base info member as struct
2019-01-13 20:37:13 +00:00
var member = new XmlRpcStructMember ( "baseinfo" , null ) ;
var memberStruct = new XmlRpcValueStruct ( new List < XmlRpcStructMember > ( ) ) ;
2014-05-05 04:36:45 +00:00
memberStruct . Members . Add ( new XmlRpcStructMember ( "idmovieimdb" , new XmlRpcValueBasic ( info . idmovieimdb ) ) ) ;
2019-01-07 23:27:46 +00:00
memberStruct . Members . Add ( new XmlRpcStructMember ( "sublanguageid" , new XmlRpcValueBasic ( info . sublanguageid ) ) ) ;
2014-05-05 04:36:45 +00:00
memberStruct . Members . Add ( new XmlRpcStructMember ( "moviereleasename" , new XmlRpcValueBasic ( info . moviereleasename ) ) ) ;
memberStruct . Members . Add ( new XmlRpcStructMember ( "movieaka" , new XmlRpcValueBasic ( info . movieaka ) ) ) ;
memberStruct . Members . Add ( new XmlRpcStructMember ( "subauthorcomment" , new XmlRpcValueBasic ( info . subauthorcomment ) ) ) ;
// memberStruct.Members.Add(new XmlRpcStructMember("hearingimpaired", new XmlRpcValueBasic(info.hearingimpaired)));
// memberStruct.Members.Add(new XmlRpcStructMember("highdefinition", new XmlRpcValueBasic(info.highdefinition)));
// memberStruct.Members.Add(new XmlRpcStructMember("automatictranslation", new XmlRpcValueBasic(info.automatictranslation)));
member . Data = memberStruct ;
s . Members . Add ( member ) ;
// CDS members
int i = 1 ;
2019-01-18 15:48:01 +00:00
foreach ( UploadSubtitleParameters cd in info . CDS )
2014-05-05 04:36:45 +00:00
{
2019-01-13 20:37:13 +00:00
var member2 = new XmlRpcStructMember ( "cd" + i , null ) ;
var memberStruct2 = new XmlRpcValueStruct ( new List < XmlRpcStructMember > ( ) ) ;
2014-05-05 04:36:45 +00:00
memberStruct2 . Members . Add ( new XmlRpcStructMember ( "subhash" , new XmlRpcValueBasic ( cd . subhash ) ) ) ;
memberStruct2 . Members . Add ( new XmlRpcStructMember ( "subfilename" , new XmlRpcValueBasic ( cd . subfilename ) ) ) ;
memberStruct2 . Members . Add ( new XmlRpcStructMember ( "moviehash" , new XmlRpcValueBasic ( cd . moviehash ) ) ) ;
memberStruct2 . Members . Add ( new XmlRpcStructMember ( "moviebytesize" , new XmlRpcValueBasic ( cd . moviebytesize ) ) ) ;
memberStruct2 . Members . Add ( new XmlRpcStructMember ( "moviefps" , new XmlRpcValueBasic ( cd . moviefps ) ) ) ;
memberStruct2 . Members . Add ( new XmlRpcStructMember ( "movietimems" , new XmlRpcValueBasic ( cd . movietimems ) ) ) ;
memberStruct2 . Members . Add ( new XmlRpcStructMember ( "movieframes" , new XmlRpcValueBasic ( cd . movieframes ) ) ) ;
memberStruct2 . Members . Add ( new XmlRpcStructMember ( "moviefilename" , new XmlRpcValueBasic ( cd . moviefilename ) ) ) ;
memberStruct2 . Members . Add ( new XmlRpcStructMember ( "subcontent" , new XmlRpcValueBasic ( cd . subcontent ) ) ) ;
member2 . Data = memberStruct2 ;
s . Members . Add ( member2 ) ;
i + + ;
}
// add main struct to parameters
parms . Add ( s ) ;
// add user agent
//parms.Add(new XmlRpcValueBasic(XML_PRC_USERAGENT));
2019-01-13 20:37:13 +00:00
var call = new XmlRpcMethodCall ( "UploadSubtitles" , parms ) ;
2014-05-05 04:36:45 +00:00
OSHConsole . WriteLine ( "Sending UploadSubtitles request to the server ..." , DebugCode . Good ) ;
// Send the request to the server
string response = Utilities . GetStreamString ( Utilities . SendRequest ( XmlRpcGenerator . Generate ( call ) , XML_PRC_USERAGENT ) ) ;
if ( ! response . Contains ( "ERROR:" ) )
{
2019-01-07 23:27:46 +00:00
// No error occur, get and decode the response.
2014-05-05 04:36:45 +00:00
XmlRpcMethodCall [ ] calls = XmlRpcGenerator . DecodeMethodResponse ( response ) ;
if ( calls . Length > 0 )
{
if ( calls [ 0 ] . Parameters . Count > 0 )
{
2019-01-13 20:37:13 +00:00
var mainStruct = ( XmlRpcValueStruct ) calls [ 0 ] . Parameters [ 0 ] ;
2014-05-05 04:36:45 +00:00
// Create the response, we'll need it later
2019-01-13 20:37:13 +00:00
var R = new MethodResponseUploadSubtitles ( ) ;
2014-05-05 04:36:45 +00:00
// To make sure response is not currepted by server, do it in loop
2019-01-18 15:48:01 +00:00
foreach ( XmlRpcStructMember MEMBER in mainStruct . Members )
2014-05-05 04:36:45 +00:00
{
switch ( MEMBER . Name )
{
case "status" : R . Status = ( string ) MEMBER . Data . Data ; OSHConsole . WriteLine ( ">" + MEMBER . Name + "= " + MEMBER . Data . Data . ToString ( ) ) ; break ;
case "seconds" : R . Seconds = ( double ) MEMBER . Data . Data ; OSHConsole . WriteLine ( ">" + MEMBER . Name + "= " + MEMBER . Data . Data . ToString ( ) ) ; break ;
case "data" : R . Data = ( string ) MEMBER . Data . Data ; OSHConsole . WriteLine ( ">" + MEMBER . Name + "= " + MEMBER . Data . Data . ToString ( ) ) ; break ;
case "subtitles" : R . SubTitles = ( bool ) MEMBER . Data . Data ; OSHConsole . WriteLine ( ">" + MEMBER . Name + "= " + MEMBER . Data . Data . ToString ( ) ) ; break ;
}
}
// Return the response to user !!
return R ;
}
}
}
else
{
OSHConsole . WriteLine ( response , DebugCode . Error ) ;
return new MethodResponseError ( "Fail" , response ) ;
}
return new MethodResponseError ( "Fail" , "UploadSubtitles call failed !" ) ;
}
}
}