ApiClient.js 71 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681
  1. if (!window.MediaBrowser) {
  2. window.MediaBrowser = {};
  3. }
  4. MediaBrowser.ApiClient = function ($, navigator, JSON, WebSocket, setTimeout) {
  5. /**
  6. * Creates a new api client instance
  7. * @param {String} serverProtocol
  8. * @param {String} serverHostName
  9. * @param {String} serverPortNumber
  10. * @param {String} clientName
  11. */
  12. return function (serverProtocol, serverHostName, serverPortNumber, clientName) {
  13. if (!serverProtocol) {
  14. throw new Error("Must supply a serverProtocol, e.g. http:");
  15. }
  16. if (!serverHostName) {
  17. throw new Error("Must supply serverHostName, e.g. 192.168.1.1 or myServerName");
  18. }
  19. if (!serverPortNumber) {
  20. throw new Error("Must supply a serverPortNumber");
  21. }
  22. var self = this;
  23. var deviceName = "Web Browser";
  24. var deviceId = MediaBrowser.SHA1(navigator.userAgent + (navigator.cpuClass || ""));
  25. var currentUserId;
  26. var webSocket;
  27. /**
  28. * Gets the server host name.
  29. */
  30. self.serverHostName = function () {
  31. return serverHostName;
  32. };
  33. /**
  34. * Gets the server port number.
  35. */
  36. self.serverPortNumber = function () {
  37. return serverPortNumber;
  38. };
  39. /**
  40. * Gets or sets the current user id.
  41. */
  42. self.currentUserId = function (val) {
  43. if (val !== undefined) {
  44. currentUserId = val;
  45. } else {
  46. return currentUserId;
  47. }
  48. };
  49. deviceName = (function () {
  50. var name = "";
  51. if ($.browser.chrome) {
  52. name = "Chrome";
  53. }
  54. else if ($.browser.safari) {
  55. name = "Safari";
  56. }
  57. else if ($.browser.webkit) {
  58. name = "WebKit";
  59. }
  60. else if ($.browser.msie) {
  61. name = "Internet Explorer";
  62. }
  63. else if ($.browser.firefox || $.browser.mozilla) {
  64. name = "Firefox";
  65. }
  66. else if ($.browser.opera) {
  67. name = "Opera";
  68. }
  69. else {
  70. name = "Web Browser";
  71. }
  72. if ($.browser.ipad) {
  73. name += " Ipad";
  74. }
  75. else if ($.browser.iphone) {
  76. name += " Iphone";
  77. }
  78. else if ($.browser.android) {
  79. name += " Android";
  80. }
  81. return name;
  82. }());
  83. self.encodeName = function (name) {
  84. var val = $.param({ name: name });
  85. return val.substring(val.indexOf('=') + 1).replace("'", '%27');
  86. };
  87. /**
  88. * Wraps around jQuery ajax methods to add additional info to the request.
  89. */
  90. self.ajax = function (request) {
  91. if (!request) {
  92. throw new Error("Request cannot be null");
  93. }
  94. if (clientName) {
  95. var auth = 'MediaBrowser Client="' + clientName + '", Device="' + deviceName + '", DeviceId="' + deviceId + '"';
  96. if (currentUserId) {
  97. auth += ', UserId="' + currentUserId + '"';
  98. }
  99. request.headers = {
  100. Authorization: auth
  101. };
  102. }
  103. return $.ajax(request);
  104. };
  105. /**
  106. * Creates an api url based on a handler name and query string parameters
  107. * @param {String} name
  108. * @param {Object} params
  109. */
  110. self.getUrl = function (name, params) {
  111. if (!name) {
  112. throw new Error("Url name cannot be empty");
  113. }
  114. var url = serverProtocol + "//" + serverHostName + ":" + serverPortNumber + "/mediabrowser/" + name;
  115. if (params) {
  116. url += "?" + $.param(params);
  117. }
  118. return url;
  119. };
  120. self.openWebSocket = function (port) {
  121. var url = "ws://" + serverHostName + ":" + port + "/mediabrowser";
  122. webSocket = new WebSocket(url);
  123. webSocket.onmessage = function (msg) {
  124. msg = JSON.parse(msg.data);
  125. $(self).trigger("websocketmessage", [msg]);
  126. };
  127. webSocket.onopen = function () {
  128. setTimeout(function () {
  129. $(self).trigger("websocketopen");
  130. }, 500);
  131. };
  132. webSocket.onerror = function () {
  133. setTimeout(function () {
  134. $(self).trigger("websocketerror");
  135. }, 0);
  136. };
  137. webSocket.onclose = function () {
  138. setTimeout(function () {
  139. $(self).trigger("websocketclose");
  140. }, 0);
  141. };
  142. };
  143. self.sendWebSocketMessage = function (name, data) {
  144. var msg = { MessageType: name };
  145. if (data) {
  146. msg.Data = data;
  147. }
  148. msg = JSON.stringify(msg);
  149. webSocket.send(msg);
  150. };
  151. self.isWebSocketOpen = function () {
  152. return webSocket && webSocket.readyState === WebSocket.OPEN;
  153. };
  154. self.isWebSocketOpenOrConnecting = function () {
  155. return webSocket && (webSocket.readyState === WebSocket.OPEN || webSocket.readyState === WebSocket.CONNECTING);
  156. };
  157. /**
  158. * Gets an item from the server
  159. * Omit itemId to get the root folder.
  160. */
  161. self.getItem = function (userId, itemId) {
  162. if (!userId) {
  163. throw new Error("null userId");
  164. }
  165. var url = self.getUrl("Users/" + userId + "/Items/" + itemId);
  166. return self.ajax({
  167. type: "GET",
  168. url: url,
  169. dataType: "json"
  170. });
  171. };
  172. /**
  173. * Gets the root folder from the server
  174. */
  175. self.getRootFolder = function (userId) {
  176. if (!userId) {
  177. throw new Error("null userId");
  178. }
  179. var url = self.getUrl("Users/" + userId + "/Items/Root");
  180. return self.ajax({
  181. type: "GET",
  182. url: url,
  183. dataType: "json"
  184. });
  185. };
  186. /**
  187. * Gets the current server status
  188. */
  189. self.getSystemInfo = function () {
  190. var url = self.getUrl("System/Info");
  191. return self.ajax({
  192. type: "GET",
  193. url: url,
  194. dataType: "json"
  195. });
  196. };
  197. /**
  198. * Gets all cultures known to the server
  199. */
  200. self.getCultures = function () {
  201. var url = self.getUrl("Localization/cultures");
  202. return self.ajax({
  203. type: "GET",
  204. url: url,
  205. dataType: "json"
  206. });
  207. };
  208. /**
  209. * Gets all countries known to the server
  210. */
  211. self.getCountries = function () {
  212. var url = self.getUrl("Localization/countries");
  213. return self.ajax({
  214. type: "GET",
  215. url: url,
  216. dataType: "json"
  217. });
  218. };
  219. /**
  220. * Gets plugin security info
  221. */
  222. self.getPluginSecurityInfo = function () {
  223. var url = self.getUrl("Plugins/SecurityInfo");
  224. return self.ajax({
  225. type: "GET",
  226. url: url,
  227. dataType: "json"
  228. });
  229. };
  230. /**
  231. * Gets the directory contents of a path on the server
  232. */
  233. self.getDirectoryContents = function (path, options) {
  234. if (!path) {
  235. throw new Error("null path");
  236. }
  237. options = options || {};
  238. options.path = path;
  239. var url = self.getUrl("Environment/DirectoryContents", options);
  240. return self.ajax({
  241. type: "GET",
  242. url: url,
  243. dataType: "json"
  244. });
  245. };
  246. /**
  247. * Gets a list of physical drives from the server
  248. */
  249. self.getDrives = function () {
  250. var url = self.getUrl("Environment/Drives");
  251. return self.ajax({
  252. type: "GET",
  253. url: url,
  254. dataType: "json"
  255. });
  256. };
  257. /**
  258. * Gets a list of network devices from the server
  259. */
  260. self.getNetworkDevices = function () {
  261. var url = self.getUrl("Environment/NetworkDevices");
  262. return self.ajax({
  263. type: "GET",
  264. url: url,
  265. dataType: "json"
  266. });
  267. };
  268. /**
  269. * Cancels a package installation
  270. */
  271. self.cancelPackageInstallation = function (installationId) {
  272. if (!installationId) {
  273. throw new Error("null installationId");
  274. }
  275. var url = self.getUrl("Packages/Installing/" + id);
  276. return self.ajax({
  277. type: "DELETE",
  278. url: url
  279. });
  280. };
  281. /**
  282. * Installs or updates a new plugin
  283. */
  284. self.installPlugin = function (name, updateClass, version) {
  285. if (!name) {
  286. throw new Error("null name");
  287. }
  288. if (!updateClass) {
  289. throw new Error("null updateClass");
  290. }
  291. var options = {
  292. updateClass: updateClass
  293. };
  294. if (version) {
  295. options.version = version;
  296. }
  297. var url = self.getUrl("Packages/Installed/" + name, options);
  298. return self.ajax({
  299. type: "POST",
  300. url: url
  301. });
  302. };
  303. /**
  304. * Instructs the server to perform a pending kernel reload or app restart.
  305. * If a restart is not currently required, nothing will happen.
  306. */
  307. self.performPendingRestart = function () {
  308. var url = self.getUrl("System/Restart");
  309. return self.ajax({
  310. type: "POST",
  311. url: url
  312. });
  313. };
  314. /**
  315. * Gets information about an installable package
  316. */
  317. self.getPackageInfo = function (name) {
  318. if (!name) {
  319. throw new Error("null name");
  320. }
  321. var url = self.getUrl("Packages/" + name);
  322. return self.ajax({
  323. type: "GET",
  324. url: url,
  325. dataType: "json"
  326. });
  327. };
  328. /**
  329. * Gets the latest available application update (if any)
  330. */
  331. self.getAvailableApplicationUpdate = function () {
  332. var url = self.getUrl("Packages/Updates", { PackageType: "System" });
  333. return self.ajax({
  334. type: "GET",
  335. url: url,
  336. dataType: "json"
  337. });
  338. };
  339. /**
  340. * Gets the latest available plugin updates (if any)
  341. */
  342. self.getAvailablePluginUpdates = function () {
  343. var url = self.getUrl("Packages/Updates", { PackageType: "UserInstalled" });
  344. return self.ajax({
  345. type: "GET",
  346. url: url,
  347. dataType: "json"
  348. });
  349. };
  350. /**
  351. * Gets the virtual folder for a view. Specify a userId to get a user view, or omit for the default view.
  352. */
  353. self.getVirtualFolders = function (userId) {
  354. var url = userId ? "Users/" + userId + "/VirtualFolders" : "Library/VirtualFolders";
  355. url = self.getUrl(url);
  356. return self.ajax({
  357. type: "GET",
  358. url: url,
  359. dataType: "json"
  360. });
  361. };
  362. /**
  363. * Gets all the paths of the locations in the physical root.
  364. */
  365. self.getPhysicalPaths = function () {
  366. var url = self.getUrl("Library/PhysicalPaths");
  367. return self.ajax({
  368. type: "GET",
  369. url: url,
  370. dataType: "json"
  371. });
  372. };
  373. /**
  374. * Gets the current server configuration
  375. */
  376. self.getServerConfiguration = function () {
  377. var url = self.getUrl("System/Configuration");
  378. return self.ajax({
  379. type: "GET",
  380. url: url,
  381. dataType: "json"
  382. });
  383. };
  384. /**
  385. * Gets the server's scheduled tasks
  386. */
  387. self.getScheduledTasks = function () {
  388. var url = self.getUrl("ScheduledTasks");
  389. return self.ajax({
  390. type: "GET",
  391. url: url,
  392. dataType: "json"
  393. });
  394. };
  395. /**
  396. * Starts a scheduled task
  397. */
  398. self.startScheduledTask = function (id) {
  399. if (!id) {
  400. throw new Error("null id");
  401. }
  402. var url = self.getUrl("ScheduledTasks/Running/" + id);
  403. return self.ajax({
  404. type: "POST",
  405. url: url
  406. });
  407. };
  408. /**
  409. * Gets a scheduled task
  410. */
  411. self.getScheduledTask = function (id) {
  412. if (!id) {
  413. throw new Error("null id");
  414. }
  415. var url = self.getUrl("ScheduledTasks/" + id);
  416. return self.ajax({
  417. type: "GET",
  418. url: url,
  419. dataType: "json"
  420. });
  421. };
  422. self.getNextUpEpisodes = function (options) {
  423. var url = self.getUrl("Shows/NextUp", options);
  424. return self.ajax({
  425. type: "GET",
  426. url: url,
  427. dataType: "json"
  428. });
  429. };
  430. /**
  431. * Stops a scheduled task
  432. */
  433. self.stopScheduledTask = function (id) {
  434. if (!id) {
  435. throw new Error("null id");
  436. }
  437. var url = self.getUrl("ScheduledTasks/Running/" + id);
  438. return self.ajax({
  439. type: "DELETE",
  440. url: url
  441. });
  442. };
  443. /**
  444. * Gets the configuration of a plugin
  445. * @param {String} Id
  446. */
  447. self.getPluginConfiguration = function (id) {
  448. if (!id) {
  449. throw new Error("null Id");
  450. }
  451. var url = self.getUrl("Plugins/" + id + "/Configuration");
  452. return self.ajax({
  453. type: "GET",
  454. url: url,
  455. dataType: "json"
  456. });
  457. };
  458. /**
  459. * Gets a list of plugins that are available to be installed
  460. */
  461. self.getAvailablePlugins = function (options) {
  462. options = $.extend({}, options || {});
  463. options.PackageType = "UserInstalled";
  464. var url = self.getUrl("Packages", options);
  465. return self.ajax({
  466. type: "GET",
  467. url: url,
  468. dataType: "json"
  469. });
  470. };
  471. /**
  472. * Uninstalls a plugin
  473. * @param {String} Id
  474. */
  475. self.uninstallPlugin = function (id) {
  476. if (!id) {
  477. throw new Error("null Id");
  478. }
  479. var url = self.getUrl("Plugins/" + id);
  480. return self.ajax({
  481. type: "DELETE",
  482. url: url
  483. });
  484. };
  485. /**
  486. * Removes a virtual folder from either the default view or a user view
  487. * @param {String} name
  488. */
  489. self.removeVirtualFolder = function (name, userId) {
  490. if (!name) {
  491. throw new Error("null name");
  492. }
  493. var url = userId ? "Users/" + userId + "/VirtualFolders" : "Library/VirtualFolders";
  494. url += "/" + name;
  495. url = self.getUrl(url);
  496. return self.ajax({
  497. type: "DELETE",
  498. url: url
  499. });
  500. };
  501. /**
  502. * Adds a virtual folder to either the default view or a user view
  503. * @param {String} name
  504. */
  505. self.addVirtualFolder = function (name, userId) {
  506. if (!name) {
  507. throw new Error("null name");
  508. }
  509. var url = userId ? "Users/" + userId + "/VirtualFolders" : "Library/VirtualFolders";
  510. url += "/" + name;
  511. url = self.getUrl(url);
  512. return self.ajax({
  513. type: "POST",
  514. url: url
  515. });
  516. };
  517. /**
  518. * Renames a virtual folder, within either the default view or a user view
  519. * @param {String} name
  520. */
  521. self.renameVirtualFolder = function (name, newName, userId) {
  522. if (!name) {
  523. throw new Error("null name");
  524. }
  525. var url = userId ? "Users/" + userId + "/VirtualFolders" : "Library/VirtualFolders";
  526. url += "/" + name + "/Name";
  527. url = self.getUrl(url, { newName: newName });
  528. return self.ajax({
  529. type: "POST",
  530. url: url
  531. });
  532. };
  533. /**
  534. * Adds an additional mediaPath to an existing virtual folder, within either the default view or a user view
  535. * @param {String} name
  536. */
  537. self.addMediaPath = function (virtualFolderName, mediaPath, userId) {
  538. if (!virtualFolderName) {
  539. throw new Error("null virtualFolderName");
  540. }
  541. if (!mediaPath) {
  542. throw new Error("null mediaPath");
  543. }
  544. var url = userId ? "Users/" + userId + "/VirtualFolders" : "Library/VirtualFolders";
  545. url += "/" + virtualFolderName + "/Paths";
  546. url = self.getUrl(url, { path: mediaPath });
  547. return self.ajax({
  548. type: "POST",
  549. url: url
  550. });
  551. };
  552. /**
  553. * Removes a media path from a virtual folder, within either the default view or a user view
  554. * @param {String} name
  555. */
  556. self.removeMediaPath = function (virtualFolderName, mediaPath, userId) {
  557. if (!virtualFolderName) {
  558. throw new Error("null virtualFolderName");
  559. }
  560. if (!mediaPath) {
  561. throw new Error("null mediaPath");
  562. }
  563. var url = userId ? "Users/" + userId + "/VirtualFolders" : "Library/VirtualFolders";
  564. url += "/" + virtualFolderName + "/Paths";
  565. url = self.getUrl(url, { path: mediaPath });
  566. return self.ajax({
  567. type: "DELETE",
  568. url: url
  569. });
  570. };
  571. /**
  572. * Deletes a user
  573. * @param {String} id
  574. */
  575. self.deleteUser = function (id) {
  576. if (!id) {
  577. throw new Error("null id");
  578. }
  579. var url = self.getUrl("Users/" + id);
  580. return self.ajax({
  581. type: "DELETE",
  582. url: url
  583. });
  584. };
  585. /**
  586. * Deletes a user image
  587. * @param {String} userId
  588. * @param {String} imageType The type of image to delete, based on the server-side ImageType enum.
  589. */
  590. self.deleteUserImage = function (userId, imageType, imageIndex) {
  591. if (!userId) {
  592. throw new Error("null userId");
  593. }
  594. if (!imageType) {
  595. throw new Error("null imageType");
  596. }
  597. var url = self.getUrl("Users/" + userId + "/Images/" + imageType);
  598. if (imageIndex != null) {
  599. url += "/" + imageIndex;
  600. }
  601. return self.ajax({
  602. type: "DELETE",
  603. url: url
  604. });
  605. };
  606. self.deleteItemImage = function (itemId, imageType, imageIndex) {
  607. if (!itemId) {
  608. throw new Error("null itemId");
  609. }
  610. if (!imageType) {
  611. throw new Error("null imageType");
  612. }
  613. var url = self.getUrl("Items/" + itemId + "/Images/" + imageType);
  614. if (imageIndex != null) {
  615. url += "/" + imageIndex;
  616. }
  617. return self.ajax({
  618. type: "DELETE",
  619. url: url
  620. });
  621. };
  622. self.updateItemImageIndex = function (itemId, imageType, imageIndex, newIndex) {
  623. if (!itemId) {
  624. throw new Error("null itemId");
  625. }
  626. if (!imageType) {
  627. throw new Error("null imageType");
  628. }
  629. var url = self.getUrl("Items/" + itemId + "/Images/" + imageType + "/" + imageIndex + "/Index", { newIndex: newIndex });
  630. return self.ajax({
  631. type: "POST",
  632. url: url
  633. });
  634. };
  635. self.getItemImageInfos = function (itemId) {
  636. if (!itemId) {
  637. throw new Error("null itemId");
  638. }
  639. var url = self.getUrl("Items/" + itemId + "/Images");
  640. return self.ajax({
  641. type: "GET",
  642. url: url,
  643. dataType: "json"
  644. });
  645. };
  646. /**
  647. * Uploads a user image
  648. * @param {String} userId
  649. * @param {String} imageType The type of image to delete, based on the server-side ImageType enum.
  650. * @param {Object} file The file from the input element
  651. */
  652. self.uploadUserImage = function (userId, imageType, file) {
  653. if (!userId) {
  654. throw new Error("null userId");
  655. }
  656. if (!imageType) {
  657. throw new Error("null imageType");
  658. }
  659. if (!file) {
  660. throw new Error("File must be an image.");
  661. }
  662. if (file.type != "image/png" && file.type != "image/jpeg" && file.type != "image/jpeg") {
  663. throw new Error("File must be an image.");
  664. }
  665. var deferred = $.Deferred();
  666. var reader = new FileReader();
  667. reader.onerror = function () {
  668. deferred.reject();
  669. };
  670. reader.onabort = function () {
  671. deferred.reject();
  672. };
  673. // Closure to capture the file information.
  674. reader.onload = function (e) {
  675. var data = window.btoa(e.target.result);
  676. var url = self.getUrl("Users/" + userId + "/Images/" + imageType);
  677. self.ajax({
  678. type: "POST",
  679. url: url,
  680. data: data,
  681. contentType: "image/" + file.name.substring(file.name.lastIndexOf('.') + 1)
  682. }).done(function (result) {
  683. deferred.resolveWith(null, [result]);
  684. }).fail(function () {
  685. deferred.reject();
  686. });
  687. };
  688. // Read in the image file as a data URL.
  689. reader.readAsBinaryString(file);
  690. return deferred.promise();
  691. };
  692. self.uploadItemImage = function (itemId, imageType, file) {
  693. if (!itemId) {
  694. throw new Error("null itemId");
  695. }
  696. if (!imageType) {
  697. throw new Error("null imageType");
  698. }
  699. if (!file) {
  700. throw new Error("File must be an image.");
  701. }
  702. if (file.type != "image/png" && file.type != "image/jpeg" && file.type != "image/jpeg") {
  703. throw new Error("File must be an image.");
  704. }
  705. var deferred = $.Deferred();
  706. var reader = new FileReader();
  707. reader.onerror = function () {
  708. deferred.reject();
  709. };
  710. reader.onabort = function () {
  711. deferred.reject();
  712. };
  713. // Closure to capture the file information.
  714. reader.onload = function (e) {
  715. var data = window.btoa(e.target.result);
  716. var url = self.getUrl("Items/" + itemId + "/Images/" + imageType);
  717. self.ajax({
  718. type: "POST",
  719. url: url,
  720. data: data,
  721. contentType: "image/" + file.name.substring(file.name.lastIndexOf('.') + 1)
  722. }).done(function (result) {
  723. deferred.resolveWith(null, [result]);
  724. }).fail(function () {
  725. deferred.reject();
  726. });
  727. };
  728. // Read in the image file as a data URL.
  729. reader.readAsBinaryString(file);
  730. return deferred.promise();
  731. };
  732. /**
  733. * Gets the list of installed plugins on the server
  734. */
  735. self.getInstalledPlugins = function () {
  736. var url = self.getUrl("Plugins");
  737. return self.ajax({
  738. type: "GET",
  739. url: url,
  740. dataType: "json"
  741. });
  742. };
  743. /**
  744. * Gets a user by id
  745. * @param {String} id
  746. */
  747. self.getUser = function (id) {
  748. if (!id) {
  749. throw new Error("Must supply a userId");
  750. }
  751. var url = self.getUrl("Users/" + id);
  752. return self.ajax({
  753. type: "GET",
  754. url: url,
  755. dataType: "json"
  756. });
  757. };
  758. /**
  759. * Gets a studio
  760. */
  761. self.getStudio = function (name, userId) {
  762. if (!name) {
  763. throw new Error("null name");
  764. }
  765. var options = {};
  766. if (userId) {
  767. options.userId = userId;
  768. }
  769. var url = self.getUrl("Studios/" + self.encodeName(name), options);
  770. return self.ajax({
  771. type: "GET",
  772. url: url,
  773. dataType: "json"
  774. });
  775. };
  776. /**
  777. * Gets a genre
  778. */
  779. self.getGenre = function (name, userId) {
  780. if (!name) {
  781. throw new Error("null name");
  782. }
  783. var options = {};
  784. if (userId) {
  785. options.userId = userId;
  786. }
  787. var url = self.getUrl("Genres/" + self.encodeName(name), options);
  788. return self.ajax({
  789. type: "GET",
  790. url: url,
  791. dataType: "json"
  792. });
  793. };
  794. /**
  795. * Gets an artist
  796. */
  797. self.getArtist = function (name, userId) {
  798. if (!name) {
  799. throw new Error("null name");
  800. }
  801. var options = {};
  802. if (userId) {
  803. options.userId = userId;
  804. }
  805. var url = self.getUrl("Artists/" + self.encodeName(name), options);
  806. return self.ajax({
  807. type: "GET",
  808. url: url,
  809. dataType: "json"
  810. });
  811. };
  812. /**
  813. * Gets a year
  814. */
  815. self.getYear = function (yea, userId) {
  816. if (!name) {
  817. throw new Error("null name");
  818. }
  819. var options = {};
  820. if (userId) {
  821. options.userId = userId;
  822. }
  823. var url = self.getUrl("Years/" + self.encodeName(name), options);
  824. return self.ajax({
  825. type: "GET",
  826. url: url,
  827. dataType: "json"
  828. });
  829. };
  830. /**
  831. * Gets a Person
  832. */
  833. self.getPerson = function (name, userId) {
  834. if (!name) {
  835. throw new Error("null name");
  836. }
  837. var options = {};
  838. if (userId) {
  839. options.userId = userId;
  840. }
  841. var url = self.getUrl("Persons/" + self.encodeName(name), options);
  842. return self.ajax({
  843. type: "GET",
  844. url: url,
  845. dataType: "json"
  846. });
  847. };
  848. /**
  849. * Gets weather info
  850. * @param {String} location - us zip code / city, state, country / city, country
  851. * Omit location to get weather info using stored server configuration value
  852. */
  853. self.getWeatherInfo = function (location) {
  854. var url = self.getUrl("weather", {
  855. location: location
  856. });
  857. return self.ajax({
  858. type: "GET",
  859. url: url,
  860. dataType: "json"
  861. });
  862. };
  863. /**
  864. * Gets all users from the server
  865. */
  866. self.getUsers = function () {
  867. var url = self.getUrl("users");
  868. return self.ajax({
  869. type: "GET",
  870. url: url,
  871. dataType: "json"
  872. });
  873. };
  874. /**
  875. * Gets all available parental ratings from the server
  876. */
  877. self.getParentalRatings = function () {
  878. var url = self.getUrl("Localization/ParentalRatings");
  879. return self.ajax({
  880. type: "GET",
  881. url: url,
  882. dataType: "json"
  883. });
  884. };
  885. /**
  886. * Gets a list of all available conrete BaseItem types from the server
  887. */
  888. self.getItemTypes = function (options) {
  889. var url = self.getUrl("Library/ItemTypes", options);
  890. return self.ajax({
  891. type: "GET",
  892. url: url,
  893. dataType: "json"
  894. });
  895. };
  896. /**
  897. * Constructs a url for a user image
  898. * @param {String} userId
  899. * @param {Object} options
  900. * Options supports the following properties:
  901. * width - download the image at a fixed width
  902. * height - download the image at a fixed height
  903. * maxWidth - download the image at a maxWidth
  904. * maxHeight - download the image at a maxHeight
  905. * quality - A scale of 0-100. This should almost always be omitted as the default will suffice.
  906. * For best results do not specify both width and height together, as aspect ratio might be altered.
  907. */
  908. self.getUserImageUrl = function (userId, options) {
  909. if (!userId) {
  910. throw new Error("null userId");
  911. }
  912. options = options || {
  913. };
  914. var url = "Users/" + userId + "/Images/" + options.type;
  915. if (options.index != null) {
  916. url += "/" + options.index;
  917. }
  918. // Don't put these on the query string
  919. delete options.type;
  920. delete options.index;
  921. return self.getUrl(url, options);
  922. };
  923. /**
  924. * Constructs a url for a person image
  925. * @param {String} name
  926. * @param {Object} options
  927. * Options supports the following properties:
  928. * width - download the image at a fixed width
  929. * height - download the image at a fixed height
  930. * maxWidth - download the image at a maxWidth
  931. * maxHeight - download the image at a maxHeight
  932. * quality - A scale of 0-100. This should almost always be omitted as the default will suffice.
  933. * For best results do not specify both width and height together, as aspect ratio might be altered.
  934. */
  935. self.getPersonImageUrl = function (name, options) {
  936. if (!name) {
  937. throw new Error("null name");
  938. }
  939. options = options || {
  940. };
  941. var url = "Persons/" + self.encodeName(name) + "/Images/" + options.type;
  942. if (options.index != null) {
  943. url += "/" + options.index;
  944. }
  945. // Don't put these on the query string
  946. delete options.type;
  947. delete options.index;
  948. return self.getUrl(url, options);
  949. };
  950. /**
  951. * Constructs a url for a year image
  952. * @param {String} year
  953. * @param {Object} options
  954. * Options supports the following properties:
  955. * width - download the image at a fixed width
  956. * height - download the image at a fixed height
  957. * maxWidth - download the image at a maxWidth
  958. * maxHeight - download the image at a maxHeight
  959. * quality - A scale of 0-100. This should almost always be omitted as the default will suffice.
  960. * For best results do not specify both width and height together, as aspect ratio might be altered.
  961. */
  962. self.getYearImageUrl = function (year, options) {
  963. if (!year) {
  964. throw new Error("null year");
  965. }
  966. options = options || {
  967. };
  968. var url = "Years/" + year + "/Images/" + options.type;
  969. if (options.index != null) {
  970. url += "/" + options.index;
  971. }
  972. // Don't put these on the query string
  973. delete options.type;
  974. delete options.index;
  975. return self.getUrl(url, options);
  976. };
  977. /**
  978. * Constructs a url for a genre image
  979. * @param {String} name
  980. * @param {Object} options
  981. * Options supports the following properties:
  982. * width - download the image at a fixed width
  983. * height - download the image at a fixed height
  984. * maxWidth - download the image at a maxWidth
  985. * maxHeight - download the image at a maxHeight
  986. * quality - A scale of 0-100. This should almost always be omitted as the default will suffice.
  987. * For best results do not specify both width and height together, as aspect ratio might be altered.
  988. */
  989. self.getGenreImageUrl = function (name, options) {
  990. if (!name) {
  991. throw new Error("null name");
  992. }
  993. options = options || {
  994. };
  995. var url = "Genres/" + self.encodeName(name) + "/Images/" + options.type;
  996. if (options.index != null) {
  997. url += "/" + options.index;
  998. }
  999. // Don't put these on the query string
  1000. delete options.type;
  1001. delete options.index;
  1002. return self.getUrl(url, options);
  1003. };
  1004. /**
  1005. * Constructs a url for a artist image
  1006. * @param {String} name
  1007. * @param {Object} options
  1008. * Options supports the following properties:
  1009. * width - download the image at a fixed width
  1010. * height - download the image at a fixed height
  1011. * maxWidth - download the image at a maxWidth
  1012. * maxHeight - download the image at a maxHeight
  1013. * quality - A scale of 0-100. This should almost always be omitted as the default will suffice.
  1014. * For best results do not specify both width and height together, as aspect ratio might be altered.
  1015. */
  1016. self.getArtistImageUrl = function (name, options) {
  1017. if (!name) {
  1018. throw new Error("null name");
  1019. }
  1020. options = options || {
  1021. };
  1022. var url = "Artists/" + self.encodeName(name) + "/Images/" + options.type;
  1023. if (options.index != null) {
  1024. url += "/" + options.index;
  1025. }
  1026. // Don't put these on the query string
  1027. delete options.type;
  1028. delete options.index;
  1029. return self.getUrl(url, options);
  1030. };
  1031. /**
  1032. * Constructs a url for a studio image
  1033. * @param {String} name
  1034. * @param {Object} options
  1035. * Options supports the following properties:
  1036. * width - download the image at a fixed width
  1037. * height - download the image at a fixed height
  1038. * maxWidth - download the image at a maxWidth
  1039. * maxHeight - download the image at a maxHeight
  1040. * quality - A scale of 0-100. This should almost always be omitted as the default will suffice.
  1041. * For best results do not specify both width and height together, as aspect ratio might be altered.
  1042. */
  1043. self.getStudioImageUrl = function (name, options) {
  1044. if (!name) {
  1045. throw new Error("null name");
  1046. }
  1047. options = options || {
  1048. };
  1049. var url = "Studios/" + self.encodeName(name) + "/Images/" + options.type;
  1050. if (options.index != null) {
  1051. url += "/" + options.index;
  1052. }
  1053. // Don't put these on the query string
  1054. delete options.type;
  1055. delete options.index;
  1056. return self.getUrl(url, options);
  1057. };
  1058. /**
  1059. * Constructs a url for an item image
  1060. * @param {String} itemId
  1061. * @param {Object} options
  1062. * Options supports the following properties:
  1063. * type - Primary, logo, backdrop, etc. See the server-side enum ImageType
  1064. * index - When downloading a backdrop, use this to specify which one (omitting is equivalent to zero)
  1065. * width - download the image at a fixed width
  1066. * height - download the image at a fixed height
  1067. * maxWidth - download the image at a maxWidth
  1068. * maxHeight - download the image at a maxHeight
  1069. * quality - A scale of 0-100. This should almost always be omitted as the default will suffice.
  1070. * For best results do not specify both width and height together, as aspect ratio might be altered.
  1071. */
  1072. self.getImageUrl = function (itemId, options) {
  1073. if (!itemId) {
  1074. throw new Error("itemId cannot be empty");
  1075. }
  1076. options = options || {
  1077. };
  1078. var url = "Items/" + itemId + "/Images/" + options.type;
  1079. if (options.index != null) {
  1080. url += "/" + options.index;
  1081. }
  1082. // Don't put these on the query string
  1083. delete options.type;
  1084. delete options.index;
  1085. return self.getUrl(url, options);
  1086. };
  1087. /**
  1088. * Constructs a url for an item logo image
  1089. * If the item doesn't have a logo, it will inherit a logo from a parent
  1090. * @param {Object} item A BaseItem
  1091. * @param {Object} options
  1092. * Options supports the following properties:
  1093. * width - download the image at a fixed width
  1094. * height - download the image at a fixed height
  1095. * maxWidth - download the image at a maxWidth
  1096. * maxHeight - download the image at a maxHeight
  1097. * quality - A scale of 0-100. This should almost always be omitted as the default will suffice.
  1098. * For best results do not specify both width and height together, as aspect ratio might be altered.
  1099. */
  1100. self.getLogoImageUrl = function (item, options) {
  1101. if (!item) {
  1102. throw new Error("null item");
  1103. }
  1104. options = options || {
  1105. };
  1106. options.imageType = "logo";
  1107. var logoItemId = item.HasLogo ? item.Id : item.ParentLogoItemId;
  1108. return logoItemId ? self.getImageUrl(logoItemId, options) : null;
  1109. };
  1110. /**
  1111. * Constructs an array of backdrop image url's for an item
  1112. * If the item doesn't have any backdrops, it will inherit them from a parent
  1113. * @param {Object} item A BaseItem
  1114. * @param {Object} options
  1115. * Options supports the following properties:
  1116. * width - download the image at a fixed width
  1117. * height - download the image at a fixed height
  1118. * maxWidth - download the image at a maxWidth
  1119. * maxHeight - download the image at a maxHeight
  1120. * quality - A scale of 0-100. This should almost always be omitted as the default will suffice.
  1121. * For best results do not specify both width and height together, as aspect ratio might be altered.
  1122. */
  1123. self.getBackdropImageUrl = function (item, options) {
  1124. if (!item) {
  1125. throw new Error("null item");
  1126. }
  1127. options = options || {
  1128. };
  1129. options.imageType = "backdrop";
  1130. var backdropItemId;
  1131. var backdropCount;
  1132. if (!item.BackdropCount) {
  1133. backdropItemId = item.ParentBackdropItemId;
  1134. backdropCount = item.ParentBackdropCount || 0;
  1135. } else {
  1136. backdropItemId = item.Id;
  1137. backdropCount = item.BackdropCount;
  1138. }
  1139. if (!backdropItemId) {
  1140. return [];
  1141. }
  1142. var files = [];
  1143. for (var i = 0; i < backdropCount; i++) {
  1144. options.imageIndex = i;
  1145. files[i] = self.getImageUrl(backdropItemId, options);
  1146. }
  1147. return files;
  1148. };
  1149. /**
  1150. * Authenticates a user
  1151. * @param {String} userId
  1152. * @param {String} password
  1153. */
  1154. self.authenticateUser = function (userId, password) {
  1155. if (!userId) {
  1156. throw new Error("null userId");
  1157. }
  1158. var url = self.getUrl("Users/" + userId + "/authenticate");
  1159. var postData = {
  1160. password: MediaBrowser.SHA1(password || "")
  1161. };
  1162. return self.ajax({
  1163. type: "POST",
  1164. url: url,
  1165. data: JSON.stringify(postData),
  1166. contentType: "application/json"
  1167. });
  1168. };
  1169. /**
  1170. * Updates a user's password
  1171. * @param {String} userId
  1172. * @param {String} currentPassword
  1173. * @param {String} newPassword
  1174. */
  1175. self.updateUserPassword = function (userId, currentPassword, newPassword) {
  1176. if (!userId) {
  1177. throw new Error("null userId");
  1178. }
  1179. var url = self.getUrl("Users/" + userId + "/Password");
  1180. var postData = {
  1181. };
  1182. postData.currentPassword = MediaBrowser.SHA1(currentPassword);
  1183. if (newPassword) {
  1184. postData.newPassword = newPassword;
  1185. }
  1186. return self.ajax({
  1187. type: "POST",
  1188. url: url,
  1189. data: postData
  1190. });
  1191. };
  1192. /**
  1193. * Resets a user's password
  1194. * @param {String} userId
  1195. */
  1196. self.resetUserPassword = function (userId) {
  1197. if (!userId) {
  1198. throw new Error("null userId");
  1199. }
  1200. var url = self.getUrl("Users/" + userId + "/Password");
  1201. var postData = {
  1202. };
  1203. postData.resetPassword = true;
  1204. return self.ajax({
  1205. type: "POST",
  1206. url: url,
  1207. data: postData
  1208. });
  1209. };
  1210. /**
  1211. * Updates the server's configuration
  1212. * @param {Object} configuration
  1213. */
  1214. self.updateServerConfiguration = function (configuration) {
  1215. if (!configuration) {
  1216. throw new Error("null configuration");
  1217. }
  1218. var url = self.getUrl("System/Configuration");
  1219. return self.ajax({
  1220. type: "POST",
  1221. url: url,
  1222. data: JSON.stringify(configuration),
  1223. contentType: "application/json"
  1224. });
  1225. };
  1226. /**
  1227. * Updates plugin security info
  1228. */
  1229. self.updatePluginSecurityInfo = function (info) {
  1230. var url = self.getUrl("Plugins/SecurityInfo");
  1231. return self.ajax({
  1232. type: "POST",
  1233. url: url,
  1234. data: JSON.stringify(info),
  1235. contentType: "application/json"
  1236. });
  1237. };
  1238. /**
  1239. * Creates a user
  1240. * @param {Object} user
  1241. */
  1242. self.createUser = function (user) {
  1243. if (!user) {
  1244. throw new Error("null user");
  1245. }
  1246. var url = self.getUrl("Users");
  1247. return self.ajax({
  1248. type: "POST",
  1249. url: url,
  1250. data: JSON.stringify(user),
  1251. dataType: "json",
  1252. contentType: "application/json"
  1253. });
  1254. };
  1255. /**
  1256. * Updates a user
  1257. * @param {Object} user
  1258. */
  1259. self.updateUser = function (user) {
  1260. if (!user) {
  1261. throw new Error("null user");
  1262. }
  1263. var url = self.getUrl("Users/" + user.Id);
  1264. return self.ajax({
  1265. type: "POST",
  1266. url: url,
  1267. data: JSON.stringify(user),
  1268. contentType: "application/json"
  1269. });
  1270. };
  1271. /**
  1272. * Updates the Triggers for a ScheduledTask
  1273. * @param {String} id
  1274. * @param {Object} triggers
  1275. */
  1276. self.updateScheduledTaskTriggers = function (id, triggers) {
  1277. if (!id) {
  1278. throw new Error("null id");
  1279. }
  1280. if (!triggers) {
  1281. throw new Error("null triggers");
  1282. }
  1283. var url = self.getUrl("ScheduledTasks/" + id + "/Triggers");
  1284. return self.ajax({
  1285. type: "POST",
  1286. url: url,
  1287. data: JSON.stringify(triggers),
  1288. contentType: "application/json"
  1289. });
  1290. };
  1291. /**
  1292. * Updates a plugin's configuration
  1293. * @param {String} Id
  1294. * @param {Object} configuration
  1295. */
  1296. self.updatePluginConfiguration = function (id, configuration) {
  1297. if (!id) {
  1298. throw new Error("null Id");
  1299. }
  1300. if (!configuration) {
  1301. throw new Error("null configuration");
  1302. }
  1303. var url = self.getUrl("Plugins/" + id + "/Configuration");
  1304. return self.ajax({
  1305. type: "POST",
  1306. url: url,
  1307. data: JSON.stringify(configuration),
  1308. contentType: "application/json"
  1309. });
  1310. };
  1311. /**
  1312. * Gets items based on a query, typically for children of a folder
  1313. * @param {String} userId
  1314. * @param {Object} options
  1315. * Options accepts the following properties:
  1316. * itemId - Localize the search to a specific folder (root if omitted)
  1317. * startIndex - Use for paging
  1318. * limit - Use to limit results to a certain number of items
  1319. * filter - Specify one or more ItemFilters, comma delimeted (see server-side enum)
  1320. * sortBy - Specify an ItemSortBy (comma-delimeted list see server-side enum)
  1321. * sortOrder - ascending/descending
  1322. * fields - additional fields to include aside from basic info. This is a comma delimited list. See server-side enum ItemFields.
  1323. * index - the name of the dynamic, localized index function
  1324. * dynamicSortBy - the name of the dynamic localized sort function
  1325. * recursive - Whether or not the query should be recursive
  1326. * searchTerm - search term to use as a filter
  1327. */
  1328. self.getItems = function (userId, options) {
  1329. if (!userId) {
  1330. throw new Error("null userId");
  1331. }
  1332. var url = self.getUrl("Users/" + userId + "/Items", options);
  1333. return self.ajax({
  1334. type: "GET",
  1335. url: url,
  1336. dataType: "json"
  1337. });
  1338. };
  1339. /**
  1340. Gets artists from an item
  1341. */
  1342. self.getArtists = function (userId, options) {
  1343. if (!userId) {
  1344. throw new Error("null userId");
  1345. }
  1346. options = options || {};
  1347. options.userId = userId;
  1348. var url = self.getUrl("Artists", options);
  1349. return self.ajax({
  1350. type: "GET",
  1351. url: url,
  1352. dataType: "json"
  1353. });
  1354. };
  1355. /**
  1356. Gets genres from an item
  1357. */
  1358. self.getGenres = function (userId, options) {
  1359. if (!userId) {
  1360. throw new Error("null userId");
  1361. }
  1362. options = options || {};
  1363. options.userId = userId;
  1364. var url = self.getUrl("Genres", options);
  1365. return self.ajax({
  1366. type: "GET",
  1367. url: url,
  1368. dataType: "json"
  1369. });
  1370. };
  1371. /**
  1372. Gets people from an item
  1373. */
  1374. self.getPeople = function (userId, options) {
  1375. if (!userId) {
  1376. throw new Error("null userId");
  1377. }
  1378. options = options || {};
  1379. options.userId = userId;
  1380. var url = self.getUrl("Persons", options);
  1381. return self.ajax({
  1382. type: "GET",
  1383. url: url,
  1384. dataType: "json"
  1385. });
  1386. };
  1387. /**
  1388. Gets studios from an item
  1389. */
  1390. self.getStudios = function (userId, options) {
  1391. if (!userId) {
  1392. throw new Error("null userId");
  1393. }
  1394. options = options || {};
  1395. options.userId = userId;
  1396. var url = self.getUrl("Studios", options);
  1397. return self.ajax({
  1398. type: "GET",
  1399. url: url,
  1400. dataType: "json"
  1401. });
  1402. };
  1403. /**
  1404. * Gets local trailers for an item
  1405. */
  1406. self.getLocalTrailers = function (userId, itemId) {
  1407. if (!userId) {
  1408. throw new Error("null userId");
  1409. }
  1410. if (!itemId) {
  1411. throw new Error("null itemId");
  1412. }
  1413. var url = self.getUrl("Users/" + userId + "/Items/" + itemId + "/LocalTrailers");
  1414. return self.ajax({
  1415. type: "GET",
  1416. url: url,
  1417. dataType: "json"
  1418. });
  1419. };
  1420. /**
  1421. * Gets theme songs for an item
  1422. */
  1423. self.getThemeSongs = function (userId, itemId) {
  1424. if (!userId) {
  1425. throw new Error("null userId");
  1426. }
  1427. if (!itemId) {
  1428. throw new Error("null itemId");
  1429. }
  1430. var url = self.getUrl("Users/" + userId + "/Items/" + itemId + "/ThemeSongs");
  1431. return self.ajax({
  1432. type: "GET",
  1433. url: url,
  1434. dataType: "json"
  1435. });
  1436. };
  1437. self.getThemeVideos = function (userId, itemId) {
  1438. if (!userId) {
  1439. throw new Error("null userId");
  1440. }
  1441. if (!itemId) {
  1442. throw new Error("null itemId");
  1443. }
  1444. var url = self.getUrl("Users/" + userId + "/Items/" + itemId + "/ThemeVideos");
  1445. return self.ajax({
  1446. type: "GET",
  1447. url: url,
  1448. dataType: "json"
  1449. });
  1450. };
  1451. self.getSearchHints = function (options) {
  1452. var url = self.getUrl("Search/Hints", options);
  1453. return self.ajax({
  1454. type: "GET",
  1455. url: url,
  1456. dataType: "json"
  1457. });
  1458. };
  1459. /**
  1460. * Gets special features for an item
  1461. */
  1462. self.getSpecialFeatures = function (userId, itemId) {
  1463. if (!userId) {
  1464. throw new Error("null userId");
  1465. }
  1466. if (!itemId) {
  1467. throw new Error("null itemId");
  1468. }
  1469. var url = self.getUrl("Users/" + userId + "/Items/" + itemId + "/SpecialFeatures");
  1470. return self.ajax({
  1471. type: "GET",
  1472. url: url,
  1473. dataType: "json"
  1474. });
  1475. };
  1476. /**
  1477. * Marks an item as played or unplayed
  1478. * This should not be used to update playstate following playback.
  1479. * There are separate playstate check-in methods for that. This should be used for a
  1480. * separate option to reset playstate.
  1481. * @param {String} userId
  1482. * @param {String} itemId
  1483. * @param {Boolean} wasPlayed
  1484. */
  1485. self.updatePlayedStatus = function (userId, itemId, wasPlayed) {
  1486. if (!userId) {
  1487. throw new Error("null userId");
  1488. }
  1489. if (!itemId) {
  1490. throw new Error("null itemId");
  1491. }
  1492. var url = self.getUrl("Users/" + userId + "/PlayedItems/" + itemId);
  1493. var method = wasPlayed ? "POST" : "DELETE";
  1494. return self.ajax({
  1495. type: method,
  1496. url: url
  1497. });
  1498. };
  1499. /**
  1500. * Updates a user's favorite status for an item.
  1501. * @param {String} userId
  1502. * @param {String} itemId
  1503. * @param {Boolean} isFavorite
  1504. */
  1505. self.updateFavoriteStatus = function (userId, itemId, isFavorite) {
  1506. if (!userId) {
  1507. throw new Error("null userId");
  1508. }
  1509. if (!itemId) {
  1510. throw new Error("null itemId");
  1511. }
  1512. var url = self.getUrl("Users/" + userId + "/FavoriteItems/" + itemId);
  1513. var method = isFavorite ? "POST" : "DELETE";
  1514. return self.ajax({
  1515. type: method,
  1516. url: url
  1517. });
  1518. };
  1519. /**
  1520. * Updates a user's personal rating for an item
  1521. * @param {String} userId
  1522. * @param {String} itemId
  1523. * @param {Boolean} likes
  1524. */
  1525. self.updateUserItemRating = function (userId, itemId, likes) {
  1526. if (!userId) {
  1527. throw new Error("null userId");
  1528. }
  1529. if (!itemId) {
  1530. throw new Error("null itemId");
  1531. }
  1532. var url = self.getUrl("Users/" + userId + "/Items/" + itemId + "/Rating", {
  1533. likes: likes
  1534. });
  1535. return self.ajax({
  1536. type: "POST",
  1537. url: url
  1538. });
  1539. };
  1540. /**
  1541. * Updates a user's favorite status for an item by name.
  1542. * @param {String} userId
  1543. * @param {String} name
  1544. * @param {Boolean} isFavorite
  1545. */
  1546. self.updateFavoriteArtistStatus = function (userId, name, isFavorite) {
  1547. if (!userId) {
  1548. throw new Error("null userId");
  1549. }
  1550. if (!name) {
  1551. throw new Error("null name");
  1552. }
  1553. var url = self.getUrl("Users/" + userId + "/Favorites/Artists/" + self.encodeName(name));
  1554. var method = isFavorite ? "POST" : "DELETE";
  1555. return self.ajax({
  1556. type: method,
  1557. url: url
  1558. });
  1559. };
  1560. self.updateFavoritePersonStatus = function (userId, name, isFavorite) {
  1561. if (!userId) {
  1562. throw new Error("null userId");
  1563. }
  1564. if (!name) {
  1565. throw new Error("null name");
  1566. }
  1567. var url = self.getUrl("Users/" + userId + "/Favorites/Persons/" + self.encodeName(name));
  1568. var method = isFavorite ? "POST" : "DELETE";
  1569. return self.ajax({
  1570. type: method,
  1571. url: url
  1572. });
  1573. };
  1574. self.updateFavoriteStudioStatus = function (userId, name, isFavorite) {
  1575. if (!userId) {
  1576. throw new Error("null userId");
  1577. }
  1578. if (!name) {
  1579. throw new Error("null name");
  1580. }
  1581. var url = self.getUrl("Users/" + userId + "/Favorites/Studios/" + self.encodeName(name));
  1582. var method = isFavorite ? "POST" : "DELETE";
  1583. return self.ajax({
  1584. type: method,
  1585. url: url
  1586. });
  1587. };
  1588. self.updateFavoriteGenreStatus = function (userId, name, isFavorite) {
  1589. if (!userId) {
  1590. throw new Error("null userId");
  1591. }
  1592. if (!name) {
  1593. throw new Error("null name");
  1594. }
  1595. var url = self.getUrl("Users/" + userId + "/Favorites/Genres/" + self.encodeName(name));
  1596. var method = isFavorite ? "POST" : "DELETE";
  1597. return self.ajax({
  1598. type: method,
  1599. url: url
  1600. });
  1601. };
  1602. /**
  1603. * Updates a user's rating for an item by name.
  1604. * @param {String} userId
  1605. * @param {String} name
  1606. * @param {Boolean} likes
  1607. */
  1608. self.updateArtistRating = function (userId, name, likes) {
  1609. if (!userId) {
  1610. throw new Error("null userId");
  1611. }
  1612. if (!name) {
  1613. throw new Error("null name");
  1614. }
  1615. var url = self.getUrl("Users/" + userId + "/Ratings/Artists/" + self.encodeName(name), {
  1616. likes: likes
  1617. });
  1618. return self.ajax({
  1619. type: "POST",
  1620. url: url
  1621. });
  1622. };
  1623. self.updatePersonRating = function (userId, name, likes) {
  1624. if (!userId) {
  1625. throw new Error("null userId");
  1626. }
  1627. if (!name) {
  1628. throw new Error("null name");
  1629. }
  1630. var url = self.getUrl("Users/" + userId + "/Ratings/Persons/" + self.encodeName(name), {
  1631. likes: likes
  1632. });
  1633. return self.ajax({
  1634. type: "POST",
  1635. url: url
  1636. });
  1637. };
  1638. self.updateStudioRating = function (userId, name, likes) {
  1639. if (!userId) {
  1640. throw new Error("null userId");
  1641. }
  1642. if (!name) {
  1643. throw new Error("null name");
  1644. }
  1645. var url = self.getUrl("Users/" + userId + "/Ratings/Studios/" + self.encodeName(name), {
  1646. likes: likes
  1647. });
  1648. return self.ajax({
  1649. type: "POST",
  1650. url: url
  1651. });
  1652. };
  1653. self.updateGenreRating = function (userId, name, likes) {
  1654. if (!userId) {
  1655. throw new Error("null userId");
  1656. }
  1657. if (!name) {
  1658. throw new Error("null name");
  1659. }
  1660. var url = self.getUrl("Users/" + userId + "/Ratings/Genres/" + self.encodeName(name), {
  1661. likes: likes
  1662. });
  1663. return self.ajax({
  1664. type: "POST",
  1665. url: url
  1666. });
  1667. };
  1668. /**
  1669. * Clears a user's rating for an item by name.
  1670. * @param {String} userId
  1671. * @param {String} name
  1672. */
  1673. self.clearArtistRating = function (userId, name) {
  1674. if (!userId) {
  1675. throw new Error("null userId");
  1676. }
  1677. if (!name) {
  1678. throw new Error("null name");
  1679. }
  1680. var url = self.getUrl("Users/" + userId + "/Ratings/Artists/" + self.encodeName(name));
  1681. return self.ajax({
  1682. type: "DELETE",
  1683. url: url
  1684. });
  1685. };
  1686. self.clearPersonRating = function (userId, name) {
  1687. if (!userId) {
  1688. throw new Error("null userId");
  1689. }
  1690. if (!name) {
  1691. throw new Error("null name");
  1692. }
  1693. var url = self.getUrl("Users/" + userId + "/Ratings/Persons/" + self.encodeName(name));
  1694. return self.ajax({
  1695. type: "DELETE",
  1696. url: url
  1697. });
  1698. };
  1699. self.clearStudioRating = function (userId, name) {
  1700. if (!userId) {
  1701. throw new Error("null userId");
  1702. }
  1703. if (!name) {
  1704. throw new Error("null name");
  1705. }
  1706. var url = self.getUrl("Users/" + userId + "/Ratings/Studios/" + self.encodeName(name));
  1707. return self.ajax({
  1708. type: "DELETE",
  1709. url: url
  1710. });
  1711. };
  1712. self.clearGenreRating = function (userId, name) {
  1713. if (!userId) {
  1714. throw new Error("null userId");
  1715. }
  1716. if (!name) {
  1717. throw new Error("null name");
  1718. }
  1719. var url = self.getUrl("Users/" + userId + "/Ratings/Genres/" + self.encodeName(name));
  1720. return self.ajax({
  1721. type: "DELETE",
  1722. url: url
  1723. });
  1724. };
  1725. /**
  1726. Gets a variety of item counts that a person appears in
  1727. */
  1728. self.getPersonItemCounts = function (userId, name) {
  1729. if (!userId) {
  1730. throw new Error("null userId");
  1731. }
  1732. if (!name) {
  1733. throw new Error("null name");
  1734. }
  1735. var url = self.getUrl("Persons/" + self.encodeName(name) + "/Counts", {
  1736. userId: userId
  1737. });
  1738. return self.ajax({
  1739. type: "GET",
  1740. url: url,
  1741. dataType: "json"
  1742. });
  1743. };
  1744. /**
  1745. Gets a variety of item counts that a genre appears in
  1746. */
  1747. self.getGenreItemCounts = function (userId, name) {
  1748. if (!userId) {
  1749. throw new Error("null userId");
  1750. }
  1751. if (!name) {
  1752. throw new Error("null name");
  1753. }
  1754. var url = self.getUrl("Genres/" + self.encodeName(name) + "/Counts", {
  1755. userId: userId
  1756. });
  1757. return self.ajax({
  1758. type: "GET",
  1759. url: url,
  1760. dataType: "json"
  1761. });
  1762. };
  1763. /**
  1764. Gets a variety of item counts that an artist appears in
  1765. */
  1766. self.getArtistItemCounts = function (userId, name) {
  1767. if (!userId) {
  1768. throw new Error("null userId");
  1769. }
  1770. if (!name) {
  1771. throw new Error("null name");
  1772. }
  1773. var url = self.getUrl("Artists/" + self.encodeName(name) + "/Counts", {
  1774. userId: userId
  1775. });
  1776. return self.ajax({
  1777. type: "GET",
  1778. url: url,
  1779. dataType: "json"
  1780. });
  1781. };
  1782. /**
  1783. Gets a variety of item counts that a studio appears in
  1784. */
  1785. self.getStudioItemCounts = function (userId, name) {
  1786. if (!userId) {
  1787. throw new Error("null userId");
  1788. }
  1789. if (!name) {
  1790. throw new Error("null name");
  1791. }
  1792. var url = self.getUrl("Studios/" + self.encodeName(name) + "/Counts", {
  1793. userId: userId
  1794. });
  1795. return self.ajax({
  1796. type: "GET",
  1797. url: url,
  1798. dataType: "json"
  1799. });
  1800. };
  1801. /**
  1802. * Clears a user's personal rating for an item
  1803. * @param {String} userId
  1804. * @param {String} itemId
  1805. */
  1806. self.clearUserItemRating = function (userId, itemId) {
  1807. if (!userId) {
  1808. throw new Error("null userId");
  1809. }
  1810. if (!itemId) {
  1811. throw new Error("null itemId");
  1812. }
  1813. var url = self.getUrl("Users/" + userId + "/Items/" + itemId + "/Rating");
  1814. return self.ajax({
  1815. type: "DELETE",
  1816. url: url
  1817. });
  1818. };
  1819. /**
  1820. * Reports the user has started playing something
  1821. * @param {String} userId
  1822. * @param {String} itemId
  1823. */
  1824. self.reportPlaybackStart = function (userId, itemId) {
  1825. if (!userId) {
  1826. throw new Error("null userId");
  1827. }
  1828. if (!itemId) {
  1829. throw new Error("null itemId");
  1830. }
  1831. var url = self.getUrl("Users/" + userId + "/PlayingItems/" + itemId);
  1832. return self.ajax({
  1833. type: "POST",
  1834. url: url
  1835. });
  1836. };
  1837. /**
  1838. * Reports progress viewing an item
  1839. * @param {String} userId
  1840. * @param {String} itemId
  1841. */
  1842. self.reportPlaybackProgress = function (userId, itemId, positionTicks) {
  1843. if (!userId) {
  1844. throw new Error("null userId");
  1845. }
  1846. if (!itemId) {
  1847. throw new Error("null itemId");
  1848. }
  1849. var params = {
  1850. };
  1851. if (positionTicks) {
  1852. params.positionTicks = positionTicks;
  1853. }
  1854. var url = self.getUrl("Users/" + userId + "/PlayingItems/" + itemId + "/Progress", params);
  1855. return self.ajax({
  1856. type: "POST",
  1857. url: url
  1858. });
  1859. };
  1860. /**
  1861. * Reports a user has stopped playing an item
  1862. * @param {String} userId
  1863. * @param {String} itemId
  1864. */
  1865. self.reportPlaybackStopped = function (userId, itemId, positionTicks) {
  1866. if (!userId) {
  1867. throw new Error("null userId");
  1868. }
  1869. if (!itemId) {
  1870. throw new Error("null itemId");
  1871. }
  1872. var params = {
  1873. };
  1874. if (positionTicks) {
  1875. params.positionTicks = positionTicks;
  1876. }
  1877. var url = self.getUrl("Users/" + userId + "/PlayingItems/" + itemId, params);
  1878. return self.ajax({
  1879. type: "DELETE",
  1880. url: url
  1881. });
  1882. };
  1883. }
  1884. }(jQuery, navigator, JSON, window.WebSocket, setTimeout);
  1885. /**
  1886. * Provides a friendly way to create an api client instance using information from the browser's current url
  1887. */
  1888. MediaBrowser.ApiClient.create = function (clientName) {
  1889. var loc = window.location;
  1890. return new MediaBrowser.ApiClient(loc.protocol, loc.hostname, loc.port, clientName);
  1891. };
  1892. /**
  1893. *
  1894. * Secure Hash Algorithm (SHA1)
  1895. * http://www.webtoolkit.info/
  1896. *
  1897. **/
  1898. MediaBrowser.SHA1 = function (msg) {
  1899. function rotate_left(n, s) {
  1900. var t4 = (n << s) | (n >>> (32 - s));
  1901. return t4;
  1902. }
  1903. function lsb_hex(val) {
  1904. var str = "";
  1905. var i;
  1906. var vh;
  1907. var vl;
  1908. for (i = 0; i <= 6; i += 2) {
  1909. vh = (val >>> (i * 4 + 4)) & 0x0f;
  1910. vl = (val >>> (i * 4)) & 0x0f;
  1911. str += vh.toString(16) + vl.toString(16);
  1912. }
  1913. return str;
  1914. }
  1915. function cvt_hex(val) {
  1916. var str = "";
  1917. var i;
  1918. var v;
  1919. for (i = 7; i >= 0; i--) {
  1920. v = (val >>> (i * 4)) & 0x0f;
  1921. str += v.toString(16);
  1922. }
  1923. return str;
  1924. }
  1925. function Utf8Encode(string) {
  1926. string = string.replace(/\r\n/g, "\n");
  1927. var utftext = "";
  1928. for (var n = 0; n < string.length; n++) {
  1929. var c = string.charCodeAt(n);
  1930. if (c < 128) {
  1931. utftext += String.fromCharCode(c);
  1932. }
  1933. else if ((c > 127) && (c < 2048)) {
  1934. utftext += String.fromCharCode((c >> 6) | 192);
  1935. utftext += String.fromCharCode((c & 63) | 128);
  1936. }
  1937. else {
  1938. utftext += String.fromCharCode((c >> 12) | 224);
  1939. utftext += String.fromCharCode(((c >> 6) & 63) | 128);
  1940. utftext += String.fromCharCode((c & 63) | 128);
  1941. }
  1942. }
  1943. return utftext;
  1944. }
  1945. var blockstart;
  1946. var i, j;
  1947. var W = new Array(80);
  1948. var H0 = 0x67452301;
  1949. var H1 = 0xEFCDAB89;
  1950. var H2 = 0x98BADCFE;
  1951. var H3 = 0x10325476;
  1952. var H4 = 0xC3D2E1F0;
  1953. var A, B, C, D, E;
  1954. var temp;
  1955. msg = Utf8Encode(msg);
  1956. var msg_len = msg.length;
  1957. var word_array = new Array();
  1958. for (i = 0; i < msg_len - 3; i += 4) {
  1959. j = msg.charCodeAt(i) << 24 | msg.charCodeAt(i + 1) << 16 |
  1960. msg.charCodeAt(i + 2) << 8 | msg.charCodeAt(i + 3);
  1961. word_array.push(j);
  1962. }
  1963. switch (msg_len % 4) {
  1964. case 0:
  1965. i = 0x080000000;
  1966. break;
  1967. case 1:
  1968. i = msg.charCodeAt(msg_len - 1) << 24 | 0x0800000;
  1969. break;
  1970. case 2:
  1971. i = msg.charCodeAt(msg_len - 2) << 24 | msg.charCodeAt(msg_len - 1) << 16 | 0x08000;
  1972. break;
  1973. case 3:
  1974. i = msg.charCodeAt(msg_len - 3) << 24 | msg.charCodeAt(msg_len - 2) << 16 | msg.charCodeAt(msg_len - 1) << 8 | 0x80;
  1975. break;
  1976. }
  1977. word_array.push(i);
  1978. while ((word_array.length % 16) != 14) word_array.push(0);
  1979. word_array.push(msg_len >>> 29);
  1980. word_array.push((msg_len << 3) & 0x0ffffffff);
  1981. for (blockstart = 0; blockstart < word_array.length; blockstart += 16) {
  1982. for (i = 0; i < 16; i++) W[i] = word_array[blockstart + i];
  1983. for (i = 16; i <= 79; i++) W[i] = rotate_left(W[i - 3] ^ W[i - 8] ^ W[i - 14] ^ W[i - 16], 1);
  1984. A = H0;
  1985. B = H1;
  1986. C = H2;
  1987. D = H3;
  1988. E = H4;
  1989. for (i = 0; i <= 19; i++) {
  1990. temp = (rotate_left(A, 5) + ((B & C) | (~B & D)) + E + W[i] + 0x5A827999) & 0x0ffffffff;
  1991. E = D;
  1992. D = C;
  1993. C = rotate_left(B, 30);
  1994. B = A;
  1995. A = temp;
  1996. }
  1997. for (i = 20; i <= 39; i++) {
  1998. temp = (rotate_left(A, 5) + (B ^ C ^ D) + E + W[i] + 0x6ED9EBA1) & 0x0ffffffff;
  1999. E = D;
  2000. D = C;
  2001. C = rotate_left(B, 30);
  2002. B = A;
  2003. A = temp;
  2004. }
  2005. for (i = 40; i <= 59; i++) {
  2006. temp = (rotate_left(A, 5) + ((B & C) | (B & D) | (C & D)) + E + W[i] + 0x8F1BBCDC) & 0x0ffffffff;
  2007. E = D;
  2008. D = C;
  2009. C = rotate_left(B, 30);
  2010. B = A;
  2011. A = temp;
  2012. }
  2013. for (i = 60; i <= 79; i++) {
  2014. temp = (rotate_left(A, 5) + (B ^ C ^ D) + E + W[i] + 0xCA62C1D6) & 0x0ffffffff;
  2015. E = D;
  2016. D = C;
  2017. C = rotate_left(B, 30);
  2018. B = A;
  2019. A = temp;
  2020. }
  2021. H0 = (H0 + A) & 0x0ffffffff;
  2022. H1 = (H1 + B) & 0x0ffffffff;
  2023. H2 = (H2 + C) & 0x0ffffffff;
  2024. H3 = (H3 + D) & 0x0ffffffff;
  2025. H4 = (H4 + E) & 0x0ffffffff;
  2026. }
  2027. var temp = cvt_hex(H0) + cvt_hex(H1) + cvt_hex(H2) + cvt_hex(H3) + cvt_hex(H4);
  2028. return temp.toLowerCase();
  2029. };
  2030. (function (jQuery, window, undefined) {
  2031. "use strict";
  2032. var matched, browser;
  2033. jQuery.uaMatch = function (ua) {
  2034. ua = ua.toLowerCase();
  2035. var match = /(chrome)[ \/]([\w.]+)/.exec(ua) ||
  2036. /(webkit)[ \/]([\w.]+)/.exec(ua) ||
  2037. /(opera)(?:.*version|)[ \/]([\w.]+)/.exec(ua) ||
  2038. /(msie) ([\w.]+)/.exec(ua) ||
  2039. ua.indexOf("compatible") < 0 && /(mozilla)(?:.*? rv:([\w.]+)|)/.exec(ua) ||
  2040. [];
  2041. var platform_match = /(ipad)/.exec(ua) ||
  2042. /(iphone)/.exec(ua) ||
  2043. /(android)/.exec(ua) ||
  2044. [];
  2045. return {
  2046. browser: match[1] || "",
  2047. version: match[2] || "0",
  2048. platform: platform_match[0] || ""
  2049. };
  2050. };
  2051. matched = jQuery.uaMatch(window.navigator.userAgent);
  2052. browser = {};
  2053. if (matched.browser) {
  2054. browser[matched.browser] = true;
  2055. browser.version = matched.version;
  2056. }
  2057. if (matched.platform) {
  2058. browser[matched.platform] = true
  2059. }
  2060. // Chrome is Webkit, but Webkit is also Safari.
  2061. if (browser.chrome) {
  2062. browser.webkit = true;
  2063. } else if (browser.webkit) {
  2064. browser.safari = true;
  2065. }
  2066. jQuery.browser = browser;
  2067. })(jQuery, window);