Create the TVRenamer class which as of now just parses the name.
authorRobert Sesek <rsesek@bluestatic.org>
Sat, 13 Nov 2010 22:30:48 +0000 (17:30 -0500)
committerRobert Sesek <rsesek@bluestatic.org>
Sat, 13 Nov 2010 22:30:48 +0000 (17:30 -0500)
build.py
web_frontend/actor.js
web_frontend/screen.css
web_frontend/tv_renamer.js [new file with mode: 0644]

index 2915eb27772eeaa8afb77bc9fb64108812c7ce06..cb3b44c363e3950cb6880f86d64f8afb2fc15078 100755 (executable)
--- 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',
index 10ed34c9f301a4a76a5bd3f2a12b8edffd4964b3..4fe72d31cc682f0865dd665dd58494a45d17ea55 100644 (file)
@@ -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.
index 0411ca57f02a5890a729b39a131dd16b056ed4d4..43baed61faef7a834eafcee7903b2f685a097061 100644 (file)
@@ -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 (file)
index 0000000..1c8733c
--- /dev/null
@@ -0,0 +1,82 @@
+//
+// Armadillo File Manager
+// Copyright (c) 2010, Robert Sesek <http://www.bluestatic.org>
+// 
+// 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;
+};