OpenSubtitles.cs 168 KB

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