2 // Armadillo File Manager
3 // Copyright (c) 2010, Robert Sesek <http://www.bluestatic.org>
5 // This program is free software: you can redistribute it and/or modify it under
6 // the terms of the GNU General Public License as published by the Free Software
7 // Foundation, either version 3 of the License, or any later version.
10 goog
.provide('armadillo.TVRenamer');
12 goog
.require('goog.Disposable');
13 goog
.require('goog.net.XhrIo');
16 * Creates a helper to rename a file in a pretty format for TV episodes.
17 * @extends {goog.Disposable}
20 armadillo
.TVRenamer
= function(file
) {
25 * @type {armadillo.File}
29 goog
.inherits(armadillo
.TVRenamer
, goog
.Disposable
);
34 armadillo
.TVRenamer
.prototype.disposeInternal
= function() {
40 * Performs the information lookup and renames the file if the lookup is
43 armadillo
.TVRenamer
.prototype.run
= function() {
44 console
.log('running for ' + this.file_
.getName());
45 console
.log(this.parseName_(this.file_
.getName()));
46 // goog.net.XhrIo.send();
50 * Callback for when the network data is received.
53 armadillo
.TVRenamer
.prototype.lookupHandler_
= function() {
57 * Parses the TV episode data out of the name.
58 * @param {string!} name The current file name.
59 * @returns {Tuple|null} Returns a tuple (show,season,episode) on success,
63 armadillo
.TVRenamer
.prototype.parseName_
= function(name
) {
64 var pattern
= /^(\d
+_
)?(.+) S
?(\d
+)(x
|E
)(\d
+)/;
65 var matches
= name
.match(pattern
);
66 if (!matches
|| matches
.length
< 5)
68 return [matches
[2], parseInt(matches
[3]), parseInt(matches
[5])];
72 * Builds the query URL.
73 * @param {string!} show Show name
74 * @param {number!} season Season number
75 * @param {number!} episode Episode number
79 armadillo
.TVRenamer
.prototype.buildURL_
= function(show
, season
, episode
) {
80 return "http://services.tvrage.com/tools/quickinfo.php?show=" + show
+
81 "&ep=" + season
+ "x" + episode
;