daily pastebin goal
46%
SHARE
TWEET

settings.js

Kafke Nov 4th, 2015 1,960 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var Q = require('q'),
  2.     os = require('os'),
  3.     path = require('path'),
  4.     _ = require('underscore'),
  5.     data_path = require('nw.gui').App.dataPath;
  6.  
  7. /** Default settings **/
  8. var Settings = {};
  9.  
  10. // User interface
  11. Settings.language = '';
  12. Settings.translateSynopsis = true;
  13. Settings.coversShowRating = true;
  14. Settings.watchedCovers = 'fade';
  15. Settings.showAdvancedSettings = false;
  16.  
  17. Settings.postersMinWidth = 134;
  18. Settings.postersMaxWidth = 294;
  19. Settings.postersMinFontSize = 0.8;
  20. Settings.postersMaxFontSize = 1.3;
  21. Settings.postersSizeRatio = (196 / 134);
  22. Settings.postersWidth = Settings.postersMinWidth;
  23. Settings.postersJump = [134, 154, 174, 194, 214, 234, 254, 274, 294];
  24.  
  25. //Playback
  26. Settings.alwaysFullscreen = false;
  27. Settings.playNextEpisodeAuto = true;
  28. Settings.chosenPlayer = 'local';
  29.  
  30. // Advanced UI
  31. Settings.alwaysOnTop = false;
  32. Settings.theme = 'Official_-_Dark_theme';
  33. Settings.ratingStars = true; //trigger on click in details
  34. Settings.startScreen = 'Movies';
  35. Settings.lastTab = '';
  36.  
  37. // Quality
  38. Settings.shows_default_quality = '720p';
  39. Settings.movies_default_quality = '1080p';
  40. Settings.moviesShowQuality = false;
  41. Settings.movies_quality = 'all';
  42.  
  43. // Subtitles
  44. Settings.subtitle_language = 'none';
  45. Settings.subtitle_size = '28px';
  46. Settings.subtitle_color = '#ffffff';
  47. Settings.subtitle_decoration = 'Outline';
  48. Settings.subtitle_font = 'Arial';
  49.  
  50. // More options
  51. Settings.httpApiPort = 8008;
  52. Settings.httpApiUsername = 'popcorn';
  53. Settings.httpApiPassword = 'popcorn';
  54.  
  55. // Trakt.tv
  56. Settings.traktToken = '';
  57. Settings.traktTokenRefresh = '';
  58. Settings.traktTokenTTL = '';
  59. Settings.traktTvVersion = '0.0.2';
  60. Settings.traktLastSync = '';
  61. Settings.traktLastActivities = '';
  62. Settings.traktSyncOnStart = true;
  63. Settings.traktPlayback = true;
  64.  
  65. // TVShow Time
  66. Settings.tvstAccessToken = '';
  67.  
  68. // Advanced options
  69. Settings.connectionLimit = 100;
  70. Settings.dhtLimit = 500;
  71. Settings.streamPort = 0; // 0 = Random
  72. Settings.tmpLocation = path.join(os.tmpDir(), 'Popcorn-Time');
  73. Settings.databaseLocation = path.join(data_path, 'data');
  74. Settings.deleteTmpOnClose = true;
  75. Settings.automaticUpdating = true;
  76. Settings.events = true;
  77. Settings.minimizeToTray = false;
  78. Settings.bigPicture = false;
  79.  
  80. // Features
  81. Settings.activateTorrentCollection = true;
  82. Settings.activateWatchlist = true;
  83. Settings.activateVpn = true;
  84. Settings.activateRandomize = true;
  85. Settings.onlineSearchEngine = 'KAT';
  86.  
  87. // Ratio
  88. Settings.totalDownloaded = 0;
  89. Settings.totalUploaded = 0;
  90.  
  91. // VPN
  92. Settings.vpn = false;
  93. Settings.vpnUsername = '';
  94. Settings.vpnPassword = '';
  95.  
  96. Settings.tvAPI = [{
  97.     url: 'https://eztvapi.re/',
  98.     strictSSL: true
  99. }, {
  100.     url: 'https://api.popcorntime.io/',
  101.     strictSSL: true
  102. }, {
  103.     url: 'http://tv.ytspt.re/',
  104.     strictSSL: false
  105. }];
  106.  
  107. Settings.ytsAPI = [{
  108.     uri: 'http://api.torrentsapi.com/',
  109.     strictSSL: false
  110. }/*, {
  111.     uri: 'https://cloudflare.com/',
  112.     headers: {
  113.         'Host': 'xor.image.yt',
  114.         'User-Agent': 'Mozilla/5.0 (Linux) AppleWebkit/534.30 (KHTML, like Gecko) PT/3.8.0'
  115.     },
  116.     strictSSL: true
  117. }, {
  118.     uri: 'http://cloudflare.com/',
  119.     headers: {
  120.         'Host': 'xor.image.yt',
  121.         'User-Agent': 'Mozilla/5.0 (Linux) AppleWebkit/534.30 (KHTML, like Gecko) PT/3.8.0'
  122.     },
  123.     strictSSL: false
  124. }*/];
  125.  
  126. Settings.updateEndpoint = {
  127.     url: 'https://popcorntime.re/',
  128.     index: 0,
  129.     proxies: [{
  130.         url: 'https://popcorntime.re/',
  131.         fingerprint: '30:A6:BA:6C:19:A4:D5:C3:5A:E8:F1:56:C6:B4:E1:DC:EF:DD:EC:8C',
  132.     }, {
  133.         url: 'https://popcorntime.io/',
  134.         fingerprint: '30:A6:BA:6C:19:A4:D5:C3:5A:E8:F1:56:C6:B4:E1:DC:EF:DD:EC:8C'
  135.     }, {
  136.         url: 'https://popcorntime.cc/',
  137.         fingerprint: '30:A6:BA:6C:19:A4:D5:C3:5A:E8:F1:56:C6:B4:E1:DC:EF:DD:EC:8C'
  138.     }, {
  139.         url: 'https://its.pt/',
  140.         ssl: false,
  141.         fingerprint: /301/
  142.     }]
  143. };
  144.  
  145. // App Settings
  146. Settings.version = false;
  147. Settings.dbversion = '0.1.0';
  148. Settings.font = 'tahoma';
  149. Settings.defaultWidth = Math.round(window.screen.availWidth * 0.8);
  150. Settings.defaultHeight = Math.round(window.screen.availHeight * 0.8);
  151.  
  152. // Miscellaneous
  153. Settings.playerSubPosition = '0px';
  154. Settings.playerVolume = '1';
  155. Settings.tv_detail_jump_to = 'next';
  156.  
  157.  
  158. var ScreenResolution = {
  159.     get SD() {
  160.         return window.screen.width < 1280 || window.screen.height < 720;
  161.     },
  162.     get HD() {
  163.         return window.screen.width >= 1280 && window.screen.width < 1920 || window.screen.height >= 720 && window.screen.height < 1080;
  164.     },
  165.     get FullHD() {
  166.         return window.screen.width >= 1920 && window.screen.width < 2000 || window.screen.height >= 1080 && window.screen.height < 1600;
  167.     },
  168.     get UltraHD() {
  169.         return window.screen.width >= 2000 || window.screen.height >= 1600;
  170.     },
  171.     get QuadHD() {
  172.         return window.screen.width >= 3000 || window.screen.height >= 1800;
  173.     },
  174.     get Standard() {
  175.         return window.devicePixelRatio <= 1;
  176.     },
  177.     get Retina() {
  178.         return window.devicePixelRatio > 1;
  179.     }
  180. };
  181.  
  182. var AdvSettings = {
  183.  
  184.     get: function (variable) {
  185.         if (typeof Settings[variable] !== 'undefined') {
  186.             return Settings[variable];
  187.         }
  188.  
  189.         return false;
  190.     },
  191.  
  192.     set: function (variable, newValue) {
  193.         Database.writeSetting({
  194.                 key: variable,
  195.                 value: newValue
  196.             })
  197.             .then(function () {
  198.                 Settings[variable] = newValue;
  199.             });
  200.     },
  201.  
  202.     setup: function () {
  203.         AdvSettings.performUpgrade();
  204.         return AdvSettings.getHardwareInfo();
  205.     },
  206.  
  207.     getHardwareInfo: function () {
  208.         if (/64/.test(process.arch)) {
  209.             AdvSettings.set('arch', 'x64');
  210.         } else {
  211.             AdvSettings.set('arch', 'x86');
  212.         }
  213.  
  214.         switch (process.platform) {
  215.         case 'darwin':
  216.             AdvSettings.set('os', 'mac');
  217.             break;
  218.         case 'win32':
  219.             AdvSettings.set('os', 'windows');
  220.             break;
  221.         case 'linux':
  222.             AdvSettings.set('os', 'linux');
  223.             break;
  224.         default:
  225.             AdvSettings.set('os', 'unknown');
  226.             break;
  227.         }
  228.  
  229.         return Q();
  230.     },
  231.  
  232.     getNextApiEndpoint: function (endpoint) {
  233.         if (endpoint.index < endpoint.proxies.length - 1) {
  234.             endpoint.index++;
  235.         } else {
  236.             endpoint.index = 0;
  237.         }
  238.         endpoint.ssl = undefined;
  239.         _.extend(endpoint, endpoint.proxies[endpoint.index]);
  240.         return endpoint;
  241.     },
  242.  
  243.     checkApiEndpoints: function (endpoints) {
  244.         return Q.all(_.map(endpoints, function (endpoint) {
  245.             return AdvSettings.checkApiEndpoint(endpoint);
  246.         }));
  247.     },
  248.  
  249.     checkApiEndpoint: function (endpoint, defer) {
  250.         if (Settings.automaticUpdating === false) {
  251.             return;
  252.         }
  253.         var tls = require('tls'),
  254.             http = require('http'),
  255.             uri = require('url');
  256.  
  257.         defer = defer || Q.defer();
  258.  
  259.         endpoint.ssl = undefined;
  260.         _.extend(endpoint, endpoint.proxies[endpoint.index]);
  261.  
  262.         var url = uri.parse(endpoint.url);
  263.         win.debug('Checking %s endpoint', url.hostname);
  264.  
  265.         if (endpoint.ssl === false) {
  266.             var timeoutWrapper = function (req) {
  267.                 return function () {
  268.                     win.warn('[%s] Endpoint timed out',
  269.                         url.hostname);
  270.                     req.abort();
  271.                     tryNextEndpoint();
  272.                 };
  273.             };
  274.             var request = http.get({
  275.                 hostname: url.hostname
  276.             }, function (res) {
  277.                 res.once('data', function (body) {
  278.                     clearTimeout(timeout);
  279.                     res.removeAllListeners('error');
  280.                     // Doesn't match the expected response
  281.                     if (!_.isRegExp(endpoint.fingerprint) || !endpoint.fingerprint.test(body.toString('utf8'))) {
  282.                         win.warn('[%s] Endpoint fingerprint %s does not match %s',
  283.                             url.hostname,
  284.                             endpoint.fingerprint,
  285.                             body.toString('utf8'));
  286.                         tryNextEndpoint();
  287.                     } else {
  288.                         defer.resolve();
  289.                     }
  290.                 }).once('error', function (e) {
  291.                     win.warn('[%s] Endpoint failed [%s]',
  292.                         url.hostname,
  293.                         e.message);
  294.                     clearTimeout(timeout);
  295.                     tryNextEndpoint();
  296.                 });
  297.             });
  298.  
  299.             var fn = timeoutWrapper(request);
  300.             var timeout = setTimeout(fn, 5000);
  301.         } else {
  302.             tls.connect(443, url.hostname, {
  303.                 servername: url.hostname,
  304.                 rejectUnauthorized: false
  305.             }, function () {
  306.                 this.setTimeout(0);
  307.                 this.removeAllListeners('error');
  308.                 if (!this.authorized ||
  309.                     this.authorizationError ||
  310.                     this.getPeerCertificate().fingerprint !== endpoint.fingerprint) {
  311.                     // "These are not the certificates you're looking for..."
  312.                     // Seems like they even got a certificate signed for us :O
  313.                     win.warn('[%s] Endpoint fingerprint %s does not match %s',
  314.                         url.hostname,
  315.                         endpoint.fingerprint,
  316.                         this.getPeerCertificate().fingerprint);
  317.                     tryNextEndpoint();
  318.                 } else {
  319.                     defer.resolve();
  320.                 }
  321.                 this.end();
  322.             }).once('error', function (e) {
  323.                 win.warn('[%s] Endpoint failed [%s]',
  324.                     url.hostname,
  325.                     e.message);
  326.                 this.setTimeout(0);
  327.                 tryNextEndpoint();
  328.             }).once('timeout', function () {
  329.                 win.warn('[%s] Endpoint timed out',
  330.                     url.hostname);
  331.                 this.removeAllListeners('error');
  332.                 this.end();
  333.                 tryNextEndpoint();
  334.             }).setTimeout(5000);
  335.         }
  336.  
  337.         function tryNextEndpoint() {
  338.             if (endpoint.index < endpoint.proxies.length - 1) {
  339.                 endpoint.index++;
  340.                 AdvSettings.checkApiEndpoint(endpoint, defer);
  341.             } else {
  342.                 endpoint.index = 0;
  343.                 endpoint.ssl = undefined;
  344.                 _.extend(endpoint, endpoint.proxies[endpoint.index]);
  345.                 defer.resolve();
  346.             }
  347.         }
  348.  
  349.         return defer.promise;
  350.     },
  351.  
  352.     performUpgrade: function () {
  353.         // This gives the official version (the package.json one)
  354.         gui = require('nw.gui');
  355.         var currentVersion = gui.App.manifest.version;
  356.  
  357.         if (currentVersion !== AdvSettings.get('version')) {
  358.             // Nuke the DB if there's a newer version
  359.             // Todo: Make this nicer so we don't lose all the cached data
  360.             var cacheDb = openDatabase('cachedb', '', 'Cache database', 50 * 1024 * 1024);
  361.  
  362.             cacheDb.transaction(function (tx) {
  363.                 tx.executeSql('DELETE FROM subtitle');
  364.                 tx.executeSql('DELETE FROM metadata');
  365.             });
  366.  
  367.             // Add an upgrade flag
  368.             window.__isUpgradeInstall = true;
  369.         }
  370.         AdvSettings.set('version', currentVersion);
  371.         AdvSettings.set('releaseName', gui.App.manifest.releaseName);
  372.     },
  373. };
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top