OpenSubtitles.cs 165 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744
  1. /* This file is part of OpenSubtitles Handler
  2. A library that handle OpenSubtitles.org XML-RPC methods.
  3. Copyright © Ala Ibrahim Hadid 2013
  4. This program is free software: you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation, either version 3 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program. If not, see <http://www.gnu.org/licenses/>.
  14. */
  15. using System;
  16. using System.Collections.Generic;
  17. using System.Globalization;
  18. using System.IO;
  19. using System.Text;
  20. using System.Threading;
  21. using System.Threading.Tasks;
  22. using OpenSubtitlesHandler.Console;
  23. using XmlRpcHandler;
  24. namespace OpenSubtitlesHandler
  25. {
  26. /// <summary>
  27. /// The core of the OpenSubtitles Handler library. All members are static.
  28. /// </summary>
  29. public sealed class OpenSubtitles
  30. {
  31. private static string XML_PRC_USERAGENT = "";
  32. // This is session id after log in, important value and MUST be set by LogIn before any other call.
  33. private static string TOKEN = "";
  34. /// <summary>
  35. /// Set the useragent value. This must be called before doing anything else.
  36. /// </summary>
  37. /// <param name="agent">The useragent value</param>
  38. public static void SetUserAgent(string agent)
  39. {
  40. XML_PRC_USERAGENT = agent;
  41. }
  42. /*Session handling*/
  43. /// <summary>
  44. /// Send a LogIn request, this must be called before anything else in this class.
  45. /// </summary>
  46. /// <param name="userName">The user name of OpenSubtitles</param>
  47. /// <param name="password">The password</param>
  48. /// <param name="language">The language, usally en</param>
  49. /// <returns>Status of the login operation</returns>
  50. public static IMethodResponse LogIn(string userName, string password, string language)
  51. {
  52. // Method call ..
  53. var parms = new List<IXmlRpcValue>();
  54. parms.Add(new XmlRpcValueBasic(userName));
  55. parms.Add(new XmlRpcValueBasic(password));
  56. parms.Add(new XmlRpcValueBasic(language));
  57. parms.Add(new XmlRpcValueBasic(XML_PRC_USERAGENT));
  58. var call = new XmlRpcMethodCall("LogIn", parms);
  59. OSHConsole.WriteLine("Sending LogIn request to the server ...", DebugCode.Good);
  60. //File.WriteAllText(".\\request.txt", Encoding.UTF8.GetString(XmlRpcGenerator.Generate(call)));
  61. // Send the request to the server
  62. string response = Utilities.GetStreamString(Utilities.SendRequest(XmlRpcGenerator.Generate(call), XML_PRC_USERAGENT));
  63. if (!response.Contains("ERROR:"))
  64. {
  65. // No error occur, get and decode the response. We expect Struct here.
  66. XmlRpcMethodCall[] calls = XmlRpcGenerator.DecodeMethodResponse(response);
  67. if (calls.Length > 0)
  68. {
  69. if (calls[0].Parameters.Count > 0)
  70. {
  71. var mainStruct = (XmlRpcValueStruct)calls[0].Parameters[0];
  72. var re = new MethodResponseLogIn("Success", "Log in successful.");
  73. foreach (XmlRpcStructMember MEMBER in mainStruct.Members)
  74. {
  75. switch (MEMBER.Name)
  76. {
  77. case "token": re.Token = TOKEN = MEMBER.Data.Data.ToString(); OSHConsole.WriteLine(MEMBER.Name + "= " + MEMBER.Data.Data.ToString()); break;
  78. case "seconds": re.Seconds = (double)MEMBER.Data.Data; OSHConsole.WriteLine(MEMBER.Name + "= " + MEMBER.Data.Data.ToString()); break;
  79. case "status": re.Status = MEMBER.Data.Data.ToString(); OSHConsole.WriteLine(MEMBER.Name + "= " + MEMBER.Data.Data.ToString()); break;
  80. }
  81. }
  82. return re;
  83. }
  84. }
  85. }
  86. else
  87. {
  88. OSHConsole.WriteLine(response, DebugCode.Error);
  89. return new MethodResponseError("Fail", response);
  90. }
  91. return new MethodResponseError("Fail", "Log in failed !");
  92. }
  93. public static async Task<IMethodResponse> LogInAsync(string userName, string password, string language, CancellationToken cancellationToken)
  94. {
  95. // Method call ..
  96. var parms = new List<IXmlRpcValue>();
  97. parms.Add(new XmlRpcValueBasic(userName));
  98. parms.Add(new XmlRpcValueBasic(password));
  99. parms.Add(new XmlRpcValueBasic(language));
  100. parms.Add(new XmlRpcValueBasic(XML_PRC_USERAGENT));
  101. var call = new XmlRpcMethodCall("LogIn", parms);
  102. OSHConsole.WriteLine("Sending LogIn request to the server ...", DebugCode.Good);
  103. //File.WriteAllText(".\\request.txt", Encoding.UTF8.GetString(XmlRpcGenerator.Generate(call)));
  104. // Send the request to the server
  105. var stream = await Utilities.SendRequestAsync(XmlRpcGenerator.Generate(call), XML_PRC_USERAGENT, cancellationToken)
  106. .ConfigureAwait(false);
  107. string response = Utilities.GetStreamString(stream);
  108. if (!response.Contains("ERROR:"))
  109. {
  110. // No error occur, get and decode the response. We expect Struct here.
  111. XmlRpcMethodCall[] calls = XmlRpcGenerator.DecodeMethodResponse(response);
  112. if (calls.Length > 0)
  113. {
  114. if (calls[0].Parameters.Count > 0)
  115. {
  116. var mainStruct = (XmlRpcValueStruct)calls[0].Parameters[0];
  117. var re = new MethodResponseLogIn("Success", "Log in successful.");
  118. foreach (XmlRpcStructMember MEMBER in mainStruct.Members)
  119. {
  120. switch (MEMBER.Name)
  121. {
  122. case "token":
  123. re.Token = TOKEN = MEMBER.Data.Data.ToString();
  124. OSHConsole.WriteLine(MEMBER.Name + "= " + MEMBER.Data.Data.ToString());
  125. break;
  126. case "seconds":
  127. re.Seconds = double.Parse(MEMBER.Data.Data.ToString(), CultureInfo.InvariantCulture);
  128. OSHConsole.WriteLine(MEMBER.Name + "= " + MEMBER.Data.Data.ToString());
  129. break;
  130. case "status":
  131. re.Status = MEMBER.Data.Data.ToString();
  132. OSHConsole.WriteLine(MEMBER.Name + "= " + MEMBER.Data.Data.ToString());
  133. break;
  134. }
  135. }
  136. return re;
  137. }
  138. }
  139. }
  140. else
  141. {
  142. OSHConsole.WriteLine(response, DebugCode.Error);
  143. return new MethodResponseError("Fail", response);
  144. }
  145. return new MethodResponseError("Fail", "Log in failed !");
  146. }
  147. /// <summary>
  148. /// Log out from the server. Call this to terminate the session.
  149. /// </summary>
  150. /// <returns></returns>
  151. public static IMethodResponse LogOut()
  152. {
  153. if (TOKEN == "")
  154. {
  155. OSHConsole.WriteLine("Can't do this call, 'token' value not set. Please use Log In method first.", DebugCode.Error);
  156. return new MethodResponseError("Fail", "Can't do this call, 'token' value not set. Please use Log In method first.");
  157. }
  158. // Method call ..
  159. var parms = new List<IXmlRpcValue>();
  160. parms.Add(new XmlRpcValueBasic(TOKEN, XmlRpcBasicValueType.String));
  161. var call = new XmlRpcMethodCall("LogOut", parms);
  162. OSHConsole.WriteLine("Sending LogOut request to the server ...", DebugCode.Good);
  163. // Send the request to the server
  164. string response = Utilities.GetStreamString(Utilities.SendRequest(XmlRpcGenerator.Generate(call), XML_PRC_USERAGENT));
  165. if (!response.Contains("ERROR:"))
  166. {
  167. // No error occur, get and decode the response. We expect Struct here.
  168. XmlRpcMethodCall[] calls = XmlRpcGenerator.DecodeMethodResponse(response);
  169. if (calls.Length > 0)
  170. {
  171. if (calls[0].Parameters.Count > 0)
  172. {
  173. var strct = (XmlRpcValueStruct)calls[0].Parameters[0];
  174. OSHConsole.WriteLine("STATUS=" + ((XmlRpcValueBasic)strct.Members[0].Data).Data.ToString());
  175. OSHConsole.WriteLine("SECONDS=" + ((XmlRpcValueBasic)strct.Members[1].Data).Data.ToString());
  176. var re = new MethodResponseLogIn("Success", "Log out successful.");
  177. re.Status = ((XmlRpcValueBasic)strct.Members[0].Data).Data.ToString();
  178. re.Seconds = (double)((XmlRpcValueBasic)strct.Members[1].Data).Data;
  179. return re;
  180. }
  181. }
  182. }
  183. else
  184. {
  185. OSHConsole.WriteLine(response, DebugCode.Error);
  186. return new MethodResponseError("Fail", response);
  187. }
  188. return new MethodResponseError("Fail", "Log out failed !");
  189. }
  190. /// <summary>
  191. /// keep-alive user's session, verify token/session validity
  192. /// </summary>
  193. /// <returns>Status of the call operation</returns>
  194. public static IMethodResponse NoOperation()
  195. {
  196. if (TOKEN == "")
  197. {
  198. OSHConsole.WriteLine("Can't do this call, 'token' value not set. Please use Log In method first.", DebugCode.Error);
  199. return new MethodResponseError("Fail", "Can't do this call, 'token' value not set. Please use Log In method first.");
  200. }
  201. // Method call ..
  202. var parms = new List<IXmlRpcValue>();
  203. parms.Add(new XmlRpcValueBasic(TOKEN, XmlRpcBasicValueType.String));
  204. parms.Add(new XmlRpcValueBasic(XML_PRC_USERAGENT, XmlRpcBasicValueType.String));
  205. var call = new XmlRpcMethodCall("NoOperation", parms);
  206. OSHConsole.WriteLine("Sending NoOperation request to the server ...", DebugCode.Good);
  207. // Send the request to the server
  208. string response = Utilities.GetStreamString(Utilities.SendRequest(XmlRpcGenerator.Generate(call), XML_PRC_USERAGENT));
  209. if (!response.Contains("ERROR:"))
  210. {
  211. // No error occur, get and decode the response. We expect Struct here.
  212. XmlRpcMethodCall[] calls = XmlRpcGenerator.DecodeMethodResponse(response);
  213. if (calls.Length > 0)
  214. {
  215. if (calls[0].Parameters.Count > 0)
  216. {
  217. var R = new MethodResponseNoOperation();
  218. var mainStruct = (XmlRpcValueStruct)calls[0].Parameters[0];
  219. // To make sure response is not currepted by server, do it in loop
  220. foreach (XmlRpcStructMember MEMBER in mainStruct.Members)
  221. {
  222. switch (MEMBER.Name)
  223. {
  224. case "status": R.Status = (string)MEMBER.Data.Data; OSHConsole.WriteLine(MEMBER.Name + "= " + MEMBER.Data.Data); break;
  225. case "seconds": R.Seconds = (double)MEMBER.Data.Data; OSHConsole.WriteLine(MEMBER.Name + "= " + MEMBER.Data.Data); break;
  226. case "download_limits":
  227. var dlStruct = (XmlRpcValueStruct)MEMBER.Data;
  228. foreach (XmlRpcStructMember dlmember in dlStruct.Members)
  229. {
  230. OSHConsole.WriteLine(" >" + dlmember.Name + "= " + dlmember.Data.Data.ToString());
  231. switch (dlmember.Name)
  232. {
  233. case "global_wrh_download_limit": R.global_wrh_download_limit = dlmember.Data.Data.ToString(); break;
  234. case "client_ip": R.client_ip = dlmember.Data.Data.ToString(); break;
  235. case "limit_check_by": R.limit_check_by = dlmember.Data.Data.ToString(); break;
  236. case "client_24h_download_count": R.client_24h_download_count = dlmember.Data.Data.ToString(); break;
  237. case "client_downlaod_quota": R.client_downlaod_quota = dlmember.Data.Data.ToString(); break;
  238. case "client_24h_download_limit": R.client_24h_download_limit = dlmember.Data.Data.ToString(); break;
  239. }
  240. }
  241. break;
  242. }
  243. }
  244. return R;
  245. }
  246. }
  247. }
  248. else
  249. {
  250. OSHConsole.WriteLine(response, DebugCode.Error);
  251. return new MethodResponseError("Fail", response);
  252. }
  253. return new MethodResponseError("Fail", "NoOperation call failed !");
  254. }
  255. /*Search and download*/
  256. /// <summary>
  257. /// Search for subtitle files matching your videos using either video file hashes or IMDb IDs.
  258. /// </summary>
  259. /// <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>
  260. /// <returns>Status of the call operation. If the call success the response will be 'MethodResponseSubtitleSearch'</returns>
  261. public static IMethodResponse SearchSubtitles(SubtitleSearchParameters[] parameters)
  262. {
  263. if (TOKEN == "")
  264. {
  265. OSHConsole.WriteLine("Can't do this call, 'token' value not set. Please use Log In method first.", DebugCode.Error);
  266. return new MethodResponseError("Fail", "Can't do this call, 'token' value not set. Please use Log In method first.");
  267. }
  268. if (parameters == null)
  269. {
  270. OSHConsole.UpdateLine("No subtitle search parameter passed !!", DebugCode.Error);
  271. return new MethodResponseError("Fail", "No subtitle search parameter passed");
  272. }
  273. if (parameters.Length == 0)
  274. {
  275. OSHConsole.UpdateLine("No subtitle search parameter passed !!", DebugCode.Error);
  276. return new MethodResponseError("Fail", "No subtitle search parameter passed");
  277. }
  278. // Method call ..
  279. var parms = new List<IXmlRpcValue>();
  280. // Add token param
  281. parms.Add(new XmlRpcValueBasic(TOKEN, XmlRpcBasicValueType.String));
  282. // Add subtitle search parameters. Each one will be like 'array' of structs.
  283. var array = new XmlRpcValueArray();
  284. foreach (SubtitleSearchParameters param in parameters)
  285. {
  286. var strct = new XmlRpcValueStruct(new List<XmlRpcStructMember>());
  287. // sublanguageid member
  288. var member = new XmlRpcStructMember("sublanguageid",
  289. new XmlRpcValueBasic(param.SubLangaugeID, XmlRpcBasicValueType.String));
  290. strct.Members.Add(member);
  291. // moviehash member
  292. if (param.MovieHash.Length > 0 && param.MovieByteSize > 0)
  293. {
  294. member = new XmlRpcStructMember("moviehash",
  295. new XmlRpcValueBasic(param.MovieHash, XmlRpcBasicValueType.String));
  296. strct.Members.Add(member);
  297. // moviehash member
  298. member = new XmlRpcStructMember("moviebytesize",
  299. new XmlRpcValueBasic(param.MovieByteSize, XmlRpcBasicValueType.Int));
  300. strct.Members.Add(member);
  301. }
  302. if (param.Query.Length > 0)
  303. {
  304. member = new XmlRpcStructMember("query",
  305. new XmlRpcValueBasic(param.Query, XmlRpcBasicValueType.String));
  306. strct.Members.Add(member);
  307. }
  308. if (param.Episode.Length > 0 && param.Season.Length > 0)
  309. {
  310. member = new XmlRpcStructMember("season",
  311. new XmlRpcValueBasic(param.Season, XmlRpcBasicValueType.String));
  312. strct.Members.Add(member);
  313. member = new XmlRpcStructMember("episode",
  314. new XmlRpcValueBasic(param.Episode, XmlRpcBasicValueType.String));
  315. strct.Members.Add(member);
  316. }
  317. // imdbid member
  318. if (param.IMDbID.Length > 0)
  319. {
  320. member = new XmlRpcStructMember("imdbid",
  321. new XmlRpcValueBasic(param.IMDbID, XmlRpcBasicValueType.String));
  322. strct.Members.Add(member);
  323. }
  324. // Add the struct to the array
  325. array.Values.Add(strct);
  326. }
  327. // Add the array to the parameters
  328. parms.Add(array);
  329. // Call !
  330. var call = new XmlRpcMethodCall("SearchSubtitles", parms);
  331. OSHConsole.WriteLine("Sending SearchSubtitles request to the server ...", DebugCode.Good);
  332. // Send the request to the server
  333. string response = Utilities.GetStreamString(Utilities.SendRequest(XmlRpcGenerator.Generate(call), XML_PRC_USERAGENT));
  334. if (!response.Contains("ERROR:"))
  335. {
  336. // No error occur, get and decode the response.
  337. XmlRpcMethodCall[] calls = XmlRpcGenerator.DecodeMethodResponse(response);
  338. if (calls.Length > 0)
  339. {
  340. if (calls[0].Parameters.Count > 0)
  341. {
  342. // We expect Struct of 3 members:
  343. //* the first is status
  344. //* the second is [array of structs, each one includes subtitle file].
  345. //* the third is [double basic value] represent seconds token by server.
  346. var mainStruct = (XmlRpcValueStruct)calls[0].Parameters[0];
  347. // Create the response, we'll need it later
  348. var R = new MethodResponseSubtitleSearch();
  349. // To make sure response is not currepted by server, do it in loop
  350. foreach (XmlRpcStructMember MEMBER in mainStruct.Members)
  351. {
  352. if (MEMBER.Name == "status")
  353. {
  354. R.Status = (string)MEMBER.Data.Data;
  355. OSHConsole.WriteLine("Status= " + R.Status);
  356. }
  357. else if (MEMBER.Name == "seconds")
  358. {
  359. R.Seconds = (double)MEMBER.Data.Data;
  360. OSHConsole.WriteLine("Seconds= " + R.Seconds);
  361. }
  362. else if (MEMBER.Name == "data")
  363. {
  364. if (MEMBER.Data is XmlRpcValueArray)
  365. {
  366. OSHConsole.WriteLine("Search results: ");
  367. var rarray = (XmlRpcValueArray)MEMBER.Data;
  368. foreach (IXmlRpcValue subStruct in rarray.Values)
  369. {
  370. if (subStruct == null) continue;
  371. if (!(subStruct is XmlRpcValueStruct)) continue;
  372. var result = new SubtitleSearchResult();
  373. foreach (XmlRpcStructMember submember in ((XmlRpcValueStruct)subStruct).Members)
  374. {
  375. // To avoid errors of arranged info or missing ones, let's do it with switch..
  376. switch (submember.Name)
  377. {
  378. case "IDMovie": result.IDMovie = submember.Data.Data.ToString(); break;
  379. case "IDMovieImdb": result.IDMovieImdb = submember.Data.Data.ToString(); break;
  380. case "IDSubMovieFile": result.IDSubMovieFile = submember.Data.Data.ToString(); break;
  381. case "IDSubtitle": result.IDSubtitle = submember.Data.Data.ToString(); break;
  382. case "IDSubtitleFile": result.IDSubtitleFile = submember.Data.Data.ToString(); break;
  383. case "ISO639": result.ISO639 = submember.Data.Data.ToString(); break;
  384. case "LanguageName": result.LanguageName = submember.Data.Data.ToString(); break;
  385. case "MovieByteSize": result.MovieByteSize = submember.Data.Data.ToString(); break;
  386. case "MovieHash": result.MovieHash = submember.Data.Data.ToString(); break;
  387. case "MovieImdbRating": result.MovieImdbRating = submember.Data.Data.ToString(); break;
  388. case "MovieName": result.MovieName = submember.Data.Data.ToString(); break;
  389. case "MovieNameEng": result.MovieNameEng = submember.Data.Data.ToString(); break;
  390. case "MovieReleaseName": result.MovieReleaseName = submember.Data.Data.ToString(); break;
  391. case "MovieTimeMS": result.MovieTimeMS = submember.Data.Data.ToString(); break;
  392. case "MovieYear": result.MovieYear = submember.Data.Data.ToString(); break;
  393. case "SubActualCD": result.SubActualCD = submember.Data.Data.ToString(); break;
  394. case "SubAddDate": result.SubAddDate = submember.Data.Data.ToString(); break;
  395. case "SubAuthorComment": result.SubAuthorComment = submember.Data.Data.ToString(); break;
  396. case "SubBad": result.SubBad = submember.Data.Data.ToString(); break;
  397. case "SubDownloadLink": result.SubDownloadLink = submember.Data.Data.ToString(); break;
  398. case "SubDownloadsCnt": result.SubDownloadsCnt = submember.Data.Data.ToString(); break;
  399. case "SeriesEpisode": result.SeriesEpisode = submember.Data.Data.ToString(); break;
  400. case "SeriesSeason": result.SeriesSeason = submember.Data.Data.ToString(); break;
  401. case "SubFileName": result.SubFileName = submember.Data.Data.ToString(); break;
  402. case "SubFormat": result.SubFormat = submember.Data.Data.ToString(); break;
  403. case "SubHash": result.SubHash = submember.Data.Data.ToString(); break;
  404. case "SubLanguageID": result.SubLanguageID = submember.Data.Data.ToString(); break;
  405. case "SubRating": result.SubRating = submember.Data.Data.ToString(); break;
  406. case "SubSize": result.SubSize = submember.Data.Data.ToString(); break;
  407. case "SubSumCD": result.SubSumCD = submember.Data.Data.ToString(); break;
  408. case "UserID": result.UserID = submember.Data.Data.ToString(); break;
  409. case "UserNickName": result.UserNickName = submember.Data.Data.ToString(); break;
  410. case "ZipDownloadLink": result.ZipDownloadLink = submember.Data.Data.ToString(); break;
  411. }
  412. }
  413. R.Results.Add(result);
  414. OSHConsole.WriteLine(">" + result.ToString());
  415. }
  416. }
  417. else// Unknown data ?
  418. {
  419. OSHConsole.WriteLine("Data= " + MEMBER.Data.Data.ToString(), DebugCode.Warning);
  420. }
  421. }
  422. }
  423. // Return the response to user !!
  424. return R;
  425. }
  426. }
  427. }
  428. else
  429. {
  430. OSHConsole.WriteLine(response, DebugCode.Error);
  431. return new MethodResponseError("Fail", response);
  432. }
  433. return new MethodResponseError("Fail", "Search Subtitles call failed !");
  434. }
  435. public static async Task<IMethodResponse> SearchSubtitlesAsync(SubtitleSearchParameters[] parameters, CancellationToken cancellationToken)
  436. {
  437. if (TOKEN == "")
  438. {
  439. OSHConsole.WriteLine("Can't do this call, 'token' value not set. Please use Log In method first.", DebugCode.Error);
  440. return new MethodResponseError("Fail", "Can't do this call, 'token' value not set. Please use Log In method first.");
  441. }
  442. if (parameters == null)
  443. {
  444. OSHConsole.UpdateLine("No subtitle search parameter passed !!", DebugCode.Error);
  445. return new MethodResponseError("Fail", "No subtitle search parameter passed");
  446. }
  447. if (parameters.Length == 0)
  448. {
  449. OSHConsole.UpdateLine("No subtitle search parameter passed !!", DebugCode.Error);
  450. return new MethodResponseError("Fail", "No subtitle search parameter passed");
  451. }
  452. // Method call ..
  453. var parms = new List<IXmlRpcValue>();
  454. // Add token param
  455. parms.Add(new XmlRpcValueBasic(TOKEN, XmlRpcBasicValueType.String));
  456. // Add subtitle search parameters. Each one will be like 'array' of structs.
  457. var array = new XmlRpcValueArray();
  458. foreach (SubtitleSearchParameters param in parameters)
  459. {
  460. var strct = new XmlRpcValueStruct(new List<XmlRpcStructMember>());
  461. // sublanguageid member
  462. var member = new XmlRpcStructMember("sublanguageid",
  463. new XmlRpcValueBasic(param.SubLangaugeID, XmlRpcBasicValueType.String));
  464. strct.Members.Add(member);
  465. // moviehash member
  466. if (param.MovieHash.Length > 0 && param.MovieByteSize > 0)
  467. {
  468. member = new XmlRpcStructMember("moviehash",
  469. new XmlRpcValueBasic(param.MovieHash, XmlRpcBasicValueType.String));
  470. strct.Members.Add(member);
  471. // moviehash member
  472. member = new XmlRpcStructMember("moviebytesize",
  473. new XmlRpcValueBasic(param.MovieByteSize, XmlRpcBasicValueType.Int));
  474. strct.Members.Add(member);
  475. }
  476. if (param.Query.Length > 0)
  477. {
  478. member = new XmlRpcStructMember("query",
  479. new XmlRpcValueBasic(param.Query, XmlRpcBasicValueType.String));
  480. strct.Members.Add(member);
  481. }
  482. if (param.Episode.Length > 0 && param.Season.Length > 0)
  483. {
  484. member = new XmlRpcStructMember("season",
  485. new XmlRpcValueBasic(param.Season, XmlRpcBasicValueType.String));
  486. strct.Members.Add(member);
  487. member = new XmlRpcStructMember("episode",
  488. new XmlRpcValueBasic(param.Episode, XmlRpcBasicValueType.String));
  489. strct.Members.Add(member);
  490. }
  491. // imdbid member
  492. if (param.IMDbID.Length > 0)
  493. {
  494. member = new XmlRpcStructMember("imdbid",
  495. new XmlRpcValueBasic(param.IMDbID, XmlRpcBasicValueType.String));
  496. strct.Members.Add(member);
  497. }
  498. // Add the struct to the array
  499. array.Values.Add(strct);
  500. }
  501. // Add the array to the parameters
  502. parms.Add(array);
  503. // Call !
  504. var call = new XmlRpcMethodCall("SearchSubtitles", parms);
  505. OSHConsole.WriteLine("Sending SearchSubtitles request to the server ...", DebugCode.Good);
  506. // Send the request to the server
  507. string response = Utilities.GetStreamString(await Utilities.SendRequestAsync(XmlRpcGenerator.Generate(call), XML_PRC_USERAGENT, cancellationToken).ConfigureAwait(false));
  508. if (!response.Contains("ERROR:"))
  509. {
  510. // No error occur, get and decode the response.
  511. XmlRpcMethodCall[] calls = XmlRpcGenerator.DecodeMethodResponse(response);
  512. if (calls.Length > 0)
  513. {
  514. if (calls[0].Parameters.Count > 0)
  515. {
  516. // We expect Struct of 3 members:
  517. //* the first is status
  518. //* the second is [array of structs, each one includes subtitle file].
  519. //* the third is [double basic value] represent seconds token by server.
  520. var mainStruct = (XmlRpcValueStruct)calls[0].Parameters[0];
  521. // Create the response, we'll need it later
  522. var R = new MethodResponseSubtitleSearch();
  523. // To make sure response is not currepted by server, do it in loop
  524. foreach (XmlRpcStructMember MEMBER in mainStruct.Members)
  525. {
  526. if (MEMBER.Name == "status")
  527. {
  528. R.Status = (string)MEMBER.Data.Data;
  529. OSHConsole.WriteLine("Status= " + R.Status);
  530. }
  531. else if (MEMBER.Name == "seconds")
  532. {
  533. R.Seconds = (double)MEMBER.Data.Data;
  534. OSHConsole.WriteLine("Seconds= " + R.Seconds);
  535. }
  536. else if (MEMBER.Name == "data")
  537. {
  538. if (MEMBER.Data is XmlRpcValueArray)
  539. {
  540. OSHConsole.WriteLine("Search results: ");
  541. var rarray = (XmlRpcValueArray)MEMBER.Data;
  542. foreach (IXmlRpcValue subStruct in rarray.Values)
  543. {
  544. if (subStruct == null) continue;
  545. if (!(subStruct is XmlRpcValueStruct)) continue;
  546. var result = new SubtitleSearchResult();
  547. foreach (XmlRpcStructMember submember in ((XmlRpcValueStruct)subStruct).Members)
  548. {
  549. // To avoid errors of arranged info or missing ones, let's do it with switch..
  550. switch (submember.Name)
  551. {
  552. case "IDMovie": result.IDMovie = submember.Data.Data.ToString(); break;
  553. case "IDMovieImdb": result.IDMovieImdb = submember.Data.Data.ToString(); break;
  554. case "IDSubMovieFile": result.IDSubMovieFile = submember.Data.Data.ToString(); break;
  555. case "IDSubtitle": result.IDSubtitle = submember.Data.Data.ToString(); break;
  556. case "IDSubtitleFile": result.IDSubtitleFile = submember.Data.Data.ToString(); break;
  557. case "ISO639": result.ISO639 = submember.Data.Data.ToString(); break;
  558. case "LanguageName": result.LanguageName = submember.Data.Data.ToString(); break;
  559. case "MovieByteSize": result.MovieByteSize = submember.Data.Data.ToString(); break;
  560. case "MovieHash": result.MovieHash = submember.Data.Data.ToString(); break;
  561. case "MovieImdbRating": result.MovieImdbRating = submember.Data.Data.ToString(); break;
  562. case "MovieName": result.MovieName = submember.Data.Data.ToString(); break;
  563. case "MovieNameEng": result.MovieNameEng = submember.Data.Data.ToString(); break;
  564. case "MovieReleaseName": result.MovieReleaseName = submember.Data.Data.ToString(); break;
  565. case "MovieTimeMS": result.MovieTimeMS = submember.Data.Data.ToString(); break;
  566. case "MovieYear": result.MovieYear = submember.Data.Data.ToString(); break;
  567. case "SubActualCD": result.SubActualCD = submember.Data.Data.ToString(); break;
  568. case "SubAddDate": result.SubAddDate = submember.Data.Data.ToString(); break;
  569. case "SubAuthorComment": result.SubAuthorComment = submember.Data.Data.ToString(); break;
  570. case "SubBad": result.SubBad = submember.Data.Data.ToString(); break;
  571. case "SubDownloadLink": result.SubDownloadLink = submember.Data.Data.ToString(); break;
  572. case "SubDownloadsCnt": result.SubDownloadsCnt = submember.Data.Data.ToString(); break;
  573. case "SeriesEpisode": result.SeriesEpisode = submember.Data.Data.ToString(); break;
  574. case "SeriesSeason": result.SeriesSeason = submember.Data.Data.ToString(); break;
  575. case "SubFileName": result.SubFileName = submember.Data.Data.ToString(); break;
  576. case "SubFormat": result.SubFormat = submember.Data.Data.ToString(); break;
  577. case "SubHash": result.SubHash = submember.Data.Data.ToString(); break;
  578. case "SubLanguageID": result.SubLanguageID = submember.Data.Data.ToString(); break;
  579. case "SubRating": result.SubRating = submember.Data.Data.ToString(); break;
  580. case "SubSize": result.SubSize = submember.Data.Data.ToString(); break;
  581. case "SubSumCD": result.SubSumCD = submember.Data.Data.ToString(); break;
  582. case "UserID": result.UserID = submember.Data.Data.ToString(); break;
  583. case "UserNickName": result.UserNickName = submember.Data.Data.ToString(); break;
  584. case "ZipDownloadLink": result.ZipDownloadLink = submember.Data.Data.ToString(); break;
  585. }
  586. }
  587. R.Results.Add(result);
  588. OSHConsole.WriteLine(">" + result.ToString());
  589. }
  590. }
  591. else// Unknown data ?
  592. {
  593. OSHConsole.WriteLine("Data= " + MEMBER.Data.Data.ToString(), DebugCode.Warning);
  594. }
  595. }
  596. }
  597. // Return the response to user !!
  598. return R;
  599. }
  600. }
  601. }
  602. else
  603. {
  604. OSHConsole.WriteLine(response, DebugCode.Error);
  605. return new MethodResponseError("Fail", response);
  606. }
  607. return new MethodResponseError("Fail", "Search Subtitles call failed !");
  608. }
  609. /// <summary>
  610. /// Download subtitle file(s)
  611. /// </summary>
  612. /// <param name="subIDS">The subtitle IDS (an array of IDSubtitleFile value that given by server as SearchSubtiles results)</param>
  613. /// <returns>Status of the call operation. If the call success the response will be 'MethodResponseSubtitleDownload' which will hold downloaded subtitles</returns>
  614. public static IMethodResponse DownloadSubtitles(int[] subIDS)
  615. {
  616. if (TOKEN == "")
  617. {
  618. OSHConsole.WriteLine("Can't do this call, 'token' value not set. Please use Log In method first.", DebugCode.Error);
  619. return new MethodResponseError("Fail", "Can't do this call, 'token' value not set. Please use Log In method first.");
  620. }
  621. if (subIDS == null)
  622. {
  623. OSHConsole.UpdateLine("No subtitle id passed !!", DebugCode.Error);
  624. return new MethodResponseError("Fail", "No subtitle id passed");
  625. }
  626. if (subIDS.Length == 0)
  627. {
  628. OSHConsole.UpdateLine("No subtitle id passed !!", DebugCode.Error);
  629. return new MethodResponseError("Fail", "No subtitle id passed");
  630. }
  631. // Method call ..
  632. var parms = new List<IXmlRpcValue>();
  633. // Add token param
  634. parms.Add(new XmlRpcValueBasic(TOKEN, XmlRpcBasicValueType.String));
  635. // Add subtitle search parameters. Each one will be like 'array' of structs.
  636. var array = new XmlRpcValueArray();
  637. foreach (int id in subIDS)
  638. {
  639. array.Values.Add(new XmlRpcValueBasic(id, XmlRpcBasicValueType.Int));
  640. }
  641. // Add the array to the parameters
  642. parms.Add(array);
  643. // Call !
  644. var call = new XmlRpcMethodCall("DownloadSubtitles", parms);
  645. OSHConsole.WriteLine("Sending DownloadSubtitles request to the server ...", DebugCode.Good);
  646. // Send the request to the server
  647. string response = Utilities.GetStreamString(Utilities.SendRequest(XmlRpcGenerator.Generate(call), XML_PRC_USERAGENT));
  648. if (!response.Contains("ERROR:"))
  649. {
  650. // No error occur, get and decode the response.
  651. XmlRpcMethodCall[] calls = XmlRpcGenerator.DecodeMethodResponse(response);
  652. if (calls.Length > 0)
  653. {
  654. if (calls[0].Parameters.Count > 0)
  655. {
  656. // We expect Struct of 3 members:
  657. //* the first is status
  658. //* the second is [array of structs, each one includes subtitle file].
  659. //* the third is [double basic value] represent seconds token by server.
  660. var mainStruct = (XmlRpcValueStruct)calls[0].Parameters[0];
  661. // Create the response, we'll need it later
  662. var R = new MethodResponseSubtitleDownload();
  663. // To make sure response is not currepted by server, do it in loop
  664. foreach (XmlRpcStructMember MEMBER in mainStruct.Members)
  665. {
  666. if (MEMBER.Name == "status")
  667. {
  668. R.Status = (string)MEMBER.Data.Data;
  669. OSHConsole.WriteLine("Status= " + R.Status);
  670. }
  671. else if (MEMBER.Name == "seconds")
  672. {
  673. R.Seconds = (double)MEMBER.Data.Data;
  674. OSHConsole.WriteLine("Seconds= " + R.Seconds);
  675. }
  676. else if (MEMBER.Name == "data")
  677. {
  678. if (MEMBER.Data is XmlRpcValueArray)
  679. {
  680. OSHConsole.WriteLine("Download results:");
  681. var rarray = (XmlRpcValueArray)MEMBER.Data;
  682. foreach (IXmlRpcValue subStruct in rarray.Values)
  683. {
  684. if (subStruct == null) continue;
  685. if (!(subStruct is XmlRpcValueStruct)) continue;
  686. var result = new SubtitleDownloadResult();
  687. foreach (XmlRpcStructMember submember in ((XmlRpcValueStruct)subStruct).Members)
  688. {
  689. // To avoid errors of arranged info or missing ones, let's do it with switch..
  690. switch (submember.Name)
  691. {
  692. case "idsubtitlefile": result.IdSubtitleFile = (string)submember.Data.Data; break;
  693. case "data": result.Data = (string)submember.Data.Data; break;
  694. }
  695. }
  696. R.Results.Add(result);
  697. OSHConsole.WriteLine("> IDSubtilteFile= " + result.ToString());
  698. }
  699. }
  700. else// Unknown data ?
  701. {
  702. OSHConsole.WriteLine("Data= " + MEMBER.Data.Data.ToString(), DebugCode.Warning);
  703. }
  704. }
  705. }
  706. // Return the response to user !!
  707. return R;
  708. }
  709. }
  710. }
  711. else
  712. {
  713. OSHConsole.WriteLine(response, DebugCode.Error);
  714. return new MethodResponseError("Fail", response);
  715. }
  716. return new MethodResponseError("Fail", "DownloadSubtitles call failed !");
  717. }
  718. public static async Task<IMethodResponse> DownloadSubtitlesAsync(int[] subIDS, CancellationToken cancellationToken)
  719. {
  720. if (TOKEN == "")
  721. {
  722. OSHConsole.WriteLine("Can't do this call, 'token' value not set. Please use Log In method first.", DebugCode.Error);
  723. return new MethodResponseError("Fail", "Can't do this call, 'token' value not set. Please use Log In method first.");
  724. }
  725. if (subIDS == null)
  726. {
  727. OSHConsole.UpdateLine("No subtitle id passed !!", DebugCode.Error);
  728. return new MethodResponseError("Fail", "No subtitle id passed");
  729. }
  730. if (subIDS.Length == 0)
  731. {
  732. OSHConsole.UpdateLine("No subtitle id passed !!", DebugCode.Error);
  733. return new MethodResponseError("Fail", "No subtitle id passed");
  734. }
  735. // Method call ..
  736. var parms = new List<IXmlRpcValue>();
  737. // Add token param
  738. parms.Add(new XmlRpcValueBasic(TOKEN, XmlRpcBasicValueType.String));
  739. // Add subtitle search parameters. Each one will be like 'array' of structs.
  740. var array = new XmlRpcValueArray();
  741. foreach (int id in subIDS)
  742. {
  743. array.Values.Add(new XmlRpcValueBasic(id, XmlRpcBasicValueType.Int));
  744. }
  745. // Add the array to the parameters
  746. parms.Add(array);
  747. // Call !
  748. var call = new XmlRpcMethodCall("DownloadSubtitles", parms);
  749. OSHConsole.WriteLine("Sending DownloadSubtitles request to the server ...", DebugCode.Good);
  750. // Send the request to the server
  751. var httpResponse = await Utilities.SendRequestAsync(XmlRpcGenerator.Generate(call), XML_PRC_USERAGENT, cancellationToken).ConfigureAwait(false);
  752. string response = Utilities.GetStreamString(httpResponse);
  753. if (!response.Contains("ERROR:"))
  754. {
  755. // No error occur, get and decode the response.
  756. XmlRpcMethodCall[] calls = XmlRpcGenerator.DecodeMethodResponse(response);
  757. if (calls.Length > 0)
  758. {
  759. if (calls[0].Parameters.Count > 0)
  760. {
  761. // We expect Struct of 3 members:
  762. //* the first is status
  763. //* the second is [array of structs, each one includes subtitle file].
  764. //* the third is [double basic value] represent seconds token by server.
  765. var mainStruct = (XmlRpcValueStruct)calls[0].Parameters[0];
  766. // Create the response, we'll need it later
  767. var R = new MethodResponseSubtitleDownload();
  768. // To make sure response is not currepted by server, do it in loop
  769. foreach (XmlRpcStructMember MEMBER in mainStruct.Members)
  770. {
  771. if (MEMBER.Name == "status")
  772. {
  773. R.Status = (string)MEMBER.Data.Data;
  774. OSHConsole.WriteLine("Status= " + R.Status);
  775. }
  776. else if (MEMBER.Name == "seconds")
  777. {
  778. R.Seconds = (double)MEMBER.Data.Data;
  779. OSHConsole.WriteLine("Seconds= " + R.Seconds);
  780. }
  781. else if (MEMBER.Name == "data")
  782. {
  783. if (MEMBER.Data is XmlRpcValueArray)
  784. {
  785. OSHConsole.WriteLine("Download results:");
  786. var rarray = (XmlRpcValueArray)MEMBER.Data;
  787. foreach (IXmlRpcValue subStruct in rarray.Values)
  788. {
  789. if (subStruct == null) continue;
  790. if (!(subStruct is XmlRpcValueStruct)) continue;
  791. var result = new SubtitleDownloadResult();
  792. foreach (XmlRpcStructMember submember in ((XmlRpcValueStruct)subStruct).Members)
  793. {
  794. // To avoid errors of arranged info or missing ones, let's do it with switch..
  795. switch (submember.Name)
  796. {
  797. case "idsubtitlefile": result.IdSubtitleFile = (string)submember.Data.Data; break;
  798. case "data": result.Data = (string)submember.Data.Data; break;
  799. }
  800. }
  801. R.Results.Add(result);
  802. OSHConsole.WriteLine("> IDSubtilteFile= " + result.ToString());
  803. }
  804. }
  805. else// Unknown data ?
  806. {
  807. OSHConsole.WriteLine("Data= " + MEMBER.Data.Data.ToString(), DebugCode.Warning);
  808. }
  809. }
  810. }
  811. // Return the response to user !!
  812. return R;
  813. }
  814. }
  815. }
  816. else
  817. {
  818. OSHConsole.WriteLine(response, DebugCode.Error);
  819. return new MethodResponseError("Fail", response);
  820. }
  821. return new MethodResponseError("Fail", "DownloadSubtitles call failed !");
  822. }
  823. /// <summary>
  824. /// Returns comments for subtitles
  825. /// </summary>
  826. /// <param name="subIDS">The subtitle IDS (an array of IDSubtitleFile value that given by server as SearchSubtiles results)</param>
  827. /// <returns>Status of the call operation. If the call success the response will be 'MethodResponseGetComments'</returns>
  828. public static IMethodResponse GetComments(int[] subIDS)
  829. {
  830. if (TOKEN == "")
  831. {
  832. OSHConsole.WriteLine("Can't do this call, 'token' value not set. Please use Log In method first.", DebugCode.Error);
  833. return new MethodResponseError("Fail", "Can't do this call, 'token' value not set. Please use Log In method first.");
  834. }
  835. if (subIDS == null)
  836. {
  837. OSHConsole.UpdateLine("No subtitle id passed !!", DebugCode.Error);
  838. return new MethodResponseError("Fail", "No subtitle id passed");
  839. }
  840. if (subIDS.Length == 0)
  841. {
  842. OSHConsole.UpdateLine("No subtitle id passed !!", DebugCode.Error);
  843. return new MethodResponseError("Fail", "No subtitle id passed");
  844. }
  845. // Method call ..
  846. var parms = new List<IXmlRpcValue>();
  847. // Add token param
  848. parms.Add(new XmlRpcValueBasic(TOKEN));
  849. // Add subtitle search parameters. Each one will be like 'array' of structs.
  850. var array = new XmlRpcValueArray(subIDS);
  851. // Add the array to the parameters
  852. parms.Add(array);
  853. // Call !
  854. var call = new XmlRpcMethodCall("GetComments", parms);
  855. OSHConsole.WriteLine("Sending GetComments request to the server ...", DebugCode.Good);
  856. // Send the request to the server
  857. string response = Utilities.GetStreamString(Utilities.SendRequest(XmlRpcGenerator.Generate(call), XML_PRC_USERAGENT));
  858. if (!response.Contains("ERROR:"))
  859. {
  860. // No error occur, get and decode the response.
  861. XmlRpcMethodCall[] calls = XmlRpcGenerator.DecodeMethodResponse(response);
  862. if (calls.Length > 0)
  863. {
  864. if (calls[0].Parameters.Count > 0)
  865. {
  866. var mainStruct = (XmlRpcValueStruct)calls[0].Parameters[0];
  867. // Create the response, we'll need it later
  868. var R = new MethodResponseGetComments();
  869. // To make sure response is not currepted by server, do it in loop
  870. foreach (XmlRpcStructMember MEMBER in mainStruct.Members)
  871. {
  872. if (MEMBER.Name == "status")
  873. {
  874. R.Status = (string)MEMBER.Data.Data;
  875. OSHConsole.WriteLine("Status= " + R.Status);
  876. }
  877. else if (MEMBER.Name == "seconds")
  878. {
  879. R.Seconds = (double)MEMBER.Data.Data;
  880. OSHConsole.WriteLine("Seconds= " + R.Seconds);
  881. }
  882. else if (MEMBER.Name == "data")
  883. {
  884. if (MEMBER.Data is XmlRpcValueArray)
  885. {
  886. OSHConsole.WriteLine("Comments results:");
  887. var rarray = (XmlRpcValueArray)MEMBER.Data;
  888. foreach (IXmlRpcValue commentStruct in rarray.Values)
  889. {
  890. if (commentStruct == null) continue;
  891. if (!(commentStruct is XmlRpcValueStruct)) continue;
  892. var result = new GetCommentsResult();
  893. foreach (XmlRpcStructMember commentmember in ((XmlRpcValueStruct)commentStruct).Members)
  894. {
  895. // To avoid errors of arranged info or missing ones, let's do it with switch..
  896. switch (commentmember.Name)
  897. {
  898. case "IDSubtitle": result.IDSubtitle = (string)commentmember.Data.Data; break;
  899. case "UserID": result.UserID = (string)commentmember.Data.Data; break;
  900. case "UserNickName": result.UserNickName = (string)commentmember.Data.Data; break;
  901. case "Comment": result.Comment = (string)commentmember.Data.Data; break;
  902. case "Created": result.Created = (string)commentmember.Data.Data; break;
  903. }
  904. }
  905. R.Results.Add(result);
  906. OSHConsole.WriteLine("> IDSubtitle= " + result.ToString());
  907. }
  908. }
  909. else// Unknown data ?
  910. {
  911. OSHConsole.WriteLine("Data= " + MEMBER.Data.Data.ToString(), DebugCode.Warning);
  912. }
  913. }
  914. }
  915. // Return the response to user !!
  916. return R;
  917. }
  918. }
  919. }
  920. else
  921. {
  922. OSHConsole.WriteLine(response, DebugCode.Error);
  923. return new MethodResponseError("Fail", response);
  924. }
  925. return new MethodResponseError("Fail", "GetComments call failed !");
  926. }
  927. /// <summary>
  928. /// Schedule a periodical search for subtitles matching given video files, send results to user's e-mail address.
  929. /// </summary>
  930. /// <param name="languageIDS">The language 3 lenght ids array</param>
  931. /// <param name="movies">The movies parameters</param>
  932. /// <returns>Status of the call operation. If the call success the response will be 'MethodResponseSearchToMail'</returns>
  933. public static IMethodResponse SearchToMail(string[] languageIDS, SearchToMailMovieParameter[] movies)
  934. {
  935. if (TOKEN == "")
  936. {
  937. OSHConsole.WriteLine("Can't do this call, 'token' value not set. Please use Log In method first.", DebugCode.Error);
  938. return new MethodResponseError("Fail", "Can't do this call, 'token' value not set. Please use Log In method first.");
  939. }
  940. // Method call ..
  941. var parms = new List<IXmlRpcValue>();
  942. parms.Add(new XmlRpcValueBasic(TOKEN, XmlRpcBasicValueType.String));
  943. // Array of sub langs
  944. var a = new XmlRpcValueArray(languageIDS);
  945. parms.Add(a);
  946. // Array of video parameters
  947. a = new XmlRpcValueArray();
  948. foreach (SearchToMailMovieParameter p in movies)
  949. {
  950. var str = new XmlRpcValueStruct(new List<XmlRpcStructMember>());
  951. str.Members.Add(new XmlRpcStructMember("moviehash", new XmlRpcValueBasic(p.moviehash)));
  952. str.Members.Add(new XmlRpcStructMember("moviesize", new XmlRpcValueBasic(p.moviesize)));
  953. a.Values.Add(str);
  954. }
  955. parms.Add(a);
  956. var call = new XmlRpcMethodCall("SearchToMail", parms);
  957. OSHConsole.WriteLine("Sending SearchToMail request to the server ...", DebugCode.Good);
  958. // Send the request to the server
  959. string response = Utilities.GetStreamString(Utilities.SendRequest(XmlRpcGenerator.Generate(call), XML_PRC_USERAGENT));
  960. if (!response.Contains("ERROR:"))
  961. {
  962. // No error occur, get and decode the response.
  963. XmlRpcMethodCall[] calls = XmlRpcGenerator.DecodeMethodResponse(response);
  964. if (calls.Length > 0)
  965. {
  966. if (calls[0].Parameters.Count > 0)
  967. {
  968. var mainStruct = (XmlRpcValueStruct)calls[0].Parameters[0];
  969. // Create the response, we'll need it later
  970. var R = new MethodResponseSearchToMail();
  971. // To make sure response is not currepted by server, do it in loop
  972. foreach (XmlRpcStructMember MEMBER in mainStruct.Members)
  973. {
  974. switch (MEMBER.Name)
  975. {
  976. case "status": R.Status = (string)MEMBER.Data.Data; OSHConsole.WriteLine(">" + MEMBER.Name + "= " + MEMBER.Data.Data.ToString()); break;
  977. case "seconds": R.Seconds = (double)MEMBER.Data.Data; OSHConsole.WriteLine(">" + MEMBER.Name + "= " + MEMBER.Data.Data.ToString()); break;
  978. }
  979. }
  980. // Return the response to user !!
  981. return R;
  982. }
  983. }
  984. }
  985. else
  986. {
  987. OSHConsole.WriteLine(response, DebugCode.Error);
  988. return new MethodResponseError("Fail", response);
  989. }
  990. return new MethodResponseError("Fail", "SearchToMail call failed !");
  991. }
  992. /*Movies*/
  993. /// <summary>
  994. /// Search for a movie (using movie title)
  995. /// </summary>
  996. /// <param name="query">Movie title user is searching for, this is cleaned-up a bit (remove dvdrip, etc.) before searching </param>
  997. /// <returns>Status of the call operation. If the call success the response will be 'MethodResponseSubtitleSearch'</returns>
  998. public static IMethodResponse SearchMoviesOnIMDB(string query)
  999. {
  1000. if (TOKEN == "")
  1001. {
  1002. OSHConsole.WriteLine("Can't do this call, 'token' value not set. Please use Log In method first.", DebugCode.Error);
  1003. return new MethodResponseError("Fail", "Can't do this call, 'token' value not set. Please use Log In method first.");
  1004. }
  1005. // Method call ..
  1006. var parms = new List<IXmlRpcValue>();
  1007. // Add token param
  1008. parms.Add(new XmlRpcValueBasic(TOKEN, XmlRpcBasicValueType.String));
  1009. // Add query param
  1010. parms.Add(new XmlRpcValueBasic(query, XmlRpcBasicValueType.String));
  1011. // Call !
  1012. var call = new XmlRpcMethodCall("SearchMoviesOnIMDB", parms);
  1013. OSHConsole.WriteLine("Sending SearchMoviesOnIMDB request to the server ...", DebugCode.Good);
  1014. // Send the request to the server
  1015. string response = Utilities.GetStreamString(Utilities.SendRequest(XmlRpcGenerator.Generate(call), XML_PRC_USERAGENT));
  1016. if (!response.Contains("ERROR:"))
  1017. {
  1018. // No error occur, get and decode the response.
  1019. XmlRpcMethodCall[] calls = XmlRpcGenerator.DecodeMethodResponse(response);
  1020. if (calls.Length > 0)
  1021. {
  1022. if (calls[0].Parameters.Count > 0)
  1023. {
  1024. var mainStruct = (XmlRpcValueStruct)calls[0].Parameters[0];
  1025. // Create the response, we'll need it later
  1026. var R = new MethodResponseMovieSearch();
  1027. // To make sure response is not currepted by server, do it in loop
  1028. foreach (XmlRpcStructMember MEMBER in mainStruct.Members)
  1029. {
  1030. if (MEMBER.Name == "status")
  1031. {
  1032. R.Status = (string)MEMBER.Data.Data;
  1033. OSHConsole.WriteLine("Status= " + R.Status);
  1034. }
  1035. else if (MEMBER.Name == "seconds")
  1036. {
  1037. R.Seconds = (double)MEMBER.Data.Data;
  1038. OSHConsole.WriteLine("Seconds= " + R.Seconds);
  1039. }
  1040. else if (MEMBER.Name == "data")
  1041. {
  1042. if (MEMBER.Data is XmlRpcValueArray)
  1043. {
  1044. OSHConsole.WriteLine("Search results:");
  1045. var rarray = (XmlRpcValueArray)MEMBER.Data;
  1046. foreach (IXmlRpcValue subStruct in rarray.Values)
  1047. {
  1048. if (subStruct == null) continue;
  1049. if (!(subStruct is XmlRpcValueStruct)) continue;
  1050. var result = new MovieSearchResult();
  1051. foreach (XmlRpcStructMember submember in ((XmlRpcValueStruct)subStruct).Members)
  1052. {
  1053. // To avoid errors of arranged info or missing ones, let's do it with switch..
  1054. switch (submember.Name)
  1055. {
  1056. case "id": result.ID = (string)submember.Data.Data; break;
  1057. case "title": result.Title = (string)submember.Data.Data; break;
  1058. }
  1059. }
  1060. R.Results.Add(result);
  1061. OSHConsole.WriteLine(">" + result.ToString());
  1062. }
  1063. }
  1064. else// Unknown data ?
  1065. {
  1066. OSHConsole.WriteLine("Data= " + MEMBER.Data.Data.ToString(), DebugCode.Warning);
  1067. }
  1068. }
  1069. }
  1070. // Return the response to user !!
  1071. return R;
  1072. }
  1073. }
  1074. }
  1075. else
  1076. {
  1077. OSHConsole.WriteLine(response, DebugCode.Error);
  1078. return new MethodResponseError("Fail", response);
  1079. }
  1080. return new MethodResponseError("Fail", "SearchMoviesOnIMDB call failed !");
  1081. }
  1082. /// <summary>
  1083. /// Get movie details for given IMDb ID
  1084. /// </summary>
  1085. /// <param name="imdbid">http://www.imdb.com/</param>
  1086. /// <returns>Status of the call operation. If the call success the response will be 'MethodResponseMovieDetails'</returns>
  1087. public static IMethodResponse GetIMDBMovieDetails(string imdbid)
  1088. {
  1089. if (TOKEN == "")
  1090. {
  1091. OSHConsole.WriteLine("Can't do this call, 'token' value not set. Please use Log In method first.", DebugCode.Error);
  1092. return new MethodResponseError("Fail", "Can't do this call, 'token' value not set. Please use Log In method first.");
  1093. }
  1094. // Method call ..
  1095. var parms = new List<IXmlRpcValue>();
  1096. // Add token param
  1097. parms.Add(new XmlRpcValueBasic(TOKEN));
  1098. // Add query param
  1099. parms.Add(new XmlRpcValueBasic(imdbid));
  1100. // Call !
  1101. var call = new XmlRpcMethodCall("GetIMDBMovieDetails", parms);
  1102. OSHConsole.WriteLine("Sending GetIMDBMovieDetails request to the server ...", DebugCode.Good);
  1103. // Send the request to the server
  1104. string response = Utilities.GetStreamString(Utilities.SendRequest(XmlRpcGenerator.Generate(call), XML_PRC_USERAGENT));
  1105. if (!response.Contains("ERROR:"))
  1106. {
  1107. // No error occur, get and decode the response.
  1108. XmlRpcMethodCall[] calls = XmlRpcGenerator.DecodeMethodResponse(response);
  1109. if (calls.Length > 0)
  1110. {
  1111. if (calls[0].Parameters.Count > 0)
  1112. {
  1113. var mainStruct = (XmlRpcValueStruct)calls[0].Parameters[0];
  1114. // Create the response, we'll need it later
  1115. var R = new MethodResponseMovieDetails();
  1116. // To make sure response is not currepted by server, do it in loop
  1117. foreach (XmlRpcStructMember MEMBER in mainStruct.Members)
  1118. {
  1119. if (MEMBER.Name == "status")
  1120. {
  1121. R.Status = (string)MEMBER.Data.Data;
  1122. OSHConsole.WriteLine("Status= " + R.Status);
  1123. }
  1124. else if (MEMBER.Name == "seconds")
  1125. {
  1126. R.Seconds = (double)MEMBER.Data.Data;
  1127. OSHConsole.WriteLine("Seconds= " + R.Seconds);
  1128. }
  1129. else if (MEMBER.Name == "data")
  1130. {
  1131. // We expect struct with details...
  1132. if (MEMBER.Data is XmlRpcValueStruct)
  1133. {
  1134. OSHConsole.WriteLine("Details result:");
  1135. var detailsStruct = (XmlRpcValueStruct)MEMBER.Data;
  1136. foreach (XmlRpcStructMember dmem in detailsStruct.Members)
  1137. {
  1138. switch (dmem.Name)
  1139. {
  1140. case "id": R.ID = dmem.Data.Data.ToString(); OSHConsole.WriteLine(">" + dmem.Name + "= " + dmem.Data.Data.ToString()); break;
  1141. case "title": R.Title = dmem.Data.Data.ToString(); OSHConsole.WriteLine(">" + dmem.Name + "= " + dmem.Data.Data.ToString()); break;
  1142. case "year": R.Year = dmem.Data.Data.ToString(); OSHConsole.WriteLine(">" + dmem.Name + "= " + dmem.Data.Data.ToString()); break;
  1143. case "cover": R.CoverLink = dmem.Data.Data.ToString(); OSHConsole.WriteLine(">" + dmem.Name + "= " + dmem.Data.Data.ToString()); break;
  1144. case "duration": R.Duration = dmem.Data.Data.ToString(); OSHConsole.WriteLine(">" + dmem.Name + "= " + dmem.Data.Data.ToString()); break;
  1145. case "tagline": R.Tagline = dmem.Data.Data.ToString(); OSHConsole.WriteLine(">" + dmem.Name + "= " + dmem.Data.Data.ToString()); break;
  1146. case "plot": R.Plot = dmem.Data.Data.ToString(); OSHConsole.WriteLine(">" + dmem.Name + "= " + dmem.Data.Data.ToString()); break;
  1147. case "goofs": R.Goofs = dmem.Data.Data.ToString(); OSHConsole.WriteLine(">" + dmem.Name + "= " + dmem.Data.Data.ToString()); break;
  1148. case "trivia": R.Trivia = dmem.Data.Data.ToString(); OSHConsole.WriteLine(">" + dmem.Name + "= " + dmem.Data.Data.ToString()); break;
  1149. case "cast":
  1150. // this is another struct with cast members...
  1151. OSHConsole.WriteLine(">" + dmem.Name + "= ");
  1152. var castStruct = (XmlRpcValueStruct)dmem.Data;
  1153. foreach (XmlRpcStructMember castMemeber in castStruct.Members)
  1154. {
  1155. R.Cast.Add(castMemeber.Data.Data.ToString());
  1156. OSHConsole.WriteLine(" >" + castMemeber.Data.Data.ToString());
  1157. }
  1158. break;
  1159. case "directors":
  1160. OSHConsole.WriteLine(">" + dmem.Name + "= ");
  1161. // this is another struct with directors members...
  1162. var directorsStruct = (XmlRpcValueStruct)dmem.Data;
  1163. foreach (XmlRpcStructMember directorsMember in directorsStruct.Members)
  1164. {
  1165. R.Directors.Add(directorsMember.Data.Data.ToString());
  1166. OSHConsole.WriteLine(" >" + directorsMember.Data.Data.ToString());
  1167. }
  1168. break;
  1169. case "writers":
  1170. OSHConsole.WriteLine(">" + dmem.Name + "= ");
  1171. // this is another struct with writers members...
  1172. var writersStruct = (XmlRpcValueStruct)dmem.Data;
  1173. foreach (XmlRpcStructMember writersMember in writersStruct.Members)
  1174. {
  1175. R.Writers.Add(writersMember.Data.Data.ToString());
  1176. OSHConsole.WriteLine("+->" + writersMember.Data.Data.ToString());
  1177. }
  1178. break;
  1179. case "awards":
  1180. // this is an array of genres...
  1181. var awardsArray = (XmlRpcValueArray)dmem.Data;
  1182. foreach (XmlRpcValueBasic award in awardsArray.Values)
  1183. {
  1184. R.Awards.Add(award.Data.ToString());
  1185. OSHConsole.WriteLine(" >" + award.Data.ToString());
  1186. }
  1187. break;
  1188. case "genres":
  1189. OSHConsole.WriteLine(">" + dmem.Name + "= ");
  1190. // this is an array of genres...
  1191. var genresArray = (XmlRpcValueArray)dmem.Data;
  1192. foreach (XmlRpcValueBasic genre in genresArray.Values)
  1193. {
  1194. R.Genres.Add(genre.Data.ToString());
  1195. OSHConsole.WriteLine(" >" + genre.Data.ToString());
  1196. }
  1197. break;
  1198. case "country":
  1199. OSHConsole.WriteLine(">" + dmem.Name + "= ");
  1200. // this is an array of country...
  1201. var countryArray = (XmlRpcValueArray)dmem.Data;
  1202. foreach (XmlRpcValueBasic country in countryArray.Values)
  1203. {
  1204. R.Country.Add(country.Data.ToString());
  1205. OSHConsole.WriteLine(" >" + country.Data.ToString());
  1206. }
  1207. break;
  1208. case "language":
  1209. OSHConsole.WriteLine(">" + dmem.Name + "= ");
  1210. // this is an array of language...
  1211. var languageArray = (XmlRpcValueArray)dmem.Data;
  1212. foreach (XmlRpcValueBasic language in languageArray.Values)
  1213. {
  1214. R.Language.Add(language.Data.ToString());
  1215. OSHConsole.WriteLine(" >" + language.Data.ToString());
  1216. }
  1217. break;
  1218. case "certification":
  1219. OSHConsole.WriteLine(">" + dmem.Name + "= ");
  1220. // this is an array of certification...
  1221. var certificationArray = (XmlRpcValueArray)dmem.Data;
  1222. foreach (XmlRpcValueBasic certification in certificationArray.Values)
  1223. {
  1224. R.Certification.Add(certification.Data.ToString());
  1225. OSHConsole.WriteLine(" >" + certification.Data.ToString());
  1226. }
  1227. break;
  1228. }
  1229. }
  1230. }
  1231. else// Unknown data ?
  1232. {
  1233. OSHConsole.WriteLine("Data= " + MEMBER.Data.Data.ToString(), DebugCode.Warning);
  1234. }
  1235. }
  1236. }
  1237. // Return the response to user !!
  1238. return R;
  1239. }
  1240. }
  1241. }
  1242. else
  1243. {
  1244. OSHConsole.WriteLine(response, DebugCode.Error);
  1245. return new MethodResponseError("Fail", response);
  1246. }
  1247. return new MethodResponseError("Fail", "GetIMDBMovieDetails call failed !");
  1248. }
  1249. /// <summary>
  1250. /// Allows registered users to insert new movies (not stored in IMDb) to the database.
  1251. /// </summary>
  1252. /// <param name="movieName">Movie title </param>
  1253. /// <param name="movieyear">Release year </param>
  1254. /// <returns>Status of the call operation. If the call success the response will be 'MethodResponseInsertMovie'</returns>
  1255. public static IMethodResponse InsertMovie(string movieName, string movieyear)
  1256. {
  1257. if (TOKEN == "")
  1258. {
  1259. OSHConsole.WriteLine("Can't do this call, 'token' value not set. Please use Log In method first.", DebugCode.Error);
  1260. return new MethodResponseError("Fail", "Can't do this call, 'token' value not set. Please use Log In method first.");
  1261. }
  1262. // Method call ..
  1263. var parms = new List<IXmlRpcValue>();
  1264. // Add token param
  1265. parms.Add(new XmlRpcValueBasic(TOKEN, XmlRpcBasicValueType.String));
  1266. // Add movieinfo struct
  1267. var movieinfo = new XmlRpcValueStruct(new List<XmlRpcStructMember>());
  1268. movieinfo.Members.Add(new XmlRpcStructMember("moviename", new XmlRpcValueBasic(movieName)));
  1269. movieinfo.Members.Add(new XmlRpcStructMember("movieyear", new XmlRpcValueBasic(movieyear)));
  1270. parms.Add(movieinfo);
  1271. // Call !
  1272. var call = new XmlRpcMethodCall("InsertMovie", parms);
  1273. OSHConsole.WriteLine("Sending InsertMovie request to the server ...", DebugCode.Good);
  1274. // Send the request to the server
  1275. string response = Utilities.GetStreamString(Utilities.SendRequest(XmlRpcGenerator.Generate(call), XML_PRC_USERAGENT));
  1276. if (!response.Contains("ERROR:"))
  1277. {
  1278. // No error occur, get and decode the response.
  1279. XmlRpcMethodCall[] calls = XmlRpcGenerator.DecodeMethodResponse(response);
  1280. if (calls.Length > 0)
  1281. {
  1282. if (calls[0].Parameters.Count > 0)
  1283. {
  1284. var mainStruct = (XmlRpcValueStruct)calls[0].Parameters[0];
  1285. // Create the response, we'll need it later
  1286. var R = new MethodResponseInsertMovie();
  1287. // To make sure response is not currepted by server, do it in loop
  1288. foreach (XmlRpcStructMember MEMBER in mainStruct.Members)
  1289. {
  1290. if (MEMBER.Name == "status")
  1291. {
  1292. R.Status = (string)MEMBER.Data.Data;
  1293. OSHConsole.WriteLine("Status= " + R.Status);
  1294. }
  1295. else if (MEMBER.Name == "seconds")
  1296. {
  1297. R.Seconds = (double)MEMBER.Data.Data;
  1298. OSHConsole.WriteLine("Seconds= " + R.Seconds);
  1299. }
  1300. else if (MEMBER.Name == "id")
  1301. {
  1302. R.ID = (string)MEMBER.Data.Data;
  1303. OSHConsole.WriteLine("ID= " + R.Seconds);
  1304. }
  1305. }
  1306. // Return the response to user !!
  1307. return R;
  1308. }
  1309. }
  1310. }
  1311. else
  1312. {
  1313. OSHConsole.WriteLine(response, DebugCode.Error);
  1314. return new MethodResponseError("Fail", response);
  1315. }
  1316. return new MethodResponseError("Fail", "InsertMovie call failed !");
  1317. }
  1318. /// <summary>
  1319. /// Inserts or updates data to tables, which are used for CheckMovieHash() and !CheckMovieHash2().
  1320. /// </summary>
  1321. /// <param name="parameters">The parameters</param>
  1322. /// <returns>Status of the call operation. If the call success the response will be 'MethodResponseInsertMovieHash'</returns>
  1323. public static IMethodResponse InsertMovieHash(InsertMovieHashParameters[] parameters)
  1324. {
  1325. if (TOKEN == "")
  1326. {
  1327. OSHConsole.WriteLine("Can't do this call, 'token' value not set. Please use Log In method first.", DebugCode.Error);
  1328. return new MethodResponseError("Fail", "Can't do this call, 'token' value not set. Please use Log In method first.");
  1329. }
  1330. // Method call ..
  1331. var parms = new List<IXmlRpcValue>();
  1332. parms.Add(new XmlRpcValueBasic(TOKEN, XmlRpcBasicValueType.String));
  1333. foreach (InsertMovieHashParameters p in parameters)
  1334. {
  1335. var pstruct = new XmlRpcValueStruct(new List<XmlRpcStructMember>());
  1336. pstruct.Members.Add(new XmlRpcStructMember("moviehash", new XmlRpcValueBasic(p.moviehash)));
  1337. pstruct.Members.Add(new XmlRpcStructMember("moviebytesize", new XmlRpcValueBasic(p.moviebytesize)));
  1338. pstruct.Members.Add(new XmlRpcStructMember("imdbid", new XmlRpcValueBasic(p.imdbid)));
  1339. pstruct.Members.Add(new XmlRpcStructMember("movietimems", new XmlRpcValueBasic(p.movietimems)));
  1340. pstruct.Members.Add(new XmlRpcStructMember("moviefps", new XmlRpcValueBasic(p.moviefps)));
  1341. pstruct.Members.Add(new XmlRpcStructMember("moviefilename", new XmlRpcValueBasic(p.moviefilename)));
  1342. parms.Add(pstruct);
  1343. }
  1344. var call = new XmlRpcMethodCall("InsertMovieHash", parms);
  1345. OSHConsole.WriteLine("Sending InsertMovieHash request to the server ...", DebugCode.Good);
  1346. // Send the request to the server
  1347. string response = Utilities.GetStreamString(Utilities.SendRequest(XmlRpcGenerator.Generate(call), XML_PRC_USERAGENT));
  1348. if (!response.Contains("ERROR:"))
  1349. {
  1350. // No error occur, get and decode the response.
  1351. XmlRpcMethodCall[] calls = XmlRpcGenerator.DecodeMethodResponse(response);
  1352. if (calls.Length > 0)
  1353. {
  1354. if (calls[0].Parameters.Count > 0)
  1355. {
  1356. var mainStruct = (XmlRpcValueStruct)calls[0].Parameters[0];
  1357. // Create the response, we'll need it later
  1358. var R = new MethodResponseInsertMovieHash();
  1359. // To make sure response is not currepted by server, do it in loop
  1360. foreach (XmlRpcStructMember MEMBER in mainStruct.Members)
  1361. {
  1362. switch (MEMBER.Name)
  1363. {
  1364. case "status":
  1365. R.Status = (string)MEMBER.Data.Data;
  1366. OSHConsole.WriteLine(">" + MEMBER.Name + "= " + MEMBER.Data.Data.ToString());
  1367. break;
  1368. case "seconds":
  1369. R.Seconds = (double)MEMBER.Data.Data;
  1370. OSHConsole.WriteLine(">" + MEMBER.Name + "= " + MEMBER.Data.Data.ToString());
  1371. break;
  1372. case "data":
  1373. var dataStruct = (XmlRpcValueStruct)MEMBER.Data;
  1374. foreach (XmlRpcStructMember dataMember in dataStruct.Members)
  1375. {
  1376. switch (dataMember.Name)
  1377. {
  1378. case "accepted_moviehashes":
  1379. var mh = (XmlRpcValueArray)dataMember.Data;
  1380. foreach (IXmlRpcValue val in mh.Values)
  1381. {
  1382. if (val is XmlRpcValueBasic)
  1383. {
  1384. R.accepted_moviehashes.Add(val.Data.ToString());
  1385. }
  1386. }
  1387. break;
  1388. case "new_imdbs":
  1389. var mi = (XmlRpcValueArray)dataMember.Data;
  1390. foreach (IXmlRpcValue val in mi.Values)
  1391. {
  1392. if (val is XmlRpcValueBasic)
  1393. {
  1394. R.new_imdbs.Add(val.Data.ToString());
  1395. }
  1396. }
  1397. break;
  1398. }
  1399. }
  1400. break;
  1401. }
  1402. }
  1403. // Return the response to user !!
  1404. return R;
  1405. }
  1406. }
  1407. }
  1408. else
  1409. {
  1410. OSHConsole.WriteLine(response, DebugCode.Error);
  1411. return new MethodResponseError("Fail", response);
  1412. }
  1413. return new MethodResponseError("Fail", "InsertMovieHash call failed !");
  1414. }
  1415. /*Reporting and rating*/
  1416. /// <summary>
  1417. /// Get basic server information and statistics
  1418. /// </summary>
  1419. /// <returns>Status of the call operation. If the call success the response will be 'MethodResponseServerInfo'</returns>
  1420. public static IMethodResponse ServerInfo()
  1421. {
  1422. if (TOKEN == "")
  1423. {
  1424. OSHConsole.WriteLine("Can't do this call, 'token' value not set. Please use Log In method first.", DebugCode.Error);
  1425. return new MethodResponseError("Fail", "Can't do this call, 'token' value not set. Please use Log In method first.");
  1426. }
  1427. // Method call ..
  1428. var parms = new List<IXmlRpcValue>();
  1429. parms.Add(new XmlRpcValueBasic(TOKEN, XmlRpcBasicValueType.String));
  1430. parms.Add(new XmlRpcValueBasic(XML_PRC_USERAGENT, XmlRpcBasicValueType.String));
  1431. var call = new XmlRpcMethodCall("ServerInfo", parms);
  1432. OSHConsole.WriteLine("Sending ServerInfo request to the server ...", DebugCode.Good);
  1433. // Send the request to the server
  1434. string response = Utilities.GetStreamString(Utilities.SendRequest(XmlRpcGenerator.Generate(call), XML_PRC_USERAGENT));
  1435. if (!response.Contains("ERROR:"))
  1436. {
  1437. // No error occur, get and decode the response.
  1438. XmlRpcMethodCall[] calls = XmlRpcGenerator.DecodeMethodResponse(response);
  1439. if (calls.Length > 0)
  1440. {
  1441. if (calls[0].Parameters.Count > 0)
  1442. {
  1443. var mainStruct = (XmlRpcValueStruct)calls[0].Parameters[0];
  1444. // Create the response, we'll need it later
  1445. var R = new MethodResponseServerInfo();
  1446. // To make sure response is not currepted by server, do it in loop
  1447. foreach (XmlRpcStructMember MEMBER in mainStruct.Members)
  1448. {
  1449. switch (MEMBER.Name)
  1450. {
  1451. case "status":
  1452. R.Status = (string)MEMBER.Data.Data;
  1453. OSHConsole.WriteLine(">" + MEMBER.Name + "= " + MEMBER.Data.Data.ToString());
  1454. break;
  1455. case "seconds":
  1456. R.Seconds = (double)MEMBER.Data.Data;
  1457. OSHConsole.WriteLine(">" + MEMBER.Name + "= " + MEMBER.Data.Data.ToString());
  1458. break;
  1459. case "xmlrpc_version":
  1460. R.xmlrpc_version = (string)MEMBER.Data.Data;
  1461. OSHConsole.WriteLine(">" + MEMBER.Name + "= " + MEMBER.Data.Data.ToString());
  1462. break;
  1463. case "xmlrpc_url":
  1464. R.xmlrpc_url = (string)MEMBER.Data.Data;
  1465. OSHConsole.WriteLine(">" + MEMBER.Name + "= " + MEMBER.Data.Data.ToString());
  1466. break;
  1467. case "application":
  1468. R.application = (string)MEMBER.Data.Data;
  1469. OSHConsole.WriteLine(">" + MEMBER.Name + "= " + MEMBER.Data.Data.ToString());
  1470. break;
  1471. case "contact":
  1472. R.contact = (string)MEMBER.Data.Data;
  1473. OSHConsole.WriteLine(">" + MEMBER.Name + "= " + MEMBER.Data.Data.ToString());
  1474. break;
  1475. case "website_url":
  1476. R.website_url = (string)MEMBER.Data.Data;
  1477. OSHConsole.WriteLine(">" + MEMBER.Name + "= " + MEMBER.Data.Data.ToString());
  1478. break;
  1479. case "users_online_total":
  1480. R.users_online_total = (int)MEMBER.Data.Data;
  1481. OSHConsole.WriteLine(">" + MEMBER.Name + "= " + MEMBER.Data.Data.ToString());
  1482. break;
  1483. case "users_online_program":
  1484. R.users_online_program = (int)MEMBER.Data.Data;
  1485. OSHConsole.WriteLine(">" + MEMBER.Name + "= " + MEMBER.Data.Data.ToString());
  1486. break;
  1487. case "users_loggedin":
  1488. R.users_loggedin = (int)MEMBER.Data.Data;
  1489. OSHConsole.WriteLine(">" + MEMBER.Name + "= " + MEMBER.Data.Data.ToString());
  1490. break;
  1491. case "users_max_alltime":
  1492. R.users_max_alltime = (string)MEMBER.Data.Data;
  1493. OSHConsole.WriteLine(">" + MEMBER.Name + "= " + MEMBER.Data.Data.ToString());
  1494. break;
  1495. case "users_registered":
  1496. R.users_registered = (string)MEMBER.Data.Data;
  1497. OSHConsole.WriteLine(">" + MEMBER.Name + "= " + MEMBER.Data.Data.ToString());
  1498. break;
  1499. case "subs_downloads":
  1500. R.subs_downloads = (string)MEMBER.Data.Data;
  1501. OSHConsole.WriteLine(">" + MEMBER.Name + "= " + MEMBER.Data.Data.ToString());
  1502. break;
  1503. case "subs_subtitle_files":
  1504. R.subs_subtitle_files = (string)MEMBER.Data.Data;
  1505. OSHConsole.WriteLine(">" + MEMBER.Name + "= " + MEMBER.Data.Data.ToString());
  1506. break;
  1507. case "movies_total":
  1508. R.movies_total = (string)MEMBER.Data.Data;
  1509. OSHConsole.WriteLine(">" + MEMBER.Name + "= " + MEMBER.Data.Data.ToString());
  1510. break;
  1511. case "movies_aka":
  1512. R.movies_aka = (string)MEMBER.Data.Data;
  1513. OSHConsole.WriteLine(">" + MEMBER.Name + "= " + MEMBER.Data.Data.ToString());
  1514. break;
  1515. case "total_subtitles_languages":
  1516. R.total_subtitles_languages = (string)MEMBER.Data.Data;
  1517. OSHConsole.WriteLine(">" + MEMBER.Name + "= " + MEMBER.Data.Data.ToString());
  1518. break;
  1519. case "last_update_strings":
  1520. //R.total_subtitles_languages = (string)MEMBER.Data.Data;
  1521. OSHConsole.WriteLine(">" + MEMBER.Name + ":");
  1522. var luStruct = (XmlRpcValueStruct)MEMBER.Data;
  1523. foreach (XmlRpcStructMember luMemeber in luStruct.Members)
  1524. {
  1525. R.last_update_strings.Add(luMemeber.Name + " [" + luMemeber.Data.Data.ToString() + "]");
  1526. OSHConsole.WriteLine(" >" + luMemeber.Name + "= " + luMemeber.Data.Data.ToString());
  1527. }
  1528. break;
  1529. }
  1530. }
  1531. // Return the response to user !!
  1532. return R;
  1533. }
  1534. }
  1535. }
  1536. else
  1537. {
  1538. OSHConsole.WriteLine(response, DebugCode.Error);
  1539. return new MethodResponseError("Fail", response);
  1540. }
  1541. return new MethodResponseError("Fail", "ServerInfo call failed !");
  1542. }
  1543. /// <summary>
  1544. /// Report wrong subtitle file <--> video file combination
  1545. /// </summary>
  1546. /// <param name="IDSubMovieFile">Identifier of the subtitle file <--> video file combination </param>
  1547. /// <returns>Status of the call operation. If the call success the response will be 'MethodResponseReportWrongMovieHash'</returns>
  1548. public static IMethodResponse ReportWrongMovieHash(string IDSubMovieFile)
  1549. {
  1550. if (TOKEN == "")
  1551. {
  1552. OSHConsole.WriteLine("Can't do this call, 'token' value not set. Please use Log In method first.", DebugCode.Error);
  1553. return new MethodResponseError("Fail", "Can't do this call, 'token' value not set. Please use Log In method first.");
  1554. }
  1555. // Method call ..
  1556. var parms = new List<IXmlRpcValue>();
  1557. parms.Add(new XmlRpcValueBasic(TOKEN, XmlRpcBasicValueType.String));
  1558. parms.Add(new XmlRpcValueBasic(IDSubMovieFile, XmlRpcBasicValueType.String));
  1559. var call = new XmlRpcMethodCall("ReportWrongMovieHash", parms);
  1560. OSHConsole.WriteLine("Sending ReportWrongMovieHash request to the server ...", DebugCode.Good);
  1561. // Send the request to the server
  1562. string response = Utilities.GetStreamString(Utilities.SendRequest(XmlRpcGenerator.Generate(call), XML_PRC_USERAGENT));
  1563. if (!response.Contains("ERROR:"))
  1564. {
  1565. // No error occur, get and decode the response.
  1566. XmlRpcMethodCall[] calls = XmlRpcGenerator.DecodeMethodResponse(response);
  1567. if (calls.Length > 0)
  1568. {
  1569. if (calls[0].Parameters.Count > 0)
  1570. {
  1571. var mainStruct = (XmlRpcValueStruct)calls[0].Parameters[0];
  1572. // Create the response, we'll need it later
  1573. var R = new MethodResponseReportWrongMovieHash();
  1574. // To make sure response is not currepted by server, do it in loop
  1575. foreach (XmlRpcStructMember MEMBER in mainStruct.Members)
  1576. {
  1577. switch (MEMBER.Name)
  1578. {
  1579. case "status":
  1580. R.Status = (string)MEMBER.Data.Data;
  1581. OSHConsole.WriteLine(">" + MEMBER.Name + "= " + MEMBER.Data.Data.ToString());
  1582. break;
  1583. case "seconds":
  1584. R.Seconds = (double)MEMBER.Data.Data;
  1585. OSHConsole.WriteLine(">" + MEMBER.Name + "= " + MEMBER.Data.Data.ToString());
  1586. break;
  1587. }
  1588. }
  1589. // Return the response to user !!
  1590. return R;
  1591. }
  1592. }
  1593. }
  1594. else
  1595. {
  1596. OSHConsole.WriteLine(response, DebugCode.Error);
  1597. return new MethodResponseError("Fail", response);
  1598. }
  1599. return new MethodResponseError("Fail", "ReportWrongMovieHash call failed !");
  1600. }
  1601. /// <summary>
  1602. /// This method is needed to report bad movie hash for imdbid. This method should be used for correcting wrong entries,
  1603. /// when using CheckMovieHash2. Pass moviehash and moviebytesize for file, and imdbid as new, corrected one IMDBID
  1604. /// (id number without trailing zeroes). After some reports, moviehash will be linked to new imdbid.
  1605. /// </summary>
  1606. /// <param name="moviehash">The movie hash</param>
  1607. /// <param name="moviebytesize">The movie size in bytes</param>
  1608. /// <param name="imdbid">The movie imbid</param>
  1609. /// <returns>Status of the call operation. If the call success the response will be 'MethodResponseReportWrongImdbMovie'</returns>
  1610. public static IMethodResponse ReportWrongImdbMovie(string moviehash, string moviebytesize, string imdbid)
  1611. {
  1612. if (TOKEN == "")
  1613. {
  1614. OSHConsole.WriteLine("Can't do this call, 'token' value not set. Please use Log In method first.", DebugCode.Error);
  1615. return new MethodResponseError("Fail", "Can't do this call, 'token' value not set. Please use Log In method first.");
  1616. }
  1617. // Method call ..
  1618. var parms = new List<IXmlRpcValue>();
  1619. parms.Add(new XmlRpcValueBasic(TOKEN, XmlRpcBasicValueType.String));
  1620. var s = new XmlRpcValueStruct(new List<XmlRpcStructMember>());
  1621. s.Members.Add(new XmlRpcStructMember("moviehash", new XmlRpcValueBasic(moviehash)));
  1622. s.Members.Add(new XmlRpcStructMember("moviebytesize", new XmlRpcValueBasic(moviebytesize)));
  1623. s.Members.Add(new XmlRpcStructMember("imdbid", new XmlRpcValueBasic(imdbid)));
  1624. parms.Add(s);
  1625. var call = new XmlRpcMethodCall("ReportWrongImdbMovie", parms);
  1626. OSHConsole.WriteLine("Sending ReportWrongImdbMovie request to the server ...", DebugCode.Good);
  1627. // Send the request to the server
  1628. string response = Utilities.GetStreamString(Utilities.SendRequest(XmlRpcGenerator.Generate(call), XML_PRC_USERAGENT));
  1629. if (!response.Contains("ERROR:"))
  1630. {
  1631. // No error occur, get and decode the response.
  1632. XmlRpcMethodCall[] calls = XmlRpcGenerator.DecodeMethodResponse(response);
  1633. if (calls.Length > 0)
  1634. {
  1635. if (calls[0].Parameters.Count > 0)
  1636. {
  1637. var mainStruct = (XmlRpcValueStruct)calls[0].Parameters[0];
  1638. // Create the response, we'll need it later
  1639. var R = new MethodResponseAddComment();
  1640. // To make sure response is not currepted by server, do it in loop
  1641. foreach (XmlRpcStructMember MEMBER in mainStruct.Members)
  1642. {
  1643. switch (MEMBER.Name)
  1644. {
  1645. case "status": R.Status = (string)MEMBER.Data.Data; OSHConsole.WriteLine(">" + MEMBER.Name + "= " + MEMBER.Data.Data.ToString()); break;
  1646. case "seconds": R.Seconds = (double)MEMBER.Data.Data; OSHConsole.WriteLine(">" + MEMBER.Name + "= " + MEMBER.Data.Data.ToString()); break;
  1647. }
  1648. }
  1649. // Return the response to user !!
  1650. return R;
  1651. }
  1652. }
  1653. }
  1654. else
  1655. {
  1656. OSHConsole.WriteLine(response, DebugCode.Error);
  1657. return new MethodResponseError("Fail", response);
  1658. }
  1659. return new MethodResponseError("Fail", "ReportWrongImdbMovie call failed !");
  1660. }
  1661. /// <summary>
  1662. /// Rate subtitles
  1663. /// </summary>
  1664. /// <param name="idsubtitle">Id of subtitle (NOT subtitle file) user wants to rate </param>
  1665. /// <param name="score">Subtitle rating, must be in interval 1 (worst) to 10 (best). </param>
  1666. /// <returns>Status of the call operation. If the call success the response will be 'MethodResponseSubtitlesVote'</returns>
  1667. public static IMethodResponse SubtitlesVote(int idsubtitle, int score)
  1668. {
  1669. if (TOKEN == "")
  1670. {
  1671. OSHConsole.WriteLine("Can't do this call, 'token' value not set. Please use Log In method first.", DebugCode.Error);
  1672. return new MethodResponseError("Fail", "Can't do this call, 'token' value not set. Please use Log In method first.");
  1673. }
  1674. // Method call ..
  1675. var parms = new List<IXmlRpcValue>();
  1676. parms.Add(new XmlRpcValueBasic(TOKEN, XmlRpcBasicValueType.String));
  1677. var s = new XmlRpcValueStruct(new List<XmlRpcStructMember>());
  1678. s.Members.Add(new XmlRpcStructMember("idsubtitle", new XmlRpcValueBasic(idsubtitle)));
  1679. s.Members.Add(new XmlRpcStructMember("score", new XmlRpcValueBasic(score)));
  1680. parms.Add(s);
  1681. var call = new XmlRpcMethodCall("SubtitlesVote", parms);
  1682. OSHConsole.WriteLine("Sending SubtitlesVote request to the server ...", DebugCode.Good);
  1683. // Send the request to the server
  1684. string response = Utilities.GetStreamString(Utilities.SendRequest(XmlRpcGenerator.Generate(call), XML_PRC_USERAGENT));
  1685. if (!response.Contains("ERROR:"))
  1686. {
  1687. // No error occur, get and decode the response.
  1688. XmlRpcMethodCall[] calls = XmlRpcGenerator.DecodeMethodResponse(response);
  1689. if (calls.Length > 0)
  1690. {
  1691. if (calls[0].Parameters.Count > 0)
  1692. {
  1693. var mainStruct = (XmlRpcValueStruct)calls[0].Parameters[0];
  1694. // Create the response, we'll need it later
  1695. var R = new MethodResponseSubtitlesVote();
  1696. // To make sure response is not currepted by server, do it in loop
  1697. foreach (XmlRpcStructMember MEMBER in mainStruct.Members)
  1698. {
  1699. switch (MEMBER.Name)
  1700. {
  1701. case "status": R.Status = (string)MEMBER.Data.Data; OSHConsole.WriteLine(">" + MEMBER.Name + "= " + MEMBER.Data.Data.ToString()); break;
  1702. case "seconds": R.Seconds = (double)MEMBER.Data.Data; OSHConsole.WriteLine(">" + MEMBER.Name + "= " + MEMBER.Data.Data.ToString()); break;
  1703. case "data":
  1704. var dataStruct = (XmlRpcValueStruct)MEMBER.Data;
  1705. foreach (XmlRpcStructMember dataMemeber in dataStruct.Members)
  1706. {
  1707. OSHConsole.WriteLine(" >" + dataMemeber.Name + "= " + dataMemeber.Data.Data.ToString());
  1708. switch (dataMemeber.Name)
  1709. {
  1710. case "SubRating": R.SubRating = dataMemeber.Data.Data.ToString(); break;
  1711. case "SubSumVotes": R.SubSumVotes = dataMemeber.Data.Data.ToString(); break;
  1712. case "IDSubtitle": R.IDSubtitle = dataMemeber.Data.Data.ToString(); break;
  1713. }
  1714. }
  1715. break;
  1716. }
  1717. }
  1718. // Return the response to user !!
  1719. return R;
  1720. }
  1721. }
  1722. }
  1723. else
  1724. {
  1725. OSHConsole.WriteLine(response, DebugCode.Error);
  1726. return new MethodResponseError("Fail", response);
  1727. }
  1728. return new MethodResponseError("Fail", "SubtitlesVote call failed !");
  1729. }
  1730. /// <summary>
  1731. /// Add comment to a subtitle
  1732. /// </summary>
  1733. /// <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>
  1734. /// <param name="comment">User's comment</param>
  1735. /// <param name="badsubtitle">Optional parameter. If set to 1, subtitles are marked as bad.</param>
  1736. /// <returns>Status of the call operation. If the call success the response will be 'MethodResponseAddComment'</returns>
  1737. public static IMethodResponse AddComment(int idsubtitle, string comment, int badsubtitle)
  1738. {
  1739. if (TOKEN == "")
  1740. {
  1741. OSHConsole.WriteLine("Can't do this call, 'token' value not set. Please use Log In method first.", DebugCode.Error);
  1742. return new MethodResponseError("Fail", "Can't do this call, 'token' value not set. Please use Log In method first.");
  1743. }
  1744. // Method call ..
  1745. var parms = new List<IXmlRpcValue>();
  1746. parms.Add(new XmlRpcValueBasic(TOKEN, XmlRpcBasicValueType.String));
  1747. var s = new XmlRpcValueStruct(new List<XmlRpcStructMember>());
  1748. s.Members.Add(new XmlRpcStructMember("idsubtitle", new XmlRpcValueBasic(idsubtitle)));
  1749. s.Members.Add(new XmlRpcStructMember("comment", new XmlRpcValueBasic(comment)));
  1750. s.Members.Add(new XmlRpcStructMember("badsubtitle", new XmlRpcValueBasic(badsubtitle)));
  1751. parms.Add(s);
  1752. var call = new XmlRpcMethodCall("AddComment", parms);
  1753. OSHConsole.WriteLine("Sending AddComment request to the server ...", DebugCode.Good);
  1754. // Send the request to the server
  1755. string response = Utilities.GetStreamString(Utilities.SendRequest(XmlRpcGenerator.Generate(call), XML_PRC_USERAGENT));
  1756. if (!response.Contains("ERROR:"))
  1757. {
  1758. // No error occur, get and decode the response.
  1759. XmlRpcMethodCall[] calls = XmlRpcGenerator.DecodeMethodResponse(response);
  1760. if (calls.Length > 0)
  1761. {
  1762. if (calls[0].Parameters.Count > 0)
  1763. {
  1764. var mainStruct = (XmlRpcValueStruct)calls[0].Parameters[0];
  1765. // Create the response, we'll need it later
  1766. var R = new MethodResponseAddComment();
  1767. // To make sure response is not currepted by server, do it in loop
  1768. foreach (var MEMBER in mainStruct.Members)
  1769. {
  1770. switch (MEMBER.Name)
  1771. {
  1772. case "status": R.Status = (string)MEMBER.Data.Data; OSHConsole.WriteLine(">" + MEMBER.Name + "= " + MEMBER.Data.Data.ToString()); break;
  1773. case "seconds": R.Seconds = (double)MEMBER.Data.Data; OSHConsole.WriteLine(">" + MEMBER.Name + "= " + MEMBER.Data.Data.ToString()); break;
  1774. }
  1775. }
  1776. // Return the response to user !!
  1777. return R;
  1778. }
  1779. }
  1780. }
  1781. else
  1782. {
  1783. OSHConsole.WriteLine(response, DebugCode.Error);
  1784. return new MethodResponseError("Fail", response);
  1785. }
  1786. return new MethodResponseError("Fail", "AddComment call failed !");
  1787. }
  1788. /// <summary>
  1789. /// Add new request for subtitles, user must be logged in
  1790. /// </summary>
  1791. /// <param name="sublanguageid">The subtitle language id 3 length</param>
  1792. /// <param name="idmovieimdb">http://www.imdb.com/</param>
  1793. /// <param name="comment">The comment</param>
  1794. /// <returns>Status of the call operation. If the call success the response will be 'MethodResponseAddRequest'</returns>
  1795. public static IMethodResponse AddRequest(string sublanguageid, string idmovieimdb, string comment)
  1796. {
  1797. if (TOKEN == "")
  1798. {
  1799. OSHConsole.WriteLine("Can't do this call, 'token' value not set. Please use Log In method first.", DebugCode.Error);
  1800. return new MethodResponseError("Fail", "Can't do this call, 'token' value not set. Please use Log In method first.");
  1801. }
  1802. // Method call ..
  1803. var parms = new List<IXmlRpcValue>();
  1804. parms.Add(new XmlRpcValueBasic(TOKEN, XmlRpcBasicValueType.String));
  1805. var s = new XmlRpcValueStruct(new List<XmlRpcStructMember>());
  1806. s.Members.Add(new XmlRpcStructMember("sublanguageid", new XmlRpcValueBasic(sublanguageid)));
  1807. s.Members.Add(new XmlRpcStructMember("idmovieimdb", new XmlRpcValueBasic(idmovieimdb)));
  1808. s.Members.Add(new XmlRpcStructMember("comment", new XmlRpcValueBasic(comment)));
  1809. parms.Add(s);
  1810. var call = new XmlRpcMethodCall("AddRequest", parms);
  1811. OSHConsole.WriteLine("Sending AddRequest request to the server ...", DebugCode.Good);
  1812. // Send the request to the server
  1813. string response = Utilities.GetStreamString(Utilities.SendRequest(XmlRpcGenerator.Generate(call), XML_PRC_USERAGENT));
  1814. if (!response.Contains("ERROR:"))
  1815. {
  1816. // No error occur, get and decode the response.
  1817. XmlRpcMethodCall[] calls = XmlRpcGenerator.DecodeMethodResponse(response);
  1818. if (calls.Length > 0)
  1819. {
  1820. if (calls[0].Parameters.Count > 0)
  1821. {
  1822. var mainStruct = (XmlRpcValueStruct)calls[0].Parameters[0];
  1823. // Create the response, we'll need it later
  1824. var R = new MethodResponseAddRequest();
  1825. // To make sure response is not currepted by server, do it in loop
  1826. foreach (XmlRpcStructMember MEMBER in mainStruct.Members)
  1827. {
  1828. switch (MEMBER.Name)
  1829. {
  1830. case "status": R.Status = (string)MEMBER.Data.Data; OSHConsole.WriteLine(">" + MEMBER.Name + "= " + MEMBER.Data.Data.ToString()); break;
  1831. case "seconds": R.Seconds = (double)MEMBER.Data.Data; OSHConsole.WriteLine(">" + MEMBER.Name + "= " + MEMBER.Data.Data.ToString()); break;
  1832. case "data":
  1833. var dataStruct = (XmlRpcValueStruct)MEMBER.Data;
  1834. foreach (XmlRpcStructMember dataMemeber in dataStruct.Members)
  1835. {
  1836. switch (dataMemeber.Name)
  1837. {
  1838. case "request_url": R.request_url = dataMemeber.Data.Data.ToString(); OSHConsole.WriteLine(">" + dataMemeber.Name + "= " + dataMemeber.Data.Data.ToString()); break;
  1839. }
  1840. }
  1841. break;
  1842. }
  1843. }
  1844. // Return the response to user !!
  1845. return R;
  1846. }
  1847. }
  1848. }
  1849. else
  1850. {
  1851. OSHConsole.WriteLine(response, DebugCode.Error);
  1852. return new MethodResponseError("Fail", response);
  1853. }
  1854. return new MethodResponseError("Fail", "AddRequest call failed !");
  1855. }
  1856. /*User interface*/
  1857. /// <summary>
  1858. /// Get list of supported subtitle languages
  1859. /// </summary>
  1860. /// <param name="language">ISO639-1 2-letter language code of user's interface language. </param>
  1861. /// <returns>Status of the call operation. If the call success the response will be 'MethodResponseGetSubLanguages'</returns>
  1862. public static IMethodResponse GetSubLanguages(string language)
  1863. {
  1864. if (TOKEN == "")
  1865. {
  1866. OSHConsole.WriteLine("Can't do this call, 'token' value not set. Please use Log In method first.", DebugCode.Error);
  1867. return new MethodResponseError("Fail", "Can't do this call, 'token' value not set. Please use Log In method first.");
  1868. }
  1869. // Method call ..
  1870. var parms = new List<IXmlRpcValue>();
  1871. parms.Add(new XmlRpcValueBasic(TOKEN));
  1872. parms.Add(new XmlRpcValueBasic(language));
  1873. var call = new XmlRpcMethodCall("GetSubLanguages", parms);
  1874. OSHConsole.WriteLine("Sending GetSubLanguages request to the server ...", DebugCode.Good);
  1875. // Send the request to the server
  1876. string response = Utilities.GetStreamString(Utilities.SendRequest(XmlRpcGenerator.Generate(call), XML_PRC_USERAGENT));
  1877. if (!response.Contains("ERROR:"))
  1878. {
  1879. // No error occur, get and decode the response.
  1880. XmlRpcMethodCall[] calls = XmlRpcGenerator.DecodeMethodResponse(response);
  1881. if (calls.Length > 0)
  1882. {
  1883. if (calls[0].Parameters.Count > 0)
  1884. {
  1885. var mainStruct = (XmlRpcValueStruct)calls[0].Parameters[0];
  1886. // Create the response, we'll need it later
  1887. var R = new MethodResponseGetSubLanguages();
  1888. // To make sure response is not currepted by server, do it in loop
  1889. foreach (XmlRpcStructMember MEMBER in mainStruct.Members)
  1890. {
  1891. switch (MEMBER.Name)
  1892. {
  1893. case "status": R.Status = (string)MEMBER.Data.Data; OSHConsole.WriteLine(">" + MEMBER.Name + "= " + MEMBER.Data.Data.ToString()); break;
  1894. case "seconds": R.Seconds = (double)MEMBER.Data.Data; OSHConsole.WriteLine(">" + MEMBER.Name + "= " + MEMBER.Data.Data.ToString()); break;
  1895. case "data":// array of structs
  1896. var array = (XmlRpcValueArray)MEMBER.Data;
  1897. foreach (IXmlRpcValue value in array.Values)
  1898. {
  1899. if (value is XmlRpcValueStruct)
  1900. {
  1901. var valueStruct = (XmlRpcValueStruct)value;
  1902. var lang = new SubtitleLanguage();
  1903. OSHConsole.WriteLine(">SubLanguage:");
  1904. foreach (XmlRpcStructMember langMemeber in valueStruct.Members)
  1905. {
  1906. OSHConsole.WriteLine(" >" + langMemeber.Name + "= " + langMemeber.Data.Data.ToString());
  1907. switch (langMemeber.Name)
  1908. {
  1909. case "SubLanguageID": lang.SubLanguageID = langMemeber.Data.Data.ToString(); break;
  1910. case "LanguageName": lang.LanguageName = langMemeber.Data.Data.ToString(); break;
  1911. case "ISO639": lang.ISO639 = langMemeber.Data.Data.ToString(); break;
  1912. }
  1913. }
  1914. R.Languages.Add(lang);
  1915. }
  1916. else
  1917. {
  1918. OSHConsole.WriteLine(">" + MEMBER.Name + "= " +
  1919. MEMBER.Data.Data.ToString() + " [Struct expected !]", DebugCode.Warning);
  1920. }
  1921. }
  1922. break;
  1923. }
  1924. }
  1925. // Return the response to user !!
  1926. return R;
  1927. }
  1928. }
  1929. }
  1930. else
  1931. {
  1932. OSHConsole.WriteLine(response, DebugCode.Error);
  1933. return new MethodResponseError("Fail", response);
  1934. }
  1935. return new MethodResponseError("Fail", "GetSubLanguages call failed !");
  1936. }
  1937. /// <summary>
  1938. /// Detect language for given strings
  1939. /// </summary>
  1940. /// <param name="texts">Array of strings you want language detected for</param>
  1941. /// <param name="encodingUsed">The encoding that will be used to get buffer of given strings. (this is not OS official parameter)</param>
  1942. /// <returns>Status of the call operation. If the call success the response will be 'MethodResponseDetectLanguage'</returns>
  1943. public static IMethodResponse DetectLanguage(string[] texts, Encoding encodingUsed)
  1944. {
  1945. if (TOKEN == "")
  1946. {
  1947. OSHConsole.WriteLine("Can't do this call, 'token' value not set. Please use Log In method first.", DebugCode.Error);
  1948. return new MethodResponseError("Fail", "Can't do this call, 'token' value not set. Please use Log In method first.");
  1949. }
  1950. // Method call ..
  1951. var parms = new List<IXmlRpcValue>();
  1952. parms.Add(new XmlRpcValueBasic(TOKEN, XmlRpcBasicValueType.String));
  1953. // We need to gzip texts then code them with base 24
  1954. var decodedTexts = new List<string>();
  1955. foreach (string text in texts)
  1956. {
  1957. // compress
  1958. Stream str = new MemoryStream();
  1959. byte[] stringData = encodingUsed.GetBytes(text);
  1960. str.Write(stringData, 0, stringData.Length);
  1961. str.Position = 0;
  1962. byte[] data = Utilities.Compress(str);
  1963. //base 64
  1964. decodedTexts.Add(Convert.ToBase64String(data));
  1965. }
  1966. parms.Add(new XmlRpcValueArray(decodedTexts.ToArray()));
  1967. var call = new XmlRpcMethodCall("DetectLanguage", parms);
  1968. OSHConsole.WriteLine("Sending DetectLanguage request to the server ...", DebugCode.Good);
  1969. // Send the request to the server
  1970. string response = Utilities.GetStreamString(Utilities.SendRequest(XmlRpcGenerator.Generate(call), XML_PRC_USERAGENT));
  1971. if (!response.Contains("ERROR:"))
  1972. {
  1973. // No error occur, get and decode the response.
  1974. XmlRpcMethodCall[] calls = XmlRpcGenerator.DecodeMethodResponse(response);
  1975. if (calls.Length > 0)
  1976. {
  1977. if (calls[0].Parameters.Count > 0)
  1978. {
  1979. var mainStruct = (XmlRpcValueStruct)calls[0].Parameters[0];
  1980. // Create the response, we'll need it later
  1981. var R = new MethodResponseDetectLanguage();
  1982. // To make sure response is not currepted by server, do it in loop
  1983. foreach (XmlRpcStructMember MEMBER in mainStruct.Members)
  1984. {
  1985. switch (MEMBER.Name)
  1986. {
  1987. case "status": R.Status = (string)MEMBER.Data.Data; OSHConsole.WriteLine(">" + MEMBER.Name + "= " + MEMBER.Data.Data.ToString()); break;
  1988. case "seconds": R.Seconds = (double)MEMBER.Data.Data; OSHConsole.WriteLine(">" + MEMBER.Name + "= " + MEMBER.Data.Data.ToString()); break;
  1989. case "data":
  1990. if (MEMBER.Data is XmlRpcValueStruct)
  1991. {
  1992. OSHConsole.WriteLine(">Languages:");
  1993. var dataStruct = (XmlRpcValueStruct)MEMBER.Data;
  1994. foreach (XmlRpcStructMember dataMember in dataStruct.Members)
  1995. {
  1996. var lang = new DetectLanguageResult();
  1997. lang.InputSample = dataMember.Name;
  1998. lang.LanguageID = dataMember.Data.Data.ToString();
  1999. R.Results.Add(lang);
  2000. OSHConsole.WriteLine(" >" + dataMember.Name + " (" + dataMember.Data.Data.ToString() + ")");
  2001. }
  2002. }
  2003. else
  2004. {
  2005. OSHConsole.WriteLine(">Languages ?? Struct expected but server return another type!!", DebugCode.Warning);
  2006. }
  2007. break;
  2008. }
  2009. }
  2010. // Return the response to user !!
  2011. return R;
  2012. }
  2013. }
  2014. }
  2015. else
  2016. {
  2017. OSHConsole.WriteLine(response, DebugCode.Error);
  2018. return new MethodResponseError("Fail", response);
  2019. }
  2020. return new MethodResponseError("Fail", "DetectLanguage call failed !");
  2021. }
  2022. /// <summary>
  2023. /// Get available translations for given program
  2024. /// </summary>
  2025. /// <param name="program">Name of the program/client application you want translations for. Currently supported values: subdownloader, oscar</param>
  2026. /// <returns>Status of the call operation. If the call success the response will be 'MethodResponseGetAvailableTranslations'</returns>
  2027. public static IMethodResponse GetAvailableTranslations(string program)
  2028. {
  2029. if (TOKEN == "")
  2030. {
  2031. OSHConsole.WriteLine("Can't do this call, 'token' value not set. Please use Log In method first.", DebugCode.Error);
  2032. return new MethodResponseError("Fail", "Can't do this call, 'token' value not set. Please use Log In method first.");
  2033. }
  2034. // Method call ..
  2035. var parms = new List<IXmlRpcValue>();
  2036. parms.Add(new XmlRpcValueBasic(TOKEN));
  2037. parms.Add(new XmlRpcValueBasic(program));
  2038. var call = new XmlRpcMethodCall("GetAvailableTranslations", parms);
  2039. OSHConsole.WriteLine("Sending GetAvailableTranslations request to the server ...", DebugCode.Good);
  2040. // Send the request to the server
  2041. string response = Utilities.GetStreamString(Utilities.SendRequest(XmlRpcGenerator.Generate(call), XML_PRC_USERAGENT));
  2042. if (!response.Contains("ERROR:"))
  2043. {
  2044. // No error occur, get and decode the response.
  2045. XmlRpcMethodCall[] calls = XmlRpcGenerator.DecodeMethodResponse(response);
  2046. if (calls.Length > 0)
  2047. {
  2048. if (calls[0].Parameters.Count > 0)
  2049. {
  2050. var mainStruct = (XmlRpcValueStruct)calls[0].Parameters[0];
  2051. // Create the response, we'll need it later
  2052. var R = new MethodResponseGetAvailableTranslations();
  2053. // To make sure response is not currepted by server, do it in loop
  2054. foreach (XmlRpcStructMember MEMBER in mainStruct.Members)
  2055. {
  2056. switch (MEMBER.Name)
  2057. {
  2058. case "status": R.Status = (string)MEMBER.Data.Data; OSHConsole.WriteLine(">" + MEMBER.Name + "= " + MEMBER.Data.Data.ToString()); break;
  2059. case "seconds": R.Seconds = (double)MEMBER.Data.Data; OSHConsole.WriteLine(">" + MEMBER.Name + "= " + MEMBER.Data.Data.ToString()); break;
  2060. case "data":
  2061. var dataStruct = (XmlRpcValueStruct)MEMBER.Data;
  2062. OSHConsole.WriteLine(">data:");
  2063. foreach (XmlRpcStructMember dataMember in dataStruct.Members)
  2064. {
  2065. if (dataMember.Data is XmlRpcValueStruct)
  2066. {
  2067. var resStruct = (XmlRpcValueStruct)dataMember.Data;
  2068. var res = new GetAvailableTranslationsResult();
  2069. res.LanguageID = dataMember.Name;
  2070. OSHConsole.WriteLine(" >LanguageID: " + dataMember.Name);
  2071. foreach (XmlRpcStructMember resMember in resStruct.Members)
  2072. {
  2073. switch (resMember.Name)
  2074. {
  2075. case "LastCreated": res.LastCreated = resMember.Data.Data.ToString(); OSHConsole.WriteLine(" >" + resMember.Name + "= " + resMember.Data.Data.ToString()); break;
  2076. case "StringsNo": res.StringsNo = resMember.Data.Data.ToString(); OSHConsole.WriteLine(" >" + resMember.Name + "= " + resMember.Data.Data.ToString()); break;
  2077. }
  2078. R.Results.Add(res);
  2079. }
  2080. }
  2081. else
  2082. {
  2083. OSHConsole.WriteLine(" >Struct expected !!", DebugCode.Warning);
  2084. }
  2085. }
  2086. break;
  2087. }
  2088. }
  2089. // Return the response to user !!
  2090. return R;
  2091. }
  2092. }
  2093. }
  2094. else
  2095. {
  2096. OSHConsole.WriteLine(response, DebugCode.Error);
  2097. return new MethodResponseError("Fail", response);
  2098. }
  2099. return new MethodResponseError("Fail", "GetAvailableTranslations call failed !");
  2100. }
  2101. /// <summary>
  2102. /// Get a translation for given program and language
  2103. /// </summary>
  2104. /// <param name="iso639">language ​ISO639-1 2-letter code </param>
  2105. /// <param name="format">available formats: [gnugettext compatible: mo, po] and [additional: txt, xml]</param>
  2106. /// <param name="program">Name of the program/client application you want translations for. (currently supported values: subdownloader, oscar)</param>
  2107. /// <returns>Status of the call operation. If the call success the response will be 'MethodResponseGetTranslation'</returns>
  2108. public static IMethodResponse GetTranslation(string iso639, string format, string program)
  2109. {
  2110. if (TOKEN == "")
  2111. {
  2112. OSHConsole.WriteLine("Can't do this call, 'token' value not set. Please use Log In method first.", DebugCode.Error);
  2113. return new MethodResponseError("Fail", "Can't do this call, 'token' value not set. Please use Log In method first.");
  2114. }
  2115. // Method call ..
  2116. var parms = new List<IXmlRpcValue>();
  2117. parms.Add(new XmlRpcValueBasic(TOKEN));
  2118. parms.Add(new XmlRpcValueBasic(iso639));
  2119. parms.Add(new XmlRpcValueBasic(format));
  2120. parms.Add(new XmlRpcValueBasic(program));
  2121. var call = new XmlRpcMethodCall("GetTranslation", parms);
  2122. OSHConsole.WriteLine("Sending GetTranslation request to the server ...", DebugCode.Good);
  2123. // Send the request to the server
  2124. //File.WriteAllText(".\\REQUEST_GetTranslation.xml", Encoding.ASCII.GetString(XmlRpcGenerator.Generate(call)));
  2125. string response = Utilities.GetStreamString(Utilities.SendRequest(XmlRpcGenerator.Generate(call), XML_PRC_USERAGENT));
  2126. if (!response.Contains("ERROR:"))
  2127. {
  2128. // No error occur, get and decode the response.
  2129. XmlRpcMethodCall[] calls = XmlRpcGenerator.DecodeMethodResponse(response);
  2130. if (calls.Length > 0)
  2131. {
  2132. if (calls[0].Parameters.Count > 0)
  2133. {
  2134. var mainStruct = (XmlRpcValueStruct)calls[0].Parameters[0];
  2135. // Create the response, we'll need it later
  2136. var R = new MethodResponseGetTranslation();
  2137. // To make sure response is not currepted by server, do it in loop
  2138. foreach (XmlRpcStructMember MEMBER in mainStruct.Members)
  2139. {
  2140. switch (MEMBER.Name)
  2141. {
  2142. case "status": R.Status = (string)MEMBER.Data.Data; OSHConsole.WriteLine(">" + MEMBER.Name + "= " + MEMBER.Data.Data.ToString()); break;
  2143. case "seconds": R.Seconds = (double)MEMBER.Data.Data; OSHConsole.WriteLine(">" + MEMBER.Name + "= " + MEMBER.Data.Data.ToString()); break;
  2144. case "data": R.ContentData = (string)MEMBER.Data.Data; OSHConsole.WriteLine(">" + MEMBER.Name + "= " + MEMBER.Data.Data.ToString()); break;
  2145. }
  2146. }
  2147. // Return the response to user !!
  2148. return R;
  2149. }
  2150. }
  2151. }
  2152. else
  2153. {
  2154. OSHConsole.WriteLine(response, DebugCode.Error);
  2155. return new MethodResponseError("Fail", response);
  2156. }
  2157. return new MethodResponseError("Fail", "GetTranslation call failed !");
  2158. }
  2159. /// <summary>
  2160. /// Check for the latest version of given application
  2161. /// </summary>
  2162. /// <param name="program">name of the program/client application you want to check. (Currently supported values: subdownloader, oscar)</param>
  2163. /// <returns>Status of the call operation. If the call success the response will be 'MethodResponseAutoUpdate'</returns>
  2164. public static IMethodResponse AutoUpdate(string program)
  2165. {
  2166. /*if (TOKEN == "")
  2167. {
  2168. OSHConsole.WriteLine("Can't do this call, 'token' value not set. Please use Log In method first.", DebugCode.Error);
  2169. return new MethodResponseError("Fail", "Can't do this call, 'token' value not set. Please use Log In method first.");
  2170. }*/
  2171. // Method call ..
  2172. var parms = new List<IXmlRpcValue>();
  2173. // parms.Add(new XmlRpcValueBasic(TOKEN));
  2174. parms.Add(new XmlRpcValueBasic(program));
  2175. // parms.Add(new XmlRpcValueBasic(XML_PRC_USERAGENT));
  2176. var call = new XmlRpcMethodCall("AutoUpdate", parms);
  2177. OSHConsole.WriteLine("Sending AutoUpdate request to the server ...", DebugCode.Good);
  2178. // Send the request to the server
  2179. string response = Utilities.GetStreamString(Utilities.SendRequest(XmlRpcGenerator.Generate(call), XML_PRC_USERAGENT));
  2180. if (!response.Contains("ERROR:"))
  2181. {
  2182. // No error occur, get and decode the response.
  2183. XmlRpcMethodCall[] calls = XmlRpcGenerator.DecodeMethodResponse(response);
  2184. if (calls.Length > 0)
  2185. {
  2186. if (calls[0].Parameters.Count > 0)
  2187. {
  2188. var mainStruct = (XmlRpcValueStruct)calls[0].Parameters[0];
  2189. // Create the response, we'll need it later
  2190. var R = new MethodResponseAutoUpdate();
  2191. // To make sure response is not currepted by server, do it in loop
  2192. foreach (XmlRpcStructMember MEMBER in mainStruct.Members)
  2193. {
  2194. switch (MEMBER.Name)
  2195. {
  2196. case "status": R.Status = (string)MEMBER.Data.Data; OSHConsole.WriteLine(">" + MEMBER.Name + "= " + MEMBER.Data.Data.ToString()); break;
  2197. case "seconds": R.Seconds = (double)MEMBER.Data.Data; OSHConsole.WriteLine(">" + MEMBER.Name + "= " + MEMBER.Data.Data.ToString()); break;
  2198. case "version": R.version = (string)MEMBER.Data.Data; OSHConsole.WriteLine(">" + MEMBER.Name + "= " + MEMBER.Data.Data.ToString()); break;
  2199. case "url_windows": R.url_windows = (string)MEMBER.Data.Data; OSHConsole.WriteLine(">" + MEMBER.Name + "= " + MEMBER.Data.Data.ToString()); break;
  2200. case "url_linux": R.url_linux = (string)MEMBER.Data.Data; OSHConsole.WriteLine(">" + MEMBER.Name + "= " + MEMBER.Data.Data.ToString()); break;
  2201. case "comments": R.comments = (string)MEMBER.Data.Data; OSHConsole.WriteLine(">" + MEMBER.Name + "= " + MEMBER.Data.Data.ToString()); break;
  2202. }
  2203. }
  2204. // Return the response to user !!
  2205. return R;
  2206. }
  2207. }
  2208. }
  2209. else
  2210. {
  2211. OSHConsole.WriteLine(response, DebugCode.Error);
  2212. return new MethodResponseError("Fail", response);
  2213. }
  2214. return new MethodResponseError("Fail", "AutoUpdate call failed !");
  2215. }
  2216. /*Checking*/
  2217. /// <summary>
  2218. /// Check if video file hashes are already stored in the database
  2219. /// </summary>
  2220. /// <param name="hashes">Array of video file hashes</param>
  2221. /// <returns>Status of the call operation. If the call success the response will be 'MethodResponseCheckMovieHash'</returns>
  2222. public static IMethodResponse CheckMovieHash(string[] hashes)
  2223. {
  2224. if (TOKEN == "")
  2225. {
  2226. OSHConsole.WriteLine("Can't do this call, 'token' value not set. Please use Log In method first.", DebugCode.Error);
  2227. return new MethodResponseError("Fail", "Can't do this call, 'token' value not set. Please use Log In method first.");
  2228. }
  2229. // Method call ..
  2230. var parms = new List<IXmlRpcValue>();
  2231. parms.Add(new XmlRpcValueBasic(TOKEN));
  2232. parms.Add(new XmlRpcValueArray(hashes));
  2233. var call = new XmlRpcMethodCall("CheckMovieHash", parms);
  2234. OSHConsole.WriteLine("Sending CheckMovieHash request to the server ...", DebugCode.Good);
  2235. // Send the request to the server
  2236. string response = Utilities.GetStreamString(Utilities.SendRequest(XmlRpcGenerator.Generate(call), XML_PRC_USERAGENT));
  2237. if (!response.Contains("ERROR:"))
  2238. {
  2239. // No error occur, get and decode the response.
  2240. XmlRpcMethodCall[] calls = XmlRpcGenerator.DecodeMethodResponse(response);
  2241. if (calls.Length > 0)
  2242. {
  2243. if (calls[0].Parameters.Count > 0)
  2244. {
  2245. var mainStruct = (XmlRpcValueStruct)calls[0].Parameters[0];
  2246. // Create the response, we'll need it later
  2247. var R = new MethodResponseCheckMovieHash();
  2248. // To make sure response is not currepted by server, do it in loop
  2249. foreach (XmlRpcStructMember MEMBER in mainStruct.Members)
  2250. {
  2251. switch (MEMBER.Name)
  2252. {
  2253. case "status": R.Status = (string)MEMBER.Data.Data; OSHConsole.WriteLine(">" + MEMBER.Name + "= " + MEMBER.Data.Data.ToString()); break;
  2254. case "seconds": R.Seconds = (double)MEMBER.Data.Data; OSHConsole.WriteLine(">" + MEMBER.Name + "= " + MEMBER.Data.Data.ToString()); break;
  2255. case "data":
  2256. var dataStruct = (XmlRpcValueStruct)MEMBER.Data;
  2257. OSHConsole.WriteLine(">Data:");
  2258. foreach (XmlRpcStructMember dataMember in dataStruct.Members)
  2259. {
  2260. var res = new CheckMovieHashResult();
  2261. res.Name = dataMember.Name;
  2262. OSHConsole.WriteLine(" >" + res.Name + ":");
  2263. var movieStruct = (XmlRpcValueStruct)dataMember.Data;
  2264. foreach (XmlRpcStructMember movieMember in movieStruct.Members)
  2265. {
  2266. switch (movieMember.Name)
  2267. {
  2268. case "MovieHash": res.MovieHash = movieMember.Data.Data.ToString(); OSHConsole.WriteLine(" >" + movieMember.Name + "= " + movieMember.Data.Data.ToString()); break;
  2269. case "MovieImdbID": res.MovieImdbID = movieMember.Data.Data.ToString(); OSHConsole.WriteLine(" >" + movieMember.Name + "= " + movieMember.Data.Data.ToString()); break;
  2270. case "MovieName": res.MovieName = movieMember.Data.Data.ToString(); OSHConsole.WriteLine(" >" + movieMember.Name + "= " + movieMember.Data.Data.ToString()); break;
  2271. case "MovieYear": res.MovieYear = movieMember.Data.Data.ToString(); OSHConsole.WriteLine(" >" + movieMember.Name + "= " + movieMember.Data.Data.ToString()); break;
  2272. }
  2273. }
  2274. R.Results.Add(res);
  2275. }
  2276. break;
  2277. }
  2278. }
  2279. // Return the response to user !!
  2280. return R;
  2281. }
  2282. }
  2283. }
  2284. else
  2285. {
  2286. OSHConsole.WriteLine(response, DebugCode.Error);
  2287. return new MethodResponseError("Fail", response);
  2288. }
  2289. return new MethodResponseError("Fail", "CheckMovieHash call failed !");
  2290. }
  2291. /// <summary>
  2292. /// Check if video file hashes are already stored in the database. This method returns matching !MovieImdbID, MovieName, MovieYear, SeriesSeason, SeriesEpisode,
  2293. /// MovieKind if available for each $moviehash, always sorted by SeenCount DESC.
  2294. /// </summary>
  2295. /// <param name="hashes">Array of video file hashes</param>
  2296. /// <returns>Status of the call operation. If the call success the response will be 'MethodResponseCheckMovieHash2'</returns>
  2297. public static IMethodResponse CheckMovieHash2(string[] hashes)
  2298. {
  2299. if (TOKEN == "")
  2300. {
  2301. OSHConsole.WriteLine("Can't do this call, 'token' value not set. Please use Log In method first.", DebugCode.Error);
  2302. return new MethodResponseError("Fail", "Can't do this call, 'token' value not set. Please use Log In method first.");
  2303. }
  2304. // Method call ..
  2305. var parms = new List<IXmlRpcValue>();
  2306. parms.Add(new XmlRpcValueBasic(TOKEN));
  2307. parms.Add(new XmlRpcValueArray(hashes));
  2308. var call = new XmlRpcMethodCall("CheckMovieHash2", parms);
  2309. OSHConsole.WriteLine("Sending CheckMovieHash2 request to the server ...", DebugCode.Good);
  2310. // Send the request to the server
  2311. string response = Utilities.GetStreamString(Utilities.SendRequest(XmlRpcGenerator.Generate(call), XML_PRC_USERAGENT));
  2312. if (!response.Contains("ERROR:"))
  2313. {
  2314. // No error occur, get and decode the response.
  2315. XmlRpcMethodCall[] calls = XmlRpcGenerator.DecodeMethodResponse(response);
  2316. if (calls.Length > 0)
  2317. {
  2318. if (calls[0].Parameters.Count > 0)
  2319. {
  2320. var mainStruct = (XmlRpcValueStruct)calls[0].Parameters[0];
  2321. // Create the response, we'll need it later
  2322. var R = new MethodResponseCheckMovieHash2();
  2323. // To make sure response is not currepted by server, do it in loop
  2324. foreach (XmlRpcStructMember MEMBER in mainStruct.Members)
  2325. {
  2326. switch (MEMBER.Name)
  2327. {
  2328. case "status": R.Status = (string)MEMBER.Data.Data; OSHConsole.WriteLine(">" + MEMBER.Name + "= " + MEMBER.Data.Data.ToString()); break;
  2329. case "seconds": R.Seconds = (double)MEMBER.Data.Data; OSHConsole.WriteLine(">" + MEMBER.Name + "= " + MEMBER.Data.Data.ToString()); break;
  2330. case "data":
  2331. var dataStruct = (XmlRpcValueStruct)MEMBER.Data;
  2332. OSHConsole.WriteLine(">Data:");
  2333. foreach (XmlRpcStructMember dataMember in dataStruct.Members)
  2334. {
  2335. var res = new CheckMovieHash2Result();
  2336. res.Name = dataMember.Name;
  2337. OSHConsole.WriteLine(" >" + res.Name + ":");
  2338. var dataArray = (XmlRpcValueArray)dataMember.Data;
  2339. foreach (XmlRpcValueStruct movieStruct in dataArray.Values)
  2340. {
  2341. var d = new CheckMovieHash2Data();
  2342. foreach (XmlRpcStructMember movieMember in movieStruct.Members)
  2343. {
  2344. switch (movieMember.Name)
  2345. {
  2346. case "MovieHash": d.MovieHash = movieMember.Data.Data.ToString(); OSHConsole.WriteLine(" >" + movieMember.Name + "= " + movieMember.Data.Data.ToString()); break;
  2347. case "MovieImdbID": d.MovieImdbID = movieMember.Data.Data.ToString(); OSHConsole.WriteLine(" >" + movieMember.Name + "= " + movieMember.Data.Data.ToString()); break;
  2348. case "MovieName": d.MovieName = movieMember.Data.Data.ToString(); OSHConsole.WriteLine(" >" + movieMember.Name + "= " + movieMember.Data.Data.ToString()); break;
  2349. case "MovieYear": d.MovieYear = movieMember.Data.Data.ToString(); OSHConsole.WriteLine(" >" + movieMember.Name + "= " + movieMember.Data.Data.ToString()); break;
  2350. case "MovieKind": d.MovieKind = movieMember.Data.Data.ToString(); OSHConsole.WriteLine(" >" + movieMember.Name + "= " + movieMember.Data.Data.ToString()); break;
  2351. case "SeriesSeason": d.SeriesSeason = movieMember.Data.Data.ToString(); OSHConsole.WriteLine(" >" + movieMember.Name + "= " + movieMember.Data.Data.ToString()); break;
  2352. case "SeriesEpisode": d.SeriesEpisode = movieMember.Data.Data.ToString(); OSHConsole.WriteLine(" >" + movieMember.Name + "= " + movieMember.Data.Data.ToString()); break;
  2353. case "SeenCount": d.MovieYear = movieMember.Data.Data.ToString(); OSHConsole.WriteLine(" >" + movieMember.Name + "= " + movieMember.Data.Data.ToString()); break;
  2354. }
  2355. }
  2356. res.Items.Add(d);
  2357. }
  2358. R.Results.Add(res);
  2359. }
  2360. break;
  2361. }
  2362. }
  2363. // Return the response to user !!
  2364. return R;
  2365. }
  2366. }
  2367. }
  2368. else
  2369. {
  2370. OSHConsole.WriteLine(response, DebugCode.Error);
  2371. return new MethodResponseError("Fail", response);
  2372. }
  2373. return new MethodResponseError("Fail", "CheckMovieHash2 call failed !");
  2374. }
  2375. /// <summary>
  2376. /// Check if given subtitle files are already stored in the database
  2377. /// </summary>
  2378. /// <param name="hashes">Array of subtitle file hashes (MD5 hashes of subtitle file contents) </param>
  2379. /// <returns>Status of the call operation. If the call success the response will be 'MethodResponseCheckSubHash'</returns>
  2380. public static IMethodResponse CheckSubHash(string[] hashes)
  2381. {
  2382. if (TOKEN == "")
  2383. {
  2384. OSHConsole.WriteLine("Can't do this call, 'token' value not set. Please use Log In method first.", DebugCode.Error);
  2385. return new MethodResponseError("Fail", "Can't do this call, 'token' value not set. Please use Log In method first.");
  2386. }
  2387. // Method call ..
  2388. var parms = new List<IXmlRpcValue>();
  2389. parms.Add(new XmlRpcValueBasic(TOKEN));
  2390. parms.Add(new XmlRpcValueArray(hashes));
  2391. var call = new XmlRpcMethodCall("CheckSubHash", parms);
  2392. OSHConsole.WriteLine("Sending CheckSubHash request to the server ...", DebugCode.Good);
  2393. // Send the request to the server
  2394. string response = Utilities.GetStreamString(Utilities.SendRequest(XmlRpcGenerator.Generate(call), XML_PRC_USERAGENT));
  2395. if (!response.Contains("ERROR:"))
  2396. {
  2397. // No error occur, get and decode the response.
  2398. XmlRpcMethodCall[] calls = XmlRpcGenerator.DecodeMethodResponse(response);
  2399. if (calls.Length > 0)
  2400. {
  2401. if (calls[0].Parameters.Count > 0)
  2402. {
  2403. var mainStruct = (XmlRpcValueStruct)calls[0].Parameters[0];
  2404. // Create the response, we'll need it later
  2405. var R = new MethodResponseCheckSubHash();
  2406. // To make sure response is not currepted by server, do it in loop
  2407. foreach (XmlRpcStructMember MEMBER in mainStruct.Members)
  2408. {
  2409. switch (MEMBER.Name)
  2410. {
  2411. case "status": R.Status = (string)MEMBER.Data.Data; OSHConsole.WriteLine(">" + MEMBER.Name + "= " + MEMBER.Data.Data.ToString()); break;
  2412. case "seconds": R.Seconds = (double)MEMBER.Data.Data; OSHConsole.WriteLine(">" + MEMBER.Name + "= " + MEMBER.Data.Data.ToString()); break;
  2413. case "data":
  2414. OSHConsole.WriteLine(">Data:");
  2415. var dataStruct = (XmlRpcValueStruct)MEMBER.Data;
  2416. foreach (XmlRpcStructMember dataMember in dataStruct.Members)
  2417. {
  2418. OSHConsole.WriteLine(" >" + dataMember.Name + "= " + dataMember.Data.Data.ToString());
  2419. var r = new CheckSubHashResult();
  2420. r.Hash = dataMember.Name;
  2421. r.SubID = dataMember.Data.Data.ToString();
  2422. R.Results.Add(r);
  2423. }
  2424. break;
  2425. }
  2426. }
  2427. // Return the response to user !!
  2428. return R;
  2429. }
  2430. }
  2431. }
  2432. else
  2433. {
  2434. OSHConsole.WriteLine(response, DebugCode.Error);
  2435. return new MethodResponseError("Fail", response);
  2436. }
  2437. return new MethodResponseError("Fail", "CheckSubHash call failed !");
  2438. }
  2439. /*Upload*/
  2440. /// <summary>
  2441. /// Try to upload subtitles, perform pre-upload checking (i.e. check if subtitles already exist on server)
  2442. /// </summary>
  2443. /// <param name="subs">The subtitle parameters collection to try to upload</param>
  2444. /// <returns>Status of the call operation. If the call success the response will be 'MethodResponseTryUploadSubtitles'</returns>
  2445. public static IMethodResponse TryUploadSubtitles(TryUploadSubtitlesParameters[] subs)
  2446. {
  2447. if (TOKEN == "")
  2448. {
  2449. OSHConsole.WriteLine("Can't do this call, 'token' value not set. Please use Log In method first.", DebugCode.Error);
  2450. return new MethodResponseError("Fail", "Can't do this call, 'token' value not set. Please use Log In method first.");
  2451. }
  2452. // Method call ..
  2453. var parms = new List<IXmlRpcValue>();
  2454. parms.Add(new XmlRpcValueBasic(TOKEN, XmlRpcBasicValueType.String));
  2455. var s = new XmlRpcValueStruct(new List<XmlRpcStructMember>());
  2456. int i = 1;
  2457. foreach (var cd in subs)
  2458. {
  2459. var member = new XmlRpcStructMember("cd" + i, null);
  2460. var memberStruct = new XmlRpcValueStruct(new List<XmlRpcStructMember>());
  2461. memberStruct.Members.Add(new XmlRpcStructMember("subhash", new XmlRpcValueBasic(cd.subhash)));
  2462. memberStruct.Members.Add(new XmlRpcStructMember("subfilename", new XmlRpcValueBasic(cd.subfilename)));
  2463. memberStruct.Members.Add(new XmlRpcStructMember("moviehash", new XmlRpcValueBasic(cd.moviehash)));
  2464. memberStruct.Members.Add(new XmlRpcStructMember("moviebytesize", new XmlRpcValueBasic(cd.moviebytesize)));
  2465. memberStruct.Members.Add(new XmlRpcStructMember("moviefps", new XmlRpcValueBasic(cd.moviefps)));
  2466. memberStruct.Members.Add(new XmlRpcStructMember("movietimems", new XmlRpcValueBasic(cd.movietimems)));
  2467. memberStruct.Members.Add(new XmlRpcStructMember("movieframes", new XmlRpcValueBasic(cd.movieframes)));
  2468. memberStruct.Members.Add(new XmlRpcStructMember("moviefilename", new XmlRpcValueBasic(cd.moviefilename)));
  2469. member.Data = memberStruct;
  2470. s.Members.Add(member);
  2471. i++;
  2472. }
  2473. parms.Add(s);
  2474. var call = new XmlRpcMethodCall("TryUploadSubtitles", parms);
  2475. OSHConsole.WriteLine("Sending TryUploadSubtitles request to the server ...", DebugCode.Good);
  2476. // Send the request to the server
  2477. string response = Utilities.GetStreamString(Utilities.SendRequest(XmlRpcGenerator.Generate(call), XML_PRC_USERAGENT));
  2478. if (!response.Contains("ERROR:"))
  2479. {
  2480. // No error occur, get and decode the response.
  2481. XmlRpcMethodCall[] calls = XmlRpcGenerator.DecodeMethodResponse(response);
  2482. if (calls.Length > 0)
  2483. {
  2484. if (calls[0].Parameters.Count > 0)
  2485. {
  2486. var mainStruct = (XmlRpcValueStruct)calls[0].Parameters[0];
  2487. // Create the response, we'll need it later
  2488. var R = new MethodResponseTryUploadSubtitles();
  2489. // To make sure response is not currepted by server, do it in loop
  2490. foreach (XmlRpcStructMember MEMBER in mainStruct.Members)
  2491. {
  2492. switch (MEMBER.Name)
  2493. {
  2494. case "status": R.Status = (string)MEMBER.Data.Data; OSHConsole.WriteLine(">" + MEMBER.Name + "= " + MEMBER.Data.Data.ToString()); break;
  2495. case "seconds": R.Seconds = (double)MEMBER.Data.Data; OSHConsole.WriteLine(">" + MEMBER.Name + "= " + MEMBER.Data.Data.ToString()); break;
  2496. case "alreadyindb": R.AlreadyInDB = (int)MEMBER.Data.Data; OSHConsole.WriteLine(">" + MEMBER.Name + "= " + MEMBER.Data.Data.ToString()); break;
  2497. case "data":
  2498. if (MEMBER.Data is XmlRpcValueArray)
  2499. {
  2500. OSHConsole.WriteLine("Results: ");
  2501. var rarray = (XmlRpcValueArray)MEMBER.Data;
  2502. foreach (IXmlRpcValue subStruct in rarray.Values)
  2503. {
  2504. if (subStruct == null) continue;
  2505. if (!(subStruct is XmlRpcValueStruct)) continue;
  2506. var result = new SubtitleSearchResult();
  2507. foreach (XmlRpcStructMember submember in ((XmlRpcValueStruct)subStruct).Members)
  2508. {
  2509. // To avoid errors of arranged info or missing ones, let's do it with switch..
  2510. switch (submember.Name)
  2511. {
  2512. case "IDMovie": result.IDMovie = submember.Data.Data.ToString(); break;
  2513. case "IDMovieImdb": result.IDMovieImdb = submember.Data.Data.ToString(); break;
  2514. case "IDSubMovieFile": result.IDSubMovieFile = submember.Data.Data.ToString(); break;
  2515. case "IDSubtitle": result.IDSubtitle = submember.Data.Data.ToString(); break;
  2516. case "IDSubtitleFile": result.IDSubtitleFile = submember.Data.Data.ToString(); break;
  2517. case "ISO639": result.ISO639 = submember.Data.Data.ToString(); break;
  2518. case "LanguageName": result.LanguageName = submember.Data.Data.ToString(); break;
  2519. case "MovieByteSize": result.MovieByteSize = submember.Data.Data.ToString(); break;
  2520. case "MovieHash": result.MovieHash = submember.Data.Data.ToString(); break;
  2521. case "MovieImdbRating": result.MovieImdbRating = submember.Data.Data.ToString(); break;
  2522. case "MovieName": result.MovieName = submember.Data.Data.ToString(); break;
  2523. case "MovieNameEng": result.MovieNameEng = submember.Data.Data.ToString(); break;
  2524. case "MovieReleaseName": result.MovieReleaseName = submember.Data.Data.ToString(); break;
  2525. case "MovieTimeMS": result.MovieTimeMS = submember.Data.Data.ToString(); break;
  2526. case "MovieYear": result.MovieYear = submember.Data.Data.ToString(); break;
  2527. case "SubActualCD": result.SubActualCD = submember.Data.Data.ToString(); break;
  2528. case "SubAddDate": result.SubAddDate = submember.Data.Data.ToString(); break;
  2529. case "SubAuthorComment": result.SubAuthorComment = submember.Data.Data.ToString(); break;
  2530. case "SubBad": result.SubBad = submember.Data.Data.ToString(); break;
  2531. case "SubDownloadLink": result.SubDownloadLink = submember.Data.Data.ToString(); break;
  2532. case "SubDownloadsCnt": result.SubDownloadsCnt = submember.Data.Data.ToString(); break;
  2533. case "SubFileName": result.SubFileName = submember.Data.Data.ToString(); break;
  2534. case "SubFormat": result.SubFormat = submember.Data.Data.ToString(); break;
  2535. case "SubHash": result.SubHash = submember.Data.Data.ToString(); break;
  2536. case "SubLanguageID": result.SubLanguageID = submember.Data.Data.ToString(); break;
  2537. case "SubRating": result.SubRating = submember.Data.Data.ToString(); break;
  2538. case "SubSize": result.SubSize = submember.Data.Data.ToString(); break;
  2539. case "SubSumCD": result.SubSumCD = submember.Data.Data.ToString(); break;
  2540. case "UserID": result.UserID = submember.Data.Data.ToString(); break;
  2541. case "UserNickName": result.UserNickName = submember.Data.Data.ToString(); break;
  2542. case "ZipDownloadLink": result.ZipDownloadLink = submember.Data.Data.ToString(); break;
  2543. }
  2544. }
  2545. R.Results.Add(result);
  2546. OSHConsole.WriteLine(">" + result.ToString());
  2547. }
  2548. }
  2549. else// Unknown data ?
  2550. {
  2551. OSHConsole.WriteLine("Data= " + MEMBER.Data.Data.ToString(), DebugCode.Warning);
  2552. }
  2553. break;
  2554. }
  2555. }
  2556. // Return the response to user !!
  2557. return R;
  2558. }
  2559. }
  2560. }
  2561. else
  2562. {
  2563. OSHConsole.WriteLine(response, DebugCode.Error);
  2564. return new MethodResponseError("Fail", response);
  2565. }
  2566. return new MethodResponseError("Fail", "TryUploadSubtitles call failed !");
  2567. }
  2568. /// <summary>
  2569. /// Upload given subtitles to OSDb server
  2570. /// </summary>
  2571. /// <param name="info">The pamaters of upload method</param>
  2572. /// <returns>Status of the call operation. If the call success the response will be 'MethodResponseUploadSubtitles'</returns>
  2573. public static IMethodResponse UploadSubtitles(UploadSubtitleInfoParameters info)
  2574. {
  2575. if (TOKEN == "")
  2576. {
  2577. OSHConsole.WriteLine("Can't do this call, 'token' value not set. Please use Log In method first.", DebugCode.Error);
  2578. return new MethodResponseError("Fail", "Can't do this call, 'token' value not set. Please use Log In method first.");
  2579. }
  2580. // Method call ..
  2581. var parms = new List<IXmlRpcValue>();
  2582. parms.Add(new XmlRpcValueBasic(TOKEN));
  2583. // Main struct
  2584. var s = new XmlRpcValueStruct(new List<XmlRpcStructMember>());
  2585. // Base info member as struct
  2586. var member = new XmlRpcStructMember("baseinfo", null);
  2587. var memberStruct = new XmlRpcValueStruct(new List<XmlRpcStructMember>());
  2588. memberStruct.Members.Add(new XmlRpcStructMember("idmovieimdb", new XmlRpcValueBasic(info.idmovieimdb)));
  2589. memberStruct.Members.Add(new XmlRpcStructMember("sublanguageid", new XmlRpcValueBasic(info.sublanguageid)));
  2590. memberStruct.Members.Add(new XmlRpcStructMember("moviereleasename", new XmlRpcValueBasic(info.moviereleasename)));
  2591. memberStruct.Members.Add(new XmlRpcStructMember("movieaka", new XmlRpcValueBasic(info.movieaka)));
  2592. memberStruct.Members.Add(new XmlRpcStructMember("subauthorcomment", new XmlRpcValueBasic(info.subauthorcomment)));
  2593. // memberStruct.Members.Add(new XmlRpcStructMember("hearingimpaired", new XmlRpcValueBasic(info.hearingimpaired)));
  2594. // memberStruct.Members.Add(new XmlRpcStructMember("highdefinition", new XmlRpcValueBasic(info.highdefinition)));
  2595. // memberStruct.Members.Add(new XmlRpcStructMember("automatictranslation", new XmlRpcValueBasic(info.automatictranslation)));
  2596. member.Data = memberStruct;
  2597. s.Members.Add(member);
  2598. // CDS members
  2599. int i = 1;
  2600. foreach (UploadSubtitleParameters cd in info.CDS)
  2601. {
  2602. var member2 = new XmlRpcStructMember("cd" + i, null);
  2603. var memberStruct2 = new XmlRpcValueStruct(new List<XmlRpcStructMember>());
  2604. memberStruct2.Members.Add(new XmlRpcStructMember("subhash", new XmlRpcValueBasic(cd.subhash)));
  2605. memberStruct2.Members.Add(new XmlRpcStructMember("subfilename", new XmlRpcValueBasic(cd.subfilename)));
  2606. memberStruct2.Members.Add(new XmlRpcStructMember("moviehash", new XmlRpcValueBasic(cd.moviehash)));
  2607. memberStruct2.Members.Add(new XmlRpcStructMember("moviebytesize", new XmlRpcValueBasic(cd.moviebytesize)));
  2608. memberStruct2.Members.Add(new XmlRpcStructMember("moviefps", new XmlRpcValueBasic(cd.moviefps)));
  2609. memberStruct2.Members.Add(new XmlRpcStructMember("movietimems", new XmlRpcValueBasic(cd.movietimems)));
  2610. memberStruct2.Members.Add(new XmlRpcStructMember("movieframes", new XmlRpcValueBasic(cd.movieframes)));
  2611. memberStruct2.Members.Add(new XmlRpcStructMember("moviefilename", new XmlRpcValueBasic(cd.moviefilename)));
  2612. memberStruct2.Members.Add(new XmlRpcStructMember("subcontent", new XmlRpcValueBasic(cd.subcontent)));
  2613. member2.Data = memberStruct2;
  2614. s.Members.Add(member2);
  2615. i++;
  2616. }
  2617. // add main struct to parameters
  2618. parms.Add(s);
  2619. // add user agent
  2620. //parms.Add(new XmlRpcValueBasic(XML_PRC_USERAGENT));
  2621. var call = new XmlRpcMethodCall("UploadSubtitles", parms);
  2622. OSHConsole.WriteLine("Sending UploadSubtitles request to the server ...", DebugCode.Good);
  2623. // Send the request to the server
  2624. string response = Utilities.GetStreamString(Utilities.SendRequest(XmlRpcGenerator.Generate(call), XML_PRC_USERAGENT));
  2625. if (!response.Contains("ERROR:"))
  2626. {
  2627. // No error occur, get and decode the response.
  2628. XmlRpcMethodCall[] calls = XmlRpcGenerator.DecodeMethodResponse(response);
  2629. if (calls.Length > 0)
  2630. {
  2631. if (calls[0].Parameters.Count > 0)
  2632. {
  2633. var mainStruct = (XmlRpcValueStruct)calls[0].Parameters[0];
  2634. // Create the response, we'll need it later
  2635. var R = new MethodResponseUploadSubtitles();
  2636. // To make sure response is not currepted by server, do it in loop
  2637. foreach (XmlRpcStructMember MEMBER in mainStruct.Members)
  2638. {
  2639. switch (MEMBER.Name)
  2640. {
  2641. case "status": R.Status = (string)MEMBER.Data.Data; OSHConsole.WriteLine(">" + MEMBER.Name + "= " + MEMBER.Data.Data.ToString()); break;
  2642. case "seconds": R.Seconds = (double)MEMBER.Data.Data; OSHConsole.WriteLine(">" + MEMBER.Name + "= " + MEMBER.Data.Data.ToString()); break;
  2643. case "data": R.Data = (string)MEMBER.Data.Data; OSHConsole.WriteLine(">" + MEMBER.Name + "= " + MEMBER.Data.Data.ToString()); break;
  2644. case "subtitles": R.SubTitles = (bool)MEMBER.Data.Data; OSHConsole.WriteLine(">" + MEMBER.Name + "= " + MEMBER.Data.Data.ToString()); break;
  2645. }
  2646. }
  2647. // Return the response to user !!
  2648. return R;
  2649. }
  2650. }
  2651. }
  2652. else
  2653. {
  2654. OSHConsole.WriteLine(response, DebugCode.Error);
  2655. return new MethodResponseError("Fail", response);
  2656. }
  2657. return new MethodResponseError("Fail", "UploadSubtitles call failed !");
  2658. }
  2659. }
  2660. }