diff --git a/CONTROL/control b/CONTROL/control
index aae87a3..e750e8a 100644
--- a/CONTROL/control
+++ b/CONTROL/control
@@ -1,7 +1,7 @@
Package: webif
Priority: optional
Section: web
-Version: 1.2.5
+Version: 1.2.5-1
Architecture: mipsel
Maintainer: af123@hummypkg.org.uk
Depends: webif-channelicons(>=1.1.18),lighttpd(>=1.4.35-2),jim(>=0.76),jim-oo,jim-sqlite3(>=0.76),jim-cgi(>=0.7),jim-binary(>=0.76),service-control(>=2.1),busybox(>=1.20.2-1),lsof(>=4.87),epg(>=1.2.0),hmt(>=2.0.7),ssmtp,anacron,trm(>=1.1),openssl-command,nicesplice,id3v2,file,rsvsync(>=1.0.2),webif-charts(>=1.2-1),stripts(>=1.2.5-3),smartmontools,tmenu(>=1.08),ffmpeg,id3v2,multienv(>=1.6),tcpping(>=1.1),e2fsprogs,wireless-tools(>=29-1),dbupdate,recmon(>=2.0.7)
diff --git a/webif/html/browse/assets.jim b/webif/html/browse/assets.jim
index 10e2217..84ead1e 100755
--- a/webif/html/browse/assets.jim
+++ b/webif/html/browse/assets.jim
@@ -361,7 +361,9 @@ puts {
Retrieving data...
+
+
diff --git a/webif/html/browse/file.jim b/webif/html/browse/file.jim
index 24571d0..4d7442b 100755
--- a/webif/html/browse/file.jim
+++ b/webif/html/browse/file.jim
@@ -49,17 +49,22 @@ if {$type eq "ts"} {
"
if {[llength $sdata] && [llength $idata]} {
- puts " DEBUG TVDB "
+
+ "
}
+# $idata(overview)
+#
+# [$sdata get _phrases]
+#
+# [lrange [$sdata get _smatches] 0 8]
+
if {[$ts flag "Guidance"] > 0} {
puts "
Guidance
@@ -139,7 +144,8 @@ puts "
"
set fileset [$ts fileset]
-puts -nonewline " "
+puts -nonewline " "
puts -nonewline "[llength $fileset] file"
if {[llength $fileset] != 1} { puts -nonewline "s" }
puts -nonewline " in set."
@@ -165,12 +171,15 @@ if {[$ts get bookmarks]} {
puts ""
puts {
diff --git a/webif/html/browse/index.jim b/webif/html/browse/index.jim
index 5f99c6f..5df566b 100755
--- a/webif/html/browse/index.jim
+++ b/webif/html/browse/index.jim
@@ -3,14 +3,16 @@
package require cgi
source /mod/webif/lib/setup
require ts.class pretty_size system.class settings.class escape browse.class \
- plugin epg.class
+ plugin epg.class classdump
set mroot [system mediaroot]
set dir [cgi_get dir $mroot]
-jqplugin contextMenu bar enadis
+jqplugin contextMenu bar enadis blockui
jscss script.js style.css
+if {[system has tvdb]} { jscss tvdb/script.js tvdb/style.css }
+
set plugins { dmenu {} menu {} omenu {} buttons {} }
eval_plugins browse
@@ -229,6 +231,7 @@ proc entry {file} {{i 0}} {
# Render web page
source assets.jim
+if {[system has tvdb]} { source tvdb/assets.jim }
if {!$dlnaok && ![system instandby]} {
puts {
@@ -255,6 +258,10 @@ foreach part [split $dir /] {
puts " "
puts ""
+if {[system has tvdb] && [string length $dir] > [string length $mroot]} {
+ source tvdb/banner.jim
+}
+
# Parent directory
set parent [join [lrange [split $dir /] 0 end-1] /]
if {$parent ne ""} {
diff --git a/webif/html/browse/script.js b/webif/html/browse/script.js
index d19c566..954837b 100755
--- a/webif/html/browse/script.js
+++ b/webif/html/browse/script.js
@@ -10,6 +10,15 @@ var plugins = {
var dir;
+function blockpage(msg)
+{
+ if (!msg)
+ msg = 'Refreshing page...';
+ $.blockUI({
+ message: ' ' + msg + ' '
+ });
+}
+
function disableall()
{
$('button,a,input').disable();
@@ -67,10 +76,12 @@ $('#paste').button()
.click(function() {
disableall();
pastedialogue();
- $('#pwfeedback').load(
- '/browse/clipboard.jim?act=paste&dir='
- + encodeURIComponent(dir), function() {
+ $('#pwfeedback').load('/browse/clipboard.jim', {
+ act: 'paste',
+ dir: dir
+ }, function() {
$('#pwdialogue').dialog('close');
+ blockpage();
window.location.reload(true);
});
});
@@ -160,19 +171,19 @@ function delete_callback(file, dir, id)
function lock_callback(file, type, id)
{
var url = '/browse/lock.jim?file=' + file;
- $.get(url, function() { window.location.reload(true); });
+ $.get(url, function() { blockpage(); window.location.reload(true); });
}
function enc_callback(file, type, id)
{
var url = '/browse/enc.jim?file=' + file;
- $.get(url, function() { window.location.reload(true); });
+ $.get(url, function() { blockpage(); window.location.reload(true); });
}
function new_callback(file, type, id)
{
var url = '/browse/new.jim?file=' + file;
- $.get(url, function() { window.location.reload(true); });
+ $.get(url, function() { blockpage(); window.location.reload(true); });
}
function thumbnail_callback(file, type, id)
@@ -193,14 +204,14 @@ function rename_submit()
{
var s = $('#renameform_form').serialize();
$.post('/browse/rename.jim', s,
- function() { window.location.reload(true); });
+ function() { blockpage(); window.location.reload(true); });
}
function drename_submit()
{
var s = $('#drenameform_form').serialize();
$.get('/browse/rename.jim?' + s,
- function() { window.location.reload(true); });
+ function() { blockpage(); window.location.reload(true); });
}
function aexpiry_submit()
@@ -208,7 +219,7 @@ function aexpiry_submit()
$('#aexpiry_working').slideDown('slow');
var s = $('#aexpiry_form').serialize();
$.get('/browse/aexpiry.jim?' + s,
- function() { window.location.reload(true); });
+ function() { blockpage(); window.location.reload(true); });
}
function aexpiry_remove()
@@ -216,14 +227,14 @@ function aexpiry_remove()
$('#aexpiry_working').slideDown('slow');
var s = $('#aexpiry_form').serialize();
$.get('/browse/aexpiry.jim?act=remove&' + s,
- function() { window.location.reload(true); });
+ function() { blockpage(); window.location.reload(true); });
}
function newdir_submit()
{
var s = $('#newdirform_form').serialize();
$.get('/browse/mknewdir.jim?' + s,
- function() { window.location.reload(true); });
+ function() { blockpage(); window.location.reload(true); });
}
function savestream_submit()
@@ -235,6 +246,7 @@ function savestream_submit()
$.get('/browse/savestream.jim?sfile=' +
encodeURIComponent(sf) + '&' + s,
function() {
+ blockpage();
window.location.reload(true);
});
}
@@ -691,6 +703,7 @@ var dmenuclick = function(action, el, pos)
case 'resetnew':
var url = '/browse/resetnew.jim?dir=' + file;
+ blockpage();
$.get(url, function() { window.location.reload(true); });
break;
@@ -877,12 +890,10 @@ var dmenuclick = function(action, el, pos)
});
// Load folder sizes
- $.getJSON('/browse/sizes.jim?dir=' + encodeURIComponent(dir),
- folder_size_callback);
+ $.getJSON('/browse/sizes.jim', {dir: dir}, folder_size_callback);
// Flag folders with unwatched items
- $.getJSON('/browse/newdir.jim?dir=' + encodeURIComponent(dir),
- new_folder_callback);
+ $.getJSON('/browse/newdir.jim', {dir: dir}, new_folder_callback);
// Load clipboard
reloadclipboard();
@@ -967,6 +978,7 @@ var dmenuclick = function(action, el, pos)
'files': files
}, function() {
$('#pwdialogue').dialog('close');
+ blockpage();
window.location.reload(true);
});
}
diff --git a/webif/html/browse/tvdb/assets.jim b/webif/html/browse/tvdb/assets.jim
new file mode 100755
index 0000000..1ca16aa
--- /dev/null
+++ b/webif/html/browse/tvdb/assets.jim
@@ -0,0 +1,57 @@
+#!/mod/bin/jimsh
+
+puts {
+
+
+
+
+
+
+ Searching theTVDB.com database, please wait...
+
+
+
+ Retrieving episode details from theTVDB.com, please wait...
+
+
+ You can optionally force a particular series number for this folder.
+ This is useful when the broadcasters do not set good synopses or
+ if episode names are re-used across series. Leave it set to zero
+ if you do not wish to do this.
+
+
+
+
+
+}
+
diff --git a/webif/html/browse/tvdb/banner.jim b/webif/html/browse/tvdb/banner.jim
new file mode 100644
index 0000000..36d9cb8
--- /dev/null
+++ b/webif/html/browse/tvdb/banner.jim
@@ -0,0 +1,35 @@
+#!/mod/bin/jimsh
+
+require classdump
+
+if {[file exists "$dir/.tvdbseriesid"]} {
+ set seriesid [string trim [file read "$dir/.tvdbseriesid"]]
+ set tvdb_series [set v [tvdb series [file tail $dir] $seriesid]]
+ puts ""
+ if {[set banner [$v get banner]] ne ""} {
+ puts "
+
+ "
+ }
+ puts "
+
+
+ [cgi_quote_html [$v get name]]
+
+
+ "
+ if {[file exists "$dir/.tvdbseries"]} {
+ set n [string trim [file read "$dir/.tvdbseries"]]
+ puts "(S$n)"
+ }
+ puts "
Change "
+ puts "
"
+} else {
+ puts {
+
+
+ Select Series
+
+ }
+}
+
diff --git a/webif/html/browse/tvdb/script.js b/webif/html/browse/tvdb/script.js
new file mode 100644
index 0000000..d22647f
--- /dev/null
+++ b/webif/html/browse/tvdb/script.js
@@ -0,0 +1,112 @@
+
+$(function() {
+
+function select_episode()
+{
+ var sid = $(this).attr('sid');
+
+ $('.tvdbresults').hide();
+ $('#tvdbresults_saving').show();
+ $('#tvdbresults').dialog('option', 'position', {
+ my: "center", at: "center", of: window });
+
+ $.get('tvdb/store.jim', { dir: dir, sid: sid }, function(data) {
+ if (data <= 0)
+ {
+ window.location.reload(true);
+ return;
+ }
+ $('.tvdbresults').hide();
+ $('#tvdbresults_force').show();
+ $('#tvdb_forceseries').attr('max', data).val(0);
+ $('#tvdbresults_forcesave')
+ .button()
+ .on('click', function() {
+ $('.tvdbresults').hide();
+ $('#tvdbresults_saving').show();
+ $('#tvdbresults').dialog('option', 'position', {
+ my: "center", at: "center", of: window });
+ $.get('tvdb/store.jim', {
+ dir: dir,
+ sid: sid,
+ series: $('#tvdb_forceseries').val()
+ }, function() {
+ window.location.reload(true);
+ });
+ });
+ });
+}
+
+$('#tvdbsetseries').button().on('click', function() {
+ val = $('#tvdbseriesname').text();
+ if (!val)
+ val = dir.split(/[\\/]/).pop();
+ val = val.trim();
+ $('#tvdbsearch').val(val);
+ $('#tvdbdialogue').dialog({
+ modal: true, autoOpen: true,
+ height: 'auto', width: 'auto',
+ show: 'scale', hide: 'fade',
+ draggable: true, resizable: true,
+ closeOnEscape: true,
+ buttons: [
+ {
+ text: "Search",
+ icons: { primary: "ui-icon-search" },
+ click: function() {
+ $(this).dialog('close');
+ $('.tvdbresults').hide();
+ $('#tvdbresults_loading').show();
+ $('#tvdbresults_inner').empty();
+ $('#tvdbresults').dialog({
+ modal: true, autoOpen: true,
+ height: 'auto', width: 'auto',
+ show: 'scale', hide: 'fade',
+ draggable: true, resizable: true,
+ closeOnEscape: true,
+ buttons: {
+ "Cancel": function() {
+ $(this).dialog('close');
+ }
+ }
+ });
+ $('#tvdbresults_inner').load('tvdb/search.jim',
+ { term: $('#tvdbsearch').val() }, function() {
+ $('#tvdbresults_inner')
+ .find('.tvdbselect')
+ .button()
+ .on('click', select_episode);
+ $('#tvdbresults_loading').slideUp('slow');
+ $('#tvdbresults_inner').show();
+ $('#tvdbresults').dialog('option',
+ 'position', {
+ my: "center", at: "center", of: window });
+ });
+ }
+ },
+ {
+ text: "Clear Series Information",
+ 'class': 'red',
+ click: function() {
+ if (!confirm('Clear series information for ' +
+ 'this folder?'))
+ return;
+ blockpage('Clearing Series Information...');
+ $.get('tvdb/store.jim', {dir: dir, sid: 0},
+ function() {
+ window.location.reload(true);
+ });
+ }
+ },
+ {
+ text: "Close",
+ click: function() {
+ $(this).dialog('close');
+ }
+ }
+ ]
+ });
+});
+
+});
+
diff --git a/webif/html/browse/tvdb/search.jim b/webif/html/browse/tvdb/search.jim
new file mode 100755
index 0000000..131a8f3
--- /dev/null
+++ b/webif/html/browse/tvdb/search.jim
@@ -0,0 +1,30 @@
+#!/mod/bin/jimsh
+
+package require cgi
+source /mod/webif/lib/setup
+require tvdb.class
+
+set term [cgi_get term -]
+if {$term eq "-"} exit
+
+httpheader
+
+foreach series [[tvdb] searchseries $term] {
+ puts "
+
+
+
+
+ $series(seriesname)
+
+
+ Select
+
+
+
+ $series(overview)
+
+
+ "
+}
+
diff --git a/webif/html/browse/tvdb/store.jim b/webif/html/browse/tvdb/store.jim
new file mode 100755
index 0000000..233888c
--- /dev/null
+++ b/webif/html/browse/tvdb/store.jim
@@ -0,0 +1,33 @@
+#!/mod/bin/jimsh
+
+package require cgi
+source /mod/webif/lib/setup
+require tvdb.class classdump
+
+set dir [cgi_get dir -]
+set sid [cgi_get sid -]
+set series [cgi_get series 0]
+
+httpheader
+
+if {$dir eq "-" || $sid eq "-"} exit
+
+if {$sid == 0} {
+ file delete "$dir/.tvdbseriesid"
+ file delete "$dir/.tvdbseries"
+ puts -nonewline 0
+ exit
+}
+
+set v [tvdb series "" $sid]
+if {[$v get seriesid] == 0} exit
+
+file write "$dir/.tvdbseriesid" $sid
+if {$series > 0} {
+ file write "$dir/.tvdbseries" $series
+} else {
+ file delete "$dir/.tvdbseries"
+}
+
+puts -nonewline [$v series_count]
+
diff --git a/webif/html/browse/tvdb/style.css b/webif/html/browse/tvdb/style.css
new file mode 100644
index 0000000..d285df6
--- /dev/null
+++ b/webif/html/browse/tvdb/style.css
@@ -0,0 +1,32 @@
+
+div.tvdbseries
+{
+ border-top: 1px solid;
+ padding-top: 4px;
+ vertical-align: middle;
+}
+
+div.tvdbsynopsis
+{
+ font-style: italic;
+ margin: 0 2em;
+}
+
+img.tvdbbanner
+{
+ height: 30px;
+ vertical-align: middle;
+}
+
+img.tvdbbannertop
+{
+ height: 60px;
+ vertical-align: middle;
+}
+
+img.tvdblogo
+{
+ vertical-align: middle;
+ height: 25px;
+}
+
diff --git a/webif/html/css/style.css b/webif/html/css/style.css
index 738ee48..9c8f8b3 100644
--- a/webif/html/css/style.css
+++ b/webif/html/css/style.css
@@ -453,21 +453,21 @@ span.toolbarcell
button.blue
{
- background: url(/img/gloss_wave_blue.png) repeat-x center;
+ background: url(/img/gloss_wave_blue.png) repeat-x center !important;
border: 1px solid blue;
color: #ffffff;
}
button.green
{
- background: url(/img/gloss_wave_green.png) repeat-x center;
+ background: url(/img/gloss_wave_green.png) repeat-x center !important;
border: 1px solid green;
color: #ffffff;
}
button.red
{
- background: url(/img/gloss_wave_red.png) repeat-x center;
+ background: url(/img/gloss_wave_red.png) repeat-x center !important;
border: 1px solid green;
color: #ffffff;
}
diff --git a/webif/html/db/index.jim b/webif/html/db/index.jim
index ae5fba9..45f6128 100755
--- a/webif/html/db/index.jim
+++ b/webif/html/db/index.jim
@@ -11,7 +11,6 @@ jscss script.js
set databases [glob /var/lib/humaxtv/*.db]
lappend databases {*}[glob /mod/etc/*.db]
lappend databases "/mnt/hd2/dms_cds.db"
-lappend databases "/mod/tmp/tvdb/series.db"
lappend databases {*}[glob /mod/var/tvdb/*.db]
header
diff --git a/webif/html/dedup/dedup b/webif/html/dedup/dedup
index 1f665de..550a05a 100755
--- a/webif/html/dedup/dedup
+++ b/webif/html/dedup/dedup
@@ -1,7 +1,7 @@
#!/mod/bin/jimsh
source /mod/webif/lib/setup
-require ts.class
+require ts.class settings.class
source /mod/webif/html/dedup/normalise.jim
source /mod/webif/html/dedup/process.jim
diff --git a/webif/html/dedup/process.jim b/webif/html/dedup/process.jim
index 92ee1c9..bffbc06 100755
--- a/webif/html/dedup/process.jim
+++ b/webif/html/dedup/process.jim
@@ -20,9 +20,21 @@ proc dedupprocess {file} {{seen {}}} {
set dir [file dirname $file]
set base [file tail [file rootname $file]]
- set syn [dedupnormalise [$ts get synopsis] [$ts get title]]
-# set epname [$ts episode_name]
-# set syn "[$ts epstr] - $epname"
+
+ set syn ""
+ if {[system has tvdb]} {
+ set epname [$ts episode_name]
+
+ if {[$ts get tvdb_method] ne "" && [$ts get episodenum] > 0} {
+ set syn "[$ts epstr] - $epname"
+ } else {
+ set syn $epname
+ }
+ }
+ if {$syn eq ""} {
+ set syn [dedupnormalise [$ts get synopsis] [$ts get title]]
+ }
+
# Escape special characters to create the filename.
set fn [system filename $syn]
@@ -32,7 +44,8 @@ proc dedupprocess {file} {{seen {}}} {
} elseif {$fn in $seen} {
set stat dup
} elseif {[string length $syn] > 40} {
- set stat error
+ set syn [string range $syn 0 39]
+ #set stat error
} elseif {$base eq $fn} {
set stat nothing
$ts set_deduped
diff --git a/webif/html/img/tvdb.png b/webif/html/img/tvdb.png
new file mode 100644
index 0000000..bb7713f
Binary files /dev/null and b/webif/html/img/tvdb.png differ
diff --git a/webif/html/settings/modules/general/settings.hook b/webif/html/settings/modules/general/settings.hook
index 4373290..b5895de 100755
--- a/webif/html/settings/modules/general/settings.hook
+++ b/webif/html/settings/modules/general/settings.hook
@@ -27,6 +27,7 @@ puts "
"
+setting_toggle "theTVDB.com integration?" "tvdb" $($tvdb)
setting_toggle "Slide-down toolbar?" "notoolbar" $(!$notoolbar) 1
setting_toggle "Mobile link on main page?" "nomobile" $(!$nomobile) 1
setting_toggle "Help links on main page?" "nohelplinks" $(!$nohelplinks) 1
diff --git a/webif/html/settings/settings.jim b/webif/html/settings/settings.jim
index 25ff514..d774063 100755
--- a/webif/html/settings/settings.jim
+++ b/webif/html/settings/settings.jim
@@ -38,6 +38,7 @@ set channel_group [$settings channel_group]
set epg_style [$settings epg_style]
set service_style [$settings service_style]
set notoolbar [$settings notoolbar]
+set tvdb [$settings tvdb]
set nomobile [$settings nomobile]
set nohelplinks [$settings nohelplinks]
set notwitfeed [$settings notwitfeed]
@@ -92,6 +93,7 @@ handle_int_update pkgdev $pkgdev "Development Package Display"
handle_int_update logsize $logsize "Log rotation size"
handle_int_update logkeep $logkeep "Logs to keep"
handle_int_update notoolbar $notoolbar "Disable toolbar"
+handle_int_update tvdb $tvdb "Enable tvdb"
handle_int_update nomobile $nomobile "Disable mobile link"
handle_int_update nohelplinks $nohelplinks "Disable help links"
handle_int_update notwitfeed $notwitfeed "Disable twitter feed ticker"
diff --git a/webif/lib/bin/tvdb b/webif/lib/bin/tvdb
index 2493d5f..f6f1ecc 100755
Binary files a/webif/lib/bin/tvdb and b/webif/lib/bin/tvdb differ
diff --git a/webif/lib/fileops b/webif/lib/fileops
index b8976c2..cc1f05c 100644
--- a/webif/lib/fileops
+++ b/webif/lib/fileops
@@ -80,6 +80,15 @@ proc {file read} {target {bytes 0}} {
error "Cannot read $target"
}
+proc {file write} {target content} {
+ if {[catch {set fd [open $target w]} msg]} {
+ error "Open failed, $msg"
+ } else {
+ $fd puts -nonewline $content
+ $fd close
+ }
+}
+
local proc file {cmd args} {
switch $cmd {
rename { tailcall {file rename} {*}$args }
@@ -87,6 +96,7 @@ local proc file {cmd args} {
touch { tailcall {file touch} {*}$args }
tdelete { tailcall {file tdelete} {*}$args }
read { tailcall {file read} {*}$args }
+ write { tailcall {file write} {*}$args }
default { tailcall upcall file $cmd {*}$args }
}
}
diff --git a/webif/lib/settings.class b/webif/lib/settings.class
index 8a4a1d0..68d2c8c 100644
--- a/webif/lib/settings.class
+++ b/webif/lib/settings.class
@@ -24,6 +24,7 @@ class settings {
smtp_server ""
pkgdev 0
notoolbar 0
+ tvdb 0
nomobile 0
nohelplinks 0
notwitfeed 0
@@ -168,6 +169,10 @@ settings method notoolbar {{val -1}} {
return [$self _nval_setting notoolbar $val]
}
+settings method tvdb {{val -1}} {
+ return [$self _nval_setting tvdb $val]
+}
+
settings method genrededup {{val -1}} {
return [$self _nval_setting genrededup $val]
}
diff --git a/webif/lib/system.class b/webif/lib/system.class
index 0267772..3b5ecd6 100644
--- a/webif/lib/system.class
+++ b/webif/lib/system.class
@@ -640,7 +640,8 @@ proc {system has} {comp} {
return 1
}
tvdb {
- return [file exists /mod/webif/.tvdb]
+ require settings.class
+ return [[settings] _nval_setting tvdb]
}
}
return 0
diff --git a/webif/lib/ts.class b/webif/lib/ts.class
index 290c341..ea03118 100644
--- a/webif/lib/ts.class
+++ b/webif/lib/ts.class
@@ -511,36 +511,57 @@ set ::ts::episode_prefixes {
{^t4: *}
{^brand new series *[-:]* *}
{^\.+}
+ { *\(Part [0-9] of [0-9]\) *}
+ {, Part [0-9]}
}
ts method tvdb_resolve {} {
# See if we can find a TVDB series for this recording.
- set tvdb_series [set v [tvdb series [$self series_name]]]
+ set dir [file dirname $file]
+
+ set seriesid 0
+ if {[file exists "$dir/.tvdbseriesid"]} {
+ set seriesid [string trim [file read "$dir/.tvdbseriesid"]]
+ } else {
+ return
+ }
+ if {!$seriesnum && [file exists "$dir/.tvdbseries"]} {
+ set seriesnum [string trim [file read "$dir/.tvdbseries"]]
+ }
+
+ set tvdb_series [set v [tvdb series [$self series_name] $seriesid]]
if {[$v get seriesid] == 0} { return }
# Got one.
+ # Easiest case - we can explicitly request the episode.
if {$seriesnum && $episodenum} {
- # Easiest case - we can explicitly request the episode.
set tvdb_method "series and episode number"
return [$v episodebynum $seriesnum $episodenum]
}
# Now try to find the episode using the current episode name
- set k [$v episodebyname $episodename]
+ # (using series or episode number if available)
+ set k [$v episodebyname $episodename $seriesnum $episodenum]
if {[llength $k]} {
set tvdb_method "episode name ($episodename)"
return $k
}
+ # More problematic but can at least narrow the list of candidates
+ # using the episode or series numbers if we have them.
+
if {$episodenum} {
- # More problematic but can at least narrow the list of
- # candidates.
set tvdb_method "episode number"
return [$v episodebyepnum $episodenum $synopsis]
}
+ if {$seriesnum} {
+ set tvdb_method "series and synopsis"
+ return [$v episodebyseries $seriesnum $synopsis]
+ }
+
# Most difficult - try and match based on synopsis alone
set tvdb_method "synopsis text"
return [$v episodebysynopsis $synopsis]
diff --git a/webif/lib/tvdb.class b/webif/lib/tvdb.class
index f46e1a7..760bf08 100644
--- a/webif/lib/tvdb.class
+++ b/webif/lib/tvdb.class
@@ -28,6 +28,7 @@ class tvdb {
name ""
overview ""
dat ""
+ banner ""
_matches {}
_smatches {}
@@ -40,6 +41,10 @@ proc ::tvdb::dlog {msg} {
}
}
+tvdb method setseries {sid} {
+ set seriesid $sid
+}
+
tvdb method _fetch {url} {
set f [socket stream $::tvdb::mirror:80]
$f puts -nonewline "GET /api/$url HTTP/1.0\r\n"
@@ -83,6 +88,97 @@ tvdb method _parse {xml vars {end "XXX"}} {
}
}
+#
+#261451
+#en
+#Teenage Mutant Ninja Turtles (2012)
+#graphical/261451-g2.jpg
+#Four ninja turtles, mutated by a mysterious alien substance, must rise up out of the sewers and defend their city against evil forces from both the past and present.
+#2012-09-29
+#Nickelodeon
+#261451
+#
+
+tvdb method _extract {xml end vars} {
+ set x [xml init $xml]
+ set cattr 0
+ set ret {}
+ set attrs {}
+ while {1} {
+ lassign [$x next] type val attr etype
+ if {$type == "EOF"} break
+ switch $etype {
+ START {
+ set cattr $val
+ }
+ END {
+ if {$val == $end} {
+ lappend ret $attrs
+ set attrs {}
+ }
+ set cattr 0
+ }
+ default {
+ if {$type == "TXT"} {
+ if {$cattr in $vars} {
+ set attrs([\
+ string tolower $cattr]) $val
+ }
+ }
+ }
+ }
+ }
+ return $ret
+}
+
+tvdb method fetchseries {} {
+ if {!$seriesid} return
+ set base "$::tvdb::cache/$seriesid"
+ # Expire old files
+ if {[file exists "$base.xml"]} {
+ set age $([clock seconds] - [file mtime "$base.xml"])
+ ::tvdb::dlog "$base.xml age $age"
+ if {$age > $::tvdb::cacheage} {
+ file delete "$base.xml"
+ ::tvdb::dlog "Expiring $base.xml"
+ }
+ }
+
+ if {![file exists "$base.xml"]} {
+ ::tvdb::dlog "Downloading"
+ # Download the series info
+ set f [open "$base.zip" w]
+ puts $f [$self _fetch \
+ "$::tvdb::apikey/series/$seriesid/all/en.zip"]
+ $f close
+ catch {exec unzip -o -q "$base.zip" en.xml -d $::tvdb::cache}
+ if {[file exists "$::tvdb::cache/en.xml"]} {
+ file rename "$::tvdb::cache/en.xml" $base.xml
+ # Extract episode info
+ puts [exec /mod/webif/lib/bin/tvdb "$base.xml"]
+ }
+ }
+}
+
+tvdb method loadseries {} {
+ if {!$seriesid} return
+ set ret [$::tvdb::indexdb query {
+ select * from series where series_id = %s} $seriesid]
+ if {[llength $ret] == 1} {
+ foreach {k v} [lindex $ret 0] {
+ set $k $v
+ }
+ }
+}
+
+tvdb method searchseries {series} {
+ ::tvdb::dlog "Searching TVDB for $series"
+ set seriesxml [$self _fetch \
+ "/GetSeries.php?seriesname=[cgi_quote_url $series]"]
+ return [$self _extract $seriesxml Series \
+ {seriesid SeriesName banner Overview}]
+}
+
tvdb method findseries {series} {
set ret ""
catch {
@@ -103,50 +199,11 @@ tvdb method findseries {series} {
$self _parse $seriesxml {seriesid} Series
}
- #puts "SERIESID: ($seriesid)"
-
if {!$seriesid} {
# Negative caching
$::tvdb::indexdb query {
replace into nseries values('%s')
} $series
- return;
- }
-
- # Found a series
-
- set base "$::tvdb::cache/$seriesid"
- # Expire old files
- if {[file exists "$base.xml"]} {
- set age $([clock seconds] - [file mtime "$base.xml"])
- ::tvdb::dlog "$base.xml age $age"
- if {$age > $::tvdb::cacheage} {
- file delete "$base.xml"
- ::tvdb::dlog "Expiring $base.xml"
- }
- }
-
- if {![file exists "$base.xml"]} {
- ::tvdb::dlog "Downloading"
- # Download the series info
- set f [open "$base.zip" w]
- puts $f [$self _fetch \
- "$::tvdb::apikey/series/$seriesid/all/en.zip"]
- $f close
- exec unzip -o -q "$base.zip" en.xml -d $::tvdb::cache
- if {[file exists "$::tvdb::cache/en.xml"]} {
- file rename "$::tvdb::cache/en.xml" $base.xml
- # Extract episode info
- puts [exec /mod/webif/lib/bin/tvdb "$base.xml"]
- }
- }
-
- set ret [$::tvdb::indexdb query {
- select * from series where series_id = %s} $seriesid]
- if {[llength $ret] == 1} {
- foreach {k v} [lindex $ret 0] {
- set $k $v
- }
}
}
@@ -172,12 +229,13 @@ tvdb method episodebynum {series episode} {
return {}
}
-tvdb method episodebyname {str} {
+tvdb method episodebyname {str {series 0} {episode 0}} {
if {![llength [set db [$self dbhandle]]]} return {}
- set ret [$db query {
- select * from episode where name like '%s'
- order by length(name)
- } [tvdb tolike $str]]
+ set q "select * from episode where name like '%s'"
+ if {$series} { append q " and series = $series" }
+ if {$episode} { append q " and episode = $episode" }
+ append q " order by length(name)"
+ set ret [$db query $q [tvdb tolike $str]]
if {[llength $ret]} { return [lindex $ret 0] }
return {}
}
@@ -239,14 +297,46 @@ tvdb method episodebyepnum {episode synopsis} {
return [$self seek $synopsis "and episode = $episode"]
}
+tvdb method episodebyseries {series synopsis} {
+ return [$self seek $synopsis "and series = $series"]
+}
+
tvdb method episodebysynopsis {synopsis} {
return [$self seek $synopsis]
}
-proc {tvdb series} {series} {
+tvdb method series_count {} {
+ if {![llength [set db [$self dbhandle]]]} { return 0 }
+
+ set ret [$db query {
+ select max(series) from episode
+ }]
+ set num 0
+ if {[llength $ret]} {
+ lassign [lindex $ret 0] x num
+ }
+ return $num
+}
+
+proc {tvdb series} {series {sid 0}} {
set t [tvdb]
- $t findseries $series
+ if {$sid} {
+ $t setseries $sid
+ } else {
+ $t findseries $series
+ }
+ if {[$t get seriesid] ne "0"} {
+ $t fetchseries
+ $t loadseries
+ if {[$t get name] eq ""} {
+ $t setseries 0
+ }
+ }
return $t
}
+proc {tvdb bannerurl} {banner} {
+ return "http://$::tvdb::mirror/banners/$banner"
+}
+