UNPKG

ez-organizer

Version:

Organise tvshows automatically (part of the 'ez' programs)

166 lines (140 loc) 5.28 kB
"use strict"; var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard"); var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator")); var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator")); var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck")); var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass")); var path = _interopRequireWildcard(require("path")); var episodeHelper = _interopRequireWildcard(require("helpers/episode")); var folderHelper = _interopRequireWildcard(require("helpers/folder")); var _FileStream = _interopRequireDefault(require("modules/FileStream")); var Episode = /*#__PURE__*/ function () { function Episode(_URI, _outputURI) { (0, _classCallCheck2.default)(this, Episode); this.fileUri = _URI; this.episodeData = this._parseData(); this.outpuDirURI = folderHelper.structureShow(_outputURI, this.episodeData.showName, this.episodeData.season); this.outputFileName = this._outputFileName(); this.stream = new _FileStream.default(_URI, this.outputFileName); } (0, _createClass2.default)(Episode, [{ key: "getEpisodeData", value: function getEpisodeData() { return this.episodeData; } }, { key: "allowedToCopy", value: function () { var _allowedToCopy = (0, _asyncToGenerator2.default)( /*#__PURE__*/ _regenerator.default.mark(function _callee() { var distinationStat; return _regenerator.default.wrap(function _callee$(_context) { while (1) { switch (_context.prev = _context.next) { case 0: _context.next = 2; return this._existsInDistination(); case 2: distinationStat = _context.sent; if (distinationStat) { _context.next = 5; break; } return _context.abrupt("return", true); case 5: return _context.abrupt("return", this._notInputSameAsOutput(distinationStat)); case 6: case "end": return _context.stop(); } } }, _callee, this); })); return function allowedToCopy() { return _allowedToCopy.apply(this, arguments); }; }() }, { key: "_notInputSameAsOutput", value: function () { var _notInputSameAsOutput2 = (0, _asyncToGenerator2.default)( /*#__PURE__*/ _regenerator.default.mark(function _callee2(stat) { var fileInputSize; return _regenerator.default.wrap(function _callee2$(_context2) { while (1) { switch (_context2.prev = _context2.next) { case 0: _context2.next = 2; return this.stream._fileStats(this.fileUri).then(function (stat) { return stat.size; }); case 2: fileInputSize = _context2.sent; return _context2.abrupt("return", fileInputSize !== stat.size); case 4: case "end": return _context2.stop(); } } }, _callee2, this); })); return function _notInputSameAsOutput(_x) { return _notInputSameAsOutput2.apply(this, arguments); }; }() }, { key: "_existsInDistination", value: function () { var _existsInDistination2 = (0, _asyncToGenerator2.default)( /*#__PURE__*/ _regenerator.default.mark(function _callee3() { return _regenerator.default.wrap(function _callee3$(_context3) { while (1) { switch (_context3.prev = _context3.next) { case 0: return _context3.abrupt("return", this.stream.exists(this.outputFileName)); case 1: case "end": return _context3.stop(); } } }, _callee3, this); })); return function _existsInDistination() { return _existsInDistination2.apply(this, arguments); }; }() }, { key: "_outputFileName", value: function _outputFileName() { return path.join(this.outpuDirURI, this.episodeData.filename); } }, { key: "_parseData", value: function _parseData() { var filename = path.basename(this.fileUri); var episodeDetails = filename.match(episodeHelper.matchRgx)[0]; var showName = filename.slice(0, filename.indexOf(episodeDetails) - 1).trim(); var episode = parseInt(episodeDetails.slice(episodeDetails.toLowerCase().indexOf('e') + 1, episodeDetails.length)); var season = parseInt(episodeDetails.slice(0, episodeDetails.toLowerCase().indexOf('e')).replace(/s/ig, '')); return { filename: filename, showName: showName, episode: episode, season: season }; } }]); return Episode; }(); exports.default = Episode; //# sourceMappingURL=Episode.js.map