OpenSubtitles.cs 147 KB

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