update tvdb support

git-svn-id: file:///root/webif/svn/pkg/webif/trunk@2494 2a923420-c742-0410-a762-8d5b09965624
This commit is contained in:
hummypkg 2015-10-12 21:14:34 +00:00
parent e7ca1d7742
commit 6b8933634b
24 changed files with 564 additions and 93 deletions

View File

@ -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)

View File

@ -361,7 +361,9 @@ puts {
<div id=dialogue>
<img src=/img/loading.gif>Retrieving data...
</div>
<div id=confirm title="Confirmation Required"></div>
<div id=pwdialogue style="display: none">
<center>
<img src=/img/loading.gif>

View File

@ -49,17 +49,22 @@ if {$type eq "ts"} {
</tr><tr>
"
if {[llength $sdata] && [llength $idata]} {
puts "</tr><tr><th class=blood>DEBUG</th><td class=footnote>
puts "</tr><tr><th class=blood>TVDB</th><td class=footnote>
<img class=collapser id=xtvdb x=tvdb_extra class=va
src=/img/tree/plusonly.png>
Found using [$ts get tvdb_method]
<br>
$idata(overview)
<br>
[$sdata get _phrases]
<br>
[lrange [$sdata get _smatches] 0 8]
</td></tr>"
<div id=tvdb_extra class=hidden>
$idata(overview)
</div>
</td></tr>"
}
# $idata(overview)
# <br>
# [$sdata get _phrases]
# <br>
# [lrange [$sdata get _smatches] 0 8]
if {[$ts flag "Guidance"] > 0} {
puts "
<th>Guidance</th>
@ -139,7 +144,8 @@ puts "
"
set fileset [$ts fileset]
puts -nonewline "<img id=xfileset class=va src=/img/tree/plusonly.png>"
puts -nonewline "<img class=collapser x=fileset id=xfileset class=va
src=/img/tree/plusonly.png>"
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 "</table>"
puts {
<script type=text/javascript>
$('#xfileset').click(function() {
$('#fileset').slideToggle('slow', function() {
if ($('#fileset').is(':visible'))
$('#xfileset').attr('src', '/img/tree/minustop.png');
$('.collapser').on('click', function() {
target = $(this).attr('x');
var $icon = $(this);
$('#' + target).slideToggle('slow', function() {
if ($(this).is(':visible'))
$icon.attr('src', '/img/tree/minustop.png');
else
$('#xfileset').attr('src', '/img/tree/plusonly.png');
$icon.attr('src', '/img/tree/plusonly.png');
});
});
</script>

View File

@ -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 "<span class=filesize id=dirsize></span>"
puts "</legend>"
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 ""} {

View File

@ -10,6 +10,15 @@ var plugins = {
var dir;
function blockpage(msg)
{
if (!msg)
msg = 'Refreshing page...';
$.blockUI({
message: '<h1><img src=/img/loading.gif> ' + msg + '</h1>'
});
}
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);
});
}

View File

@ -0,0 +1,57 @@
#!/mod/bin/jimsh
puts {
<div id=tvdbdialogue title="Select Series" class=hidden>
<table>
<tr>
<th>
<label for="tvdbsearch">
<b>Search For</b>
</label>
</th>
<td>
<input type=text name="tvdbsearch" id="tvdbsearch"
value="" size=70 maxlength=255
class="text ui-widget-content ui-corner-all">
</td>
</tr>
</table>
</div>
<div id=tvdbresults title="Choose Series" class=hidden>
<div class=tvdbresults id=tvdbresults_loading>
<img src=/img/loading.gif>
Searching theTVDB.com database, please wait...
</div>
<div class=tvdbresults id=tvdbresults_saving>
<img src=/img/loading.gif>
Retrieving episode details from theTVDB.com, please wait...
</div>
<div class=tvdbresults id=tvdbresults_force>
You can optionally force a particular series number for this folder.<br>
This is useful when the broadcasters do not set good synopses or<br>
if episode names are re-used across series. Leave it set to zero<br>
if you do not wish to do this.<br>
<table>
<tr>
<th>
Force series number:<br>
<span class=footnote>(Optional)</span>
</th>
<td>
<input id=tvdb_forceseries type=number value="" min=0>
</td>
</tr><tr>
<td></td>
<td>
<button id=tvdbresults_forcesave>Save</button>
</td>
</tr>
</table>
</div>
<div class=tvdbresults id=tvdbresults_inner></div>
</div>
}

View File

@ -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 "<div>"
if {[set banner [$v get banner]] ne ""} {
puts "
<img class=tvdbbannertop src=\"[tvdb bannerurl $banner]\">
"
}
puts "
<span id=tvdbseriesname title=\"Series ID: $seriesid\">
<a target=_blank href=\"/db/?db=$seriesid.db\">
[cgi_quote_html [$v get name]]
</a>
</span>
"
if {[file exists "$dir/.tvdbseries"]} {
set n [string trim [file read "$dir/.tvdbseries"]]
puts "(S$n)"
}
puts "<button id=tvdbsetseries>Change</button>"
puts "</div>"
} else {
puts {
<span id=tvdbinfo class="va right">
<img class=tvdblogo src=/img/tvdb.png>
<button id=tvdbsetseries>Select Series</button>
</span>
}
}

View File

@ -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');
}
}
]
});
});
});

View File

@ -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 "
<div>
<div class=tvdbseries>
<img class=tvdbbanner src=\"[tvdb bannerurl $series(banner)]\">
<span title=\"Series ID: $series(seriesid)\">
$series(seriesname)
</span>
<button class=tvdbselect sid=\"$series(seriesid)\">
Select
</button>
</div>
<div class=tvdbsynopsis>
$series(overview)
</div>
</div>
"
}

View File

@ -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]

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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

View File

@ -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

View File

@ -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

BIN
webif/html/img/tvdb.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.1 KiB

View File

@ -27,6 +27,7 @@ puts "
</tr>
"
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

View File

@ -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"

Binary file not shown.

View File

@ -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 }
}
}

View File

@ -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]
}

View File

@ -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

View File

@ -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]

View File

@ -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"}} {
}
}
#<Series>
#<seriesid>261451</seriesid>
#<language>en</language>
#<SeriesName>Teenage Mutant Ninja Turtles (2012)</SeriesName>
#<banner>graphical/261451-g2.jpg</banner>
#<Overview>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.</Overview>
#<FirstAired>2012-09-29</FirstAired>
#<Network>Nickelodeon</Network>
#<id>261451</id>
#</Series>
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"
}