From da210491df68b10da324363908f4547df36bb31c Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Sat, 13 Nov 2010 17:30:48 -0500 Subject: [PATCH] Create the TVRenamer class which as of now just parses the name. --- build.py | 1 + web_frontend/actor.js | 18 ++++++++- web_frontend/screen.css | 7 ++-- web_frontend/tv_renamer.js | 82 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 102 insertions(+), 6 deletions(-) create mode 100644 web_frontend/tv_renamer.js diff --git a/build.py b/build.py index 2915eb2..cb3b44c 100755 --- a/build.py +++ b/build.py @@ -37,6 +37,7 @@ SOURCES = [ ] SOURCES_FE = [ 'version.js', + 'tv_renamer.js', 'path_control.js', 'actor.js', 'file.js', diff --git a/web_frontend/actor.js b/web_frontend/actor.js index 10ed34c..4fe72d3 100644 --- a/web_frontend/actor.js +++ b/web_frontend/actor.js @@ -11,6 +11,7 @@ goog.provide('armadillo.Actor'); goog.provide('armadillo.Actor.TileControlRenderer_'); goog.require('armadillo.PathControl'); +goog.require('armadillo.TVRenamer'); goog.require('goog.array'); goog.require('goog.dom'); goog.require('goog.events'); @@ -56,7 +57,8 @@ armadillo.Actor.options_ = { OPEN : 'open', MOVE : 'move', RENAME : 'rename', - DELETE : 'delete' + DELETE : 'delete', + TV_RENAME : 'tv-rename', }; /** @@ -66,7 +68,8 @@ armadillo.Actor.optionStrings_ = { 'open' : 'Open', 'move' : 'Move', 'rename' : 'Rename', - 'delete' : 'Delete' + 'delete' : 'Delete', + 'tv-rename' : 'Rename TV Episode', }; /** @@ -150,6 +153,8 @@ armadillo.Actor.prototype.tileClickHandler_ = function(e) { this.performMove_(); } else if (option == armadillo.Actor.options_.DELETE) { this.performDelete_(); + } else if (option == armadillo.Actor.options_.TV_RENAME) { + this.performTVRename_(); } }; @@ -206,6 +211,15 @@ armadillo.Actor.prototype.performDelete_ = function() { this.actionObject_.setVisible(true); }; +/** + * Subroutine that renames a file to it's title based on season and episode. + * @private + */ +armadillo.Actor.prototype.performTVRename_ = function() { + var renamer = new armadillo.TVRenamer(this.file_); + renamer.run(); +}; + /** * Creates a new instance of a Dialog that has some basic properties set that * are common to performing actions. diff --git a/web_frontend/screen.css b/web_frontend/screen.css index 0411ca5..43baed6 100644 --- a/web_frontend/screen.css +++ b/web_frontend/screen.css @@ -69,8 +69,7 @@ h1 { } .actor { - width: 8.5em; - height: 8.5em; + height: 2.3em; background-color: rgb(77, 79, 83); @@ -82,8 +81,8 @@ h1 { } .actor .tile { - width: 4em; - height: 4em; + padding: 0em 1em 0em 1em; + height: 2em; display: inline-block; margin: .1em; diff --git a/web_frontend/tv_renamer.js b/web_frontend/tv_renamer.js new file mode 100644 index 0000000..1c8733c --- /dev/null +++ b/web_frontend/tv_renamer.js @@ -0,0 +1,82 @@ +// +// Armadillo File Manager +// Copyright (c) 2010, Robert Sesek +// +// This program is free software: you can redistribute it and/or modify it under +// the terms of the GNU General Public License as published by the Free Software +// Foundation, either version 3 of the License, or any later version. +// + +goog.provide('armadillo.TVRenamer'); + +goog.require('goog.Disposable'); +goog.require('goog.net.XhrIo'); + +/** + * Creates a helper to rename a file in a pretty format for TV episodes. + * @extends {goog.Disposable} + * @constructor + */ +armadillo.TVRenamer = function(file) { + goog.base(this); + + /** + * The file object + * @type {armadillo.File} + */ + this.file_ = file; +} +goog.inherits(armadillo.TVRenamer, goog.Disposable); + +/** + * @inheritDoc + */ +armadillo.TVRenamer.prototype.disposeInternal = function() { + goog.base(this); + this.file_ = null; +}; + +/** + * Performs the information lookup and renames the file if the lookup is + * successful. + */ +armadillo.TVRenamer.prototype.run = function() { + console.log('running for ' + this.file_.getName()); + console.log(this.parseName_(this.file_.getName())); + // goog.net.XhrIo.send(); +}; + +/** + * Callback for when the network data is received. + * @private + */ +armadillo.TVRenamer.prototype.lookupHandler_ = function() { +}; + +/** + * Parses the TV episode data out of the name. + * @param {string!} name The current file name. + * @returns {Tuple|null} Returns a tuple (show,season,episode) on success, + NULL on failure + * @private + */ +armadillo.TVRenamer.prototype.parseName_ = function(name) { + var pattern = /^(\d+_)?(.+) S?(\d+)(x|E)(\d+)/; + var matches = name.match(pattern); + if (!matches || matches.length < 5) + return null; + return [matches[2], parseInt(matches[3]), parseInt(matches[5])]; +}; + +/** + * Builds the query URL. + * @param {string!} show Show name + * @param {number!} season Season number + * @param {number!} episode Episode number + * @returns {string} + * @private + */ +armadillo.TVRenamer.prototype.buildURL_ = function(show, season, episode) { + return "http://services.tvrage.com/tools/quickinfo.php?show=" + show + + "&ep=" + season + "x" + episode; +}; -- 2.43.5