/* * rhwebimport * * Copyright (C) 2014-2016 Christian Pointner * Copyright (C) 2015-2016 Peter Grassberger * * This file is part of rhwebimport. * * rhwebimport is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by * the Free Software Foundation, either version 3 of the License, or * any later version. * * rhwebimport is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with rhwebimport. If not, see . */ 'use strict'; var Rivendell = Rivendell || {}; Rivendell.Rivendell = function(username, token, rdxportEndpoint) { this.username = username; this.token = token; this.rdxportEndpoint = rdxportEndpoint; }; Rivendell.Rivendell.prototype.listLog = function(name, success) { var command = { COMMAND: 22, LOGIN_NAME: this.username, PASSWORD: this.token, NAME: name }; return $.post(this.rdxportEndpoint, command, success, 'xml'); }; Rivendell.Rivendell.prototype.listLogs = function(success) { var command = { COMMAND: 20, LOGIN_NAME: this.username, PASSWORD: this.token //todo: fix optionals /*SERVICE_NAME: serviceName, TRACKABLE: trackable*/ }; return $.post(this.rdxportEndpoint, command, success, 'xml'); }; Rivendell.Rivendell.prototype.listServices = function(success) { var command = { COMMAND: 21, LOGIN_NAME: this.username, PASSWORD: this.token //todo: fix optionals /*TRACKABLE: trackable*/ }; return $.post(this.rdxportEndpoint, command, success, 'xml'); }; Rivendell.Rivendell.prototype.listGroups = function(success) { var command = { COMMAND: 4, LOGIN_NAME: this.username, PASSWORD: this.token }; return $.post(this.rdxportEndpoint, command, success, 'xml'); }; Rivendell.Rivendell.prototype.listGroup = function(groupName, success) { var command = { COMMAND: 5, LOGIN_NAME: this.username, PASSWORD: this.token, GROUP_NAME: groupName }; return $.post(this.rdxportEndpoint, command, success, 'xml'); }; Rivendell.Rivendell.prototype.listCarts = function(groupName, includeCuts, success) { var command = { COMMAND: 6, LOGIN_NAME: this.username, PASSWORD: this.token, GROUP_NAME: groupName, INCLUDE_CUTS: includeCuts }; return $.post(this.rdxportEndpoint, command, success, 'xml'); }; Rivendell.Rivendell.prototype.listCart = function(cartNumber, includeCuts, success) { var command = { COMMAND: 7, LOGIN_NAME: this.username, PASSWORD: this.token, CART_NUMBER: cartNumber, INCLUDE_CUTS: includeCuts }; return $.post(this.rdxportEndpoint, command, success); }; Rivendell.Rivendell.prototype.addCart = function(groupName, type, cartNumber, success) { var command = { COMMAND: 12, LOGIN_NAME: this.username, PASSWORD: this.token, GROUP_NAME: groupName, TYPE: type, CART_NUMBER: cartNumber }; return $.post(this.rdxportEndpoint, command, success, 'xml'); }; Rivendell.Rivendell.prototype.editCart = function(cartNumber, options, success) { options.COMMAND = 14; options.LOGIN_NAME = this.username; options.PASSWORD = this.token; options.CART_NUMBER = cartNumber; return $.post(this.rdxportEndpoint, options, success, 'xml'); }; Rivendell.Rivendell.prototype.removeCart = function(cartNumber, success) { var command = { COMMAND: 13, LOGIN_NAME: this.username, PASSWORD: this.token, CART_NUMBER: cartNumber }; return $.post(this.rdxportEndpoint, command, success, 'xml'); }; Rivendell.Rivendell.prototype.listCuts = function(cartNumber, success) { var command = { COMMAND: 9, LOGIN_NAME: this.username, PASSWORD: this.token, CART_NUMBER: cartNumber }; return $.post(this.rdxportEndpoint, command, success, 'xml'); }; Rivendell.Rivendell.prototype.listCut = function(cartNumber, cutNumber, success) { var command = { COMMAND: 8, LOGIN_NAME: this.username, PASSWORD: this.token, CART_NUMBER: cartNumber, CUT_NUMBER: cutNumber }; return $.post(this.rdxportEndpoint, command, success, 'xml'); }; Rivendell.Rivendell.prototype.addCut = function(cartNumber, success) { var command = { COMMAND: 10, LOGIN_NAME: this.username, PASSWORD: this.token, CART_NUMBER: cartNumber }; return $.post(this.rdxportEndpoint, command, success, 'xml'); }; Rivendell.Rivendell.prototype.editCut = function(cartNumber, cutNumber, options, success) { options.COMMAND = 15; options.LOGIN_NAME = this.username; options.PASSWORD = this.token; options.CART_NUMBER = cartNumber; options.CUT_NUMBER = cutNumber; return $.post(this.rdxportEndpoint, options, success, 'xml'); }; Rivendell.Rivendell.prototype.addAndEditCut = function(cartNumber, options, success) { var self = this; var returnJqXHR = null; return this.addCut(cartNumber, success) .success(function(data, textStatus, jqXHR) { var cutNumber = $('cutAdd cut cutNumber', data).text(); returnJqXHR = self.editCut(cartNumber, cutNumber, options, null); }); }; Rivendell.Rivendell.prototype.removeCut = function(cartNumber, cutNumber, success) { var command = { COMMAND: 11, LOGIN_NAME: this.username, PASSWORD: this.token, CART_NUMBER: cartNumber, CUT_NUMBER: cutNumber }; return $.post(this.rdxportEndpoint, command, success, 'xml'); }; /** * * todo: copy description and other data. * * @param sourceCartNumber * @param sourceCutNumber * @param destinationCartNumber * @param success * @returns {*} */ Rivendell.Rivendell.prototype.copyCut = function(sourceCartNumber, sourceCutNumber, destinationCartNumber, success) { var self = this; var returnJqXHR = null; this.listCut(sourceCartNumber, sourceCutNumber, function(data, textStatus, jqXHR) { var options = { DESCRIPTION: $('cutList cut description', data).text() // todo: add more options }; self.addAndEditCut(destinationCartNumber, options, function(data, textStatus, jqXHR) { var destinationCutNumber = $('cutAdd cut cutNumber', data).text(); returnJqXHR = self.copyAudio(sourceCartNumber,sourceCutNumber, destinationCartNumber, destinationCutNumber, success) .fail(function() { self.removeCut(destinationCartNumber, destinationCutNumber, null); }); }); }); return returnJqXHR; }; /** * * @param sourceCartNumber * @param sourceCutNumber * @param destinationCartNumber * @param success */ Rivendell.Rivendell.prototype.moveCut = function(sourceCartNumber, sourceCutNumber, destinationCartNumber, success) { var self = this; var returnJqXHR = null; this.copyCut(sourceCartNumber, sourceCutNumber, destinationCartNumber, function(data, textStatus, jqXHR) { returnJqXHR = self.removeCut(sourceCartNumber, sourceCutNumber, success); }); return returnJqXHR; }; Rivendell.Rivendell.prototype.copyAudio = function(sourceCartNumber, sourceCutNumber, destinationCartNumber, destinationCutNumber, success) { var command = { COMMAND: 18, LOGIN_NAME: this.username, PASSWORD: this.token, SOURCE_CART_NUMBER: sourceCartNumber, SOURCE_CUT_NUMBER: sourceCutNumber, DESTINATION_CART_NUMBER: destinationCartNumber, DESTINATION_CUT_NUMBER: destinationCutNumber }; return $.post(this.rdxportEndpoint, command, success, 'xml'); }; Rivendell.Rivendell.prototype.audioInfo = function(cartNumber, cutNumber, success) { var command = { COMMAND: 19, LOGIN_NAME: this.username, PASSWORD: this.token, CART_NUMBER: cartNumber, CUT_NUMBER: cutNumber }; return $.post(this.rdxportEndpoint, command, success, 'xml'); }; Rivendell.Rivendell.prototype.audioStore = function(success) { var command = { COMMAND: 23, LOGIN_NAME: this.username, PASSWORD: this.token }; return $.post(this.rdxportEndpoint, command, success, 'xml'); }; Rivendell.Rivendell.prototype.import = function(cartNumber, cutNumber, channels, normalizationLevel, autotrimLevel, useMetadata, filename, success) { var command = { COMMAND: 2, LOGIN_NAME: this.username, PASSWORD: this.token, CART_NUMBER: cartNumber, CUT_NUMBER: cutNumber, CHANNELS: channels, NORMALIZATION_LEVEL: normalizationLevel, AUTOTRIM_LEVEL: autotrimLevel, USE_METADATA: useMetadata, FILENAME: filename }; return $.post(this.rdxportEndpoint, command, success, 'xml'); }; Rivendell.Rivendell.prototype.export = function(cartNumber, cutNumber, format, channels, sampleRate, bitRate, quality, startPoint, endPoint, normalizationLevel, enableMetadata, success) { var command = { COMMAND: 1, LOGIN_NAME: this.username, PASSWORD: this.token, CART_NUMBER: cartNumber, CUT_NUMBER: cutNumber, FORMAT: format, CHANNELS: channels, SAMPLE_RATE: sampleRate, BIT_RATE: bitRate, QUALITY: quality, START_POINT: startPoint, END_POINT: endPoint, NORMALIZATION_LEVEL: normalizationLevel, ENABLE_METADATA: enableMetadata }; return $.post(this.rdxportEndpoint, command, success, 'xml'); }; Rivendell.Rivendell.prototype.exportPeaks = function(cartNumber, cutNumber, success) { var command = { COMMAND: 16, LOGIN_NAME: this.username, PASSWORD: this.token, CART_NUMBER: cartNumber, CUT_NUMBER: cutNumber }; return $.post(this.rdxportEndpoint, command, success, 'xml'); }; Rivendell.Rivendell.prototype.trimAudio = function(cartNumber, cutNumber, trimLevel, success) { var command = { COMMAND: 17, LOGIN_NAME: this.username, PASSWORD: this.token, CART_NUMBER: cartNumber, CUT_NUMBER: cutNumber, TRIM_LEVEL: trimLevel }; return $.post(this.rdxportEndpoint, command, success, 'xml'); }; Rivendell.Rivendell.prototype.deleteAudio = function(cartNumber, cutNumber, success) { var command = { COMMAND: 3, LOGIN_NAME: this.username, PASSWORD: this.token, CART_NUMBER: cartNumber, CUT_NUMBER: cutNumber }; return $.post(this.rdxportEndpoint, command, success, 'xml'); }; Rivendell.GroupList = function(rivendell) { this.rivendell = rivendell; this.groups = []; }; Rivendell.GroupList.prototype.destroy = function() { $(this.groups).each(function(index, group) { group.destroy(); }); }; Rivendell.Group = function(groupName, description, lowcart, highcart, normlevel, trimlevel) { this.xml = null; if (arguments.length === 1) { this.xml = arguments[0]; this.groupName = $('group', this.xml).text(); this.description = $('group-description', this.xml).text(); this.lowcart = $('group-low-cart', this.xml).text(); this.highcart = $('group-high-cart', this.xml).text(); this.normlevel = $('normalization-level', this.xml).text(); this.trimlevel = $('autotrim-level', this.xml).text(); } else { this.groupName = groupName; this.description = description; this.lowcart = lowcart; this.highcart = highcart; this.normlevel = normlevel; this.trimlevel = trimlevel; } this.carts = []; }; Rivendell.Group.prototype.fetchCarts = function() { var self = this; rivendell.listCarts(this.groupName, 1, function(cartsXml, status, req) { self.carts = []; var dbs = $('cartList', cartsXml).children(); dbs.each(function(index, cartXml) { var cart = new Rivendell.Cart(cartXml, self); var cuts = $('cutList', cartXml).children(); cuts.each(function(index, cut) { cart.cuts.push(new Rivendell.Cut(cut, cart)); }); self.carts.push(cart); }); $(self).trigger('update'); }); }; Rivendell.Cart = function(number, title, groupName, group) { this.xml = null; if (arguments.length === 2) { this.xml = arguments[0]; this.number = $('number', this.xml).text(); this.title = $('title', this.xml).text(); this.groupName = $('groupName', this.xml).text(); this.group = arguments[1]; } else { this.number = number; this.title = title; this.groupName = groupName; this.group = group; } this.cuts = []; }; Rivendell.Cart.prototype.addCut = function(cut) { this.cuts.push(cut); }; Rivendell.Cart.prototype.removeCut = function(cut) { var self = this; $.each(this.cuts, function(index, currentCut){ if(currentCut === cut) { self.cuts.splice(index, 1); } }); }; Rivendell.Cut = function(name, description, cart) { this.xml = null; if (arguments.length === 2) { this.xml = arguments[0]; this.name = $('cutName', this.xml).text(); this.description = $('description', this.xml).text(); this.cart = arguments[1]; } else { this.name = name; this.description = description; this.cart = cart; } this.number = this.name.substr(-3); this.cartNumber = this.cart.number; };