OpenSubtitles.cs 168 KB

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