more tvdb work

git-svn-id: file:///root/webif/svn/pkg/webif/trunk@2542 2a923420-c742-0410-a762-8d5b09965624
This commit is contained in:
hummypkg 2015-11-18 23:46:47 +00:00
parent f34872a4c4
commit 5f04fbdf01
14 changed files with 429 additions and 72 deletions

View File

@ -1,10 +1,10 @@
Package: webif
Priority: optional
Section: web
Version: 1.2.5-6
Version: 1.2.5-7
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)
Depends: webif-channelicons(>=1.1.18),lighttpd(>=1.4.37-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.8),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)
Suggests:
Description: An evolving web interface for the Humax.
Tags: http://hummy.tv/forum/threads/6484/

15
webif/cgi-bin/tvdbimg.jim Executable file
View File

@ -0,0 +1,15 @@
#!/mod/bin/jimsh
package require cgi
source /mod/webif/lib/setup
require tvdb.class
set file [cgi_get file "-"]
if {$file eq "-"} { exit }
if {![file exists "$::tvdb::icache/$file"]} {
tvdb cachebanner $file
}
httpredirect "/cache/tvdb/img/$file"

View File

@ -21,7 +21,7 @@ if {$type eq "ts"} {
# Causes other series information to be automatically populated
set epname [$ts episode_name]
set series [$ts series_name]
set sdata [$ts get tvdb_series]
set tvdb [$ts get tvdb_series]
set idata [$ts get tvdb_data]
puts "
@ -48,19 +48,26 @@ if {$type eq "ts"} {
</tr><tr>
<th>Episode</th>
"
if {[llength $sdata]} {
set sid [$sdata get seriesid]
if {$sid} {
append series " / <a target=_blank href=[\
tvdb seriesurl $sid]><img height=20 src=/img/tvdb.png></a>"
append series " / <a href=/db/index.jim?db=$sid.db>DB:$sid</a>"
}
puts "<td>[$ts epstr] - $epname (<i>$series</i>)"
if {[llength $tvdb]} {
puts "<button class=tvdbchoose>Change</button>"
}
puts "<td>[$ts epstr] - $epname (<i>$series</i>)<td>
puts "</td>
</tr><tr>
"
if {[llength $sdata] && [llength $idata]} {
puts "</tr><tr><th>TheTVDB</th><td>
if {[llength $tvdb] && [llength $idata]} {
puts "</tr><tr><th>TheTVDB</th><td class=va>"
set sid [$tvdb get seriesid]
puts "<a target=_blank href=[\
tvdb seriesurl $sid]>View on
<img class=va height=20 src=/img/tvdb-sm.png></a>"
if {[[settings] tvdb_debug]} {
puts " | "
puts "<a href=/db/index.jim?db=$sid.db target=_blank>
<span class=footnote>View database($sid)</span></a>"
}
puts "
<br>
<img class=collapser id=xtvdb x=tvdb_extra
class=va src=/img/tree/plusonly.png>
Found episode using [$ts get tvdb_method]
@ -72,10 +79,10 @@ if {$type eq "ts"} {
if {[[settings] tvdb_debug]} {
puts "
<div class=bluefootnote>
[$sdata get _phrases]
[$tvdb get _phrases]
</div>
<div class=footnote>
[lrange [$sdata get _smatches] 0 8]
[lrange [$tvdb get _smatches] 0 8]
</div>
"
}
@ -199,8 +206,16 @@ if {[$ts get bookmarks]} {
puts "
</table>
"
puts {
puts "
<script type=text/javascript>
var file = '$file';
"
puts {
$('button').button();
$('.tvdbchoose').on('click', function() {
window.location.href = '/browse/tvdb/episode.jim?file=' +
encodeURIComponent(file);
});
$('.collapser').on('click', function() {
target = $(this).attr('x');
var $icon = $(this);

View File

@ -248,13 +248,7 @@ puts "
<legend style=\"font-size: 1.5em; padding: 0 0.5em 0.5em 0.5em;\">
"
# Breadcrumb path
set stub ""
foreach part [split $dir /] {
if {$stub eq "/"} { set name $part } else { set name "/$part" }
append stub $name
puts "<a href=\"$env(SCRIPT_NAME)?dir=[cgi_quote_url $stub]\">$name</a>"
}
browse breadcrumb $dir
puts "<span class=filesize id=dirsize></span>"
puts "</legend>"

View File

@ -2,8 +2,9 @@
require classdump
if {[file exists "$dir/.tvdbseriesid"]} {
set seriesid [string trim [file read "$dir/.tvdbseriesid"]]
set seriescount 0
foreach seriesid [ts serieslist $dir] {
incr seriescount
set tvdb_series [set v [tvdb series [file tail $dir] $seriesid]]
puts "<div class=tvdbbanner sid=$seriesid>"
if {[set banner [$v get banner]] ne ""} {
@ -24,7 +25,8 @@ if {[file exists "$dir/.tvdbseriesid"]} {
}
puts "<button id=tvdbsetseries>Change</button>"
puts "</div>"
} else {
}
if {!$seriescount} {
puts {
<span id=tvdbinfo class="va right">
<img class=tvdblogo src=/img/tvdb.png>

View File

@ -0,0 +1,123 @@
#!/mod/bin/jimsh
package require cgi
source /mod/webif/lib/setup
require settings.class ts.class tvdb.class browse.class
jqplugin highlight tablesorter2
header
set file [cgi_get file -]
if {$file eq "-"} exit
puts "
<script type=text/javascript>
var file = '$file';
var dir = '[file dirname $file]';
</script>
"
jscss episode.js
set search [cgi_get search ""]
if {[catch {set ts [ts fetch $file]}] || $ts eq "0"} {
puts "Unable to load recording data."
exit
}
# Causes other series information to be automatically populated
$ts clearepdata
set epname [$ts episode_name]
set series [$ts series_name]
set tvdb [$ts get tvdb_series]
set idata [$ts get tvdb_data]
browse breadcrumb [file dirname $file]
puts "
<fieldset>
<legend>Episode Search</legend>
Search for:
<input id=searchterm name=search value=\"$search\">
<button id=tvdbepsearch>Search</button>
</fieldset>
<div>
<table class=keyval>
<tr>
<th>Title</th>
<td>[$ts get title]</td>
</tr><tr>
<th>File</th>
<td>[$ts get file]</td>
</tr><tr>
<th>Detected&nbsp;Episode</th>
<td>[$ts epstr] - $epname (<i>$series</i>)</td>
</tr><tr>
<th>Found&nbsp;Using</th>
<td>[$ts get tvdb_method]</td>
</tr><tr>
<th>Synopsis</th>
<td class=synopsis>[$ts get synopsis]</td>
</tr>
</table>
</div>
"
if {$search ne ""} {
set matches [lmap i [$tvdb episodesearch $search] {
lassign $i x id
list $id 0
}]
} else {
set matches [$tvdb get _smatches]
}
if {![llength $matches]} {
exit
}
puts "
<div>
<table class=\"results keyval borders\">
<thead>
<tr>
<th data-sorter=false></th>
<th>Score</th>
<th>Ep.</th>
<th>Name</th>
<th data-sorter=false>Synopsis</th>
</tr>
</thead>
<tbody>
"
foreach match $matches {
lassign $match episode_id score
set ep [$tvdb episodebyid $episode_id]
if {![llength $ep]} continue
puts "<tr sid=$episode_id s=$ep(series) e=$ep(episode)><td>"
if {[dict exists $ep thumb]} {
puts "<img width=200 src=\"[tvdb bannerurl $ep(thumb)]\">"
}
puts "</td>
<td>$score</td>
<td>s$ep(series)e$ep(episode)</td>
<td> $ep(name)
<br>
<button class=select eid=$episode_id>Select</button>
</td>
<td>$ep(overview)</td>
</tr>
"
}
puts "
</tbody>
</table>
</div>
"

View File

@ -0,0 +1,42 @@
$(function() {
var synopsis = $('.synopsis').text();
var words = synopsis.split(" ");
for (var i = 0;i < words.length - 1; i++)
{
var word = words[i];
if (word.length > 4)
$('table.results').highlight(words[i]);
}
$('button.select').button().on('click', function() {
$tr = $(this).closest('tr');
$.get('select.jim', {
file: file,
episode: $tr.attr('sid'),
s: $tr.attr('s'),
e: $tr.attr('e')
}, function() {
window.location.href = '/browse/?dir=' +
encodeURIComponent(dir);
});
});
$('#tvdbepsearch').button({icons:{primary:"ui-icon-search"}})
.on('click', function() {
window.location.href = 'episode.jim?file=' +
encodeURIComponent(file) + '&search=' +
encodeURIComponent($('#searchterm').val());
});
$('table.results')
.tablesorter({
theme: 'webif',
widthFixed: false,
sortList: [[1,1]],
widgets: ['zebra', 'stickyHeaders']
});
});

View File

@ -16,7 +16,15 @@ if {[llength $slist]} {
<div>
<div class=tvdbseries>
<a target=_blank href=[tvdb seriesurl $series(seriesid)]>
"
if {[dict exists $series banner]} {
puts "
<img class=tvdbbanner src=\"[tvdb bannerurl $series(banner)]\">
"
} else {
puts "View on TheTVDB"
}
puts "
</a>
<span title=\"Series ID: $series(seriesid)\">
$series(seriesname)

View File

@ -0,0 +1,22 @@
#!/mod/bin/jimsh
package require cgi
source /mod/webif/lib/setup
require tvdb.class ts.class
set file [cgi_get file -]
set episode [cgi_get episode -]
set s [cgi_get s -]
set e [cgi_get e -]
httpheader
if {$file eq "-" || $episode eq "-"} exit
if {[catch {set ts [ts fetch $file]}] || $ts eq "0"} {
puts "Unable to load recording data."
exit
}
$ts storeepisode [list $s $e 0]

View File

@ -3,6 +3,7 @@ require system.class plugin
if {![exists -proc class]} { package require oo }
class dir {}
class browse {}
proc _addicon {img {hover ""} {class va}} {
set icon "<img src=$img class=\"$class\" height=21"
@ -168,3 +169,13 @@ proc {ts iconset} {ts} {
return [list $icons $attrs]
}
# Breadcrumb path
proc {browse breadcrumb} {dir} {
set stub ""
foreach part [split $dir /] {
if {$stub eq "/"} { set name $part } else { set name "/$part" }
append stub $name
puts "<a href=\"/browse/?dir=[cgi_quote_url $stub]\">$name</a>"
}
}

View File

@ -9,6 +9,13 @@ if {![exists -proc require]} {
}
}
proc httpredirect {url} {
puts -nonewline "Location: $url\r\n"
puts -nonewline "\r\n"
puts "Redirecting to $url"
exit
}
proc httpheader {{type "text/html"} {cache 0} {extra ""}} {{done 0}} {
if {$done} return
if {!$cache} {

View File

@ -128,6 +128,7 @@ proc {system kernelver} {} {{ver ""}} {
"Feb 7 14:15:02 KST 2014" { format "HDR_1.03.12" }
"May 19 22:39:27 BST 2014" { format "HDR_CFW_3.00" }
"Feb 19 20:58:57 GMT 2015" { format "HDR_CFW_3.03" }
"Nov 18 19:16:42 GMT 2015" { format "HDR_CFW_3.10" }
# HD
"Oct 11 21:14:31 KST 2010" { format "HD_1.01.12" }

View File

@ -27,6 +27,7 @@ class ts {
status ""
series ""
seriescached 1
seriesnum 0
episodenum 0
episodetot 0
@ -60,7 +61,7 @@ ts method _parse {line} {
lassign [split $line "\t"] \
title synopsis definition channel_num channel_name \
start end flags_list guidance bookmarks schedstart scheddur \
genre resume status
genre resume status seriesnum episodenum episodetot
set flags [split [string range $flags_list 0 end-1] ,]
}
@ -83,6 +84,21 @@ ts method setbookmarks {marks} {
exec /mod/bin/hmt +setbookmarks=[join $marks :] $file
}
ts method storeepisode {{data {}}} {
if {[llength $data]} {
set d [join $data ","]
} else {
set d "$seriesnum,$episodenum,$episodetot"
}
exec /mod/bin/hmt +setseries=$d $file
}
ts method clearepdata {} {
set seriesnum 0
set episodenum 0
set episodetot 0
}
ts method flag {f} {
if {$f in $flags} {return 1} else {return 0}
}
@ -520,14 +536,18 @@ ts method _tvdb_resolve {seriesid} {
set dir [file dirname $file]
set tvdb_series [set v [tvdb series [$self series_name] $seriesid]]
set tvdb_series [set v [tvdb series "" $seriesid]]
if {[$v get seriesid] == 0} { return }
# Got one.
# Easiest case - we can explicitly request the episode.
if {$seriesnum && $episodenum} {
set tvdb_method "series and episode number"
if {$seriescached} {
set tvdb_method "cached values"
} else {
set tvdb_method "series and episode number"
}
return [$v episodebynum $seriesnum $episodenum]
}
@ -557,34 +577,15 @@ ts method _tvdb_resolve {seriesid} {
return [$v episodebysynopsis $synopsis]
}
ts method episode_name {} {
set s $synopsis
proc {ts serieslist} {dir} {
set idfile "$dir/.tvdbseriesid"
if {![file exists $idfile]} { return {} }
return [lmap i [split [file read $idfile] "\n"] {
string trim $i
}]
}
######################################################################
# Attempt to determine the episode name from the synopsis
# Strip common prefixes
foreach prefix $::ts::episode_prefixes {
regsub -nocase -all -- $prefix $s "" s
}
# Strip anything following a colon.
regsub -all -- { *[:].*$} $s "" s
# If the resulting string is longer than 40 characters then
# split around . and take the left hand side if appropriate.
if {[string length $s] > 40} {
lassign [split $s "."] v w
set s $v
if {[string length $s] < 6 && [string length $w] < 6} {
append s "_$w"
}
}
# Shorten if too long.
if {[string length $s] > 40} { set s [string range $s 0 39] }
set episodename $s
ts method extract_numbers {} {
######################################################################
# Check for embedded Series/Episode number.
@ -625,6 +626,42 @@ ts method episode_name {} {
}
}
}
ts method episode_name {} {
set s $synopsis
######################################################################
# Attempt to determine the episode name from the synopsis
# Strip common prefixes
foreach prefix $::ts::episode_prefixes {
regsub -nocase -all -- $prefix $s "" s
}
# Strip anything following a colon.
regsub -all -- { *[:].*$} $s "" s
# If the resulting string is longer than 40 characters then
# split around . and take the left hand side if appropriate.
if {[string length $s] > 40} {
lassign [split $s "."] v w
set s $v
if {[string length $s] < 6 && [string length $w] < 6} {
append s "_$w"
}
}
# Shorten if too long.
if {[string length $s] > 40} { set s [string range $s 0 39] }
set episodename $s
if {$episodenum == 0} {
$self extract_numbers
set seriescached 0
}
# Now see if TVDB has anything to add
set fbase "[file dirname $file]/.tvdb"
@ -636,12 +673,20 @@ ts method episode_name {} {
if {!$seriesnum && [file exists "${fbase}series"]} {
set seriesnum [string trim [file read "${fbase}series"]]
}
foreach seriesid [\
string trim [split [file read "${fbase}seriesid"] "\n"]] {
foreach seriesid [ts serieslist [$self dir]] {
set tvdb_data [$self _tvdb_resolve $seriesid]
if {![dict exists $tvdb_data name]} continue
if {!$seriesnum} { set seriesnum $tvdb_data(series) }
if {!$episodenum} { set episodenum $tvdb_data(episode) }
set flag 0
if {!$seriesnum} {
set seriesnum $tvdb_data(series)
incr flag
}
if {!$episodenum} {
set episodenum $tvdb_data(episode)
incr flag
}
if {$flag} { $self storeepisode }
return $tvdb_data(name)
}

View File

@ -3,11 +3,12 @@ source /mod/webif/lib/setup
package require cgi
if {![exists -proc class]} { package require oo }
if {![exists -proc sqlite3.open]} { package require sqlite3 }
require xml.class
require system.class xml.class
set ::tvdb::apikey 1764335F804A5A91
set ::tvdb::mirror "thetvdb.com"
set ::tvdb::cache "/mod/var/tvdb"
set ::tvdb::icache "/mod/webif/cache/tvdb/img"
set ::tvdb::cacheage 86400
set ::tvdb::debug 0
@ -15,7 +16,12 @@ if {![file isdirectory $::tvdb::cache]} {
file mkdir $::tvdb::cache
}
if {![file isdirectory $::tvdb::icache]} {
system mkdir_p $::tvdb::icache
}
set ::tvdb::indexdb [sqlite3.open "$::tvdb::cache/series.db"]
$::tvdb::indexdb query {
create table if not exists nseries(
[name] text primary key
@ -46,8 +52,8 @@ tvdb method setseries {sid} {
}
tvdb method _fetch {url} {
set f [socket stream $::tvdb::mirror:80]
$f puts -nonewline "GET /api/$url HTTP/1.0\r\n"
set f [socket stream "${::tvdb::mirror}:80"]
$f puts -nonewline "GET $url HTTP/1.0\r\n"
$f puts -nonewline "Host: $::tvdb::mirror\r\n"
$f puts -nonewline "Connection: close\r\n"
$f puts -nonewline "\r\n"
@ -149,7 +155,7 @@ tvdb method fetchseries {} {
# Download the series info
set f [open "$base.zip" w]
puts $f [$self _fetch \
"$::tvdb::apikey/series/$seriesid/all/en.zip"]
"/api/$::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"]} {
@ -174,7 +180,7 @@ tvdb method loadseries {} {
tvdb method searchseries {series} {
::tvdb::dlog "Searching TVDB for $series"
set seriesxml [$self _fetch \
"/GetSeries.php?seriesname=[cgi_quote_url $series]"]
"/api/GetSeries.php?seriesname=[cgi_quote_url $series]"]
return [$self _extract $seriesxml Series \
{seriesid SeriesName banner Overview}]
}
@ -195,7 +201,7 @@ tvdb method findseries {series} {
::tvdb::dlog "Trying to find series in TVDB"
set seriesxml [$self _fetch \
"/GetSeries.php?seriesname=[cgi_quote_url $series]"]
"/api/GetSeries.php?seriesname=[cgi_quote_url $series]"]
$self _parse $seriesxml {seriesid} Series
}
@ -260,17 +266,28 @@ tvdb method wordcount {db words extra} {
#puts "Phrase: $w<br>"
set ret [$db query {
select episode_id from episode
select episode_id,
case
when name like '%%%s%%' then 1
else 0
end as inname
from episode
where overview like '%%%s%%'
or name like '%%%s%%'
%s
} $w $w $extra]
} $w $w $w $extra]
foreach row $ret {
#puts "&nbsp;&nbsp;> FOUND: ($w)<br>"
ladd _phrases $w
lassign $row x id
# Score is twice phrase length
incr _matches($id) $($i * 2)
lassign $row x id x inname
if {$inname eq "1"} {
# If found in name then score is 10x
# phrase length
incr _matches($id) $($i * 10)
} else {
# Score is twice phrase length
incr _matches($id) $($i * 2)
}
}
}
}
@ -304,6 +321,15 @@ tvdb method seek {synopsis {extra ""}} {
return {}
}
tvdb method episodebyid {episode_id} {
if {![llength [set db [$self dbhandle]]]} return {}
set ret [$db query {
select * from episode where episode_id = %s
} $episode_id]
if {[llength $ret]} { return [lindex $ret 0] }
return {}
}
tvdb method episodebyepnum {episode synopsis} {
return [$self seek $synopsis "and episode = $episode"]
}
@ -316,6 +342,21 @@ tvdb method episodebysynopsis {synopsis} {
return [$self seek $synopsis]
}
tvdb method episodesearch {search} {
if {![llength [set db [$self dbhandle]]]} return {}
set ret [$db query {
select episode_id,
case
when name like '%%%s%%' then 1
else 0
end as inname
from episode
where overview like '%%%s%%'
or name like '%%%s%%'
} $search $search $search]
return $ret
}
tvdb method series_count {} {
if {![llength [set db [$self dbhandle]]]} { return 0 }
@ -347,8 +388,39 @@ proc {tvdb series} {series {sid 0}} {
return $t
}
proc {tvdb fetchfile} {url} {
set f [socket stream "${::tvdb::mirror}:80"]
$f puts -nonewline "GET $url HTTP/1.0\r\n"
$f puts -nonewline "Host: $::tvdb::mirror\r\n"
$f puts -nonewline "Connection: close\r\n"
$f puts -nonewline "\r\n"
# Skip headers in the response.
set line [string trim [$f gets]]
while {[string length $line]} {
#puts "Web Header: $line"
set line [string trim [$f gets]]
}
# Save the body
set ret [$f read]
$f close
return $ret
}
proc {tvdb cachebanner} {banner} {
if {![file exists "$::tvdb::icache/$banner"]} {
set ret [tvdb fetchfile \
"http://$::tvdb::mirror/banners/$banner"]
if {[string length $ret] > 50} {
system mkdir_p "$::tvdb::icache/[file dirname $banner]"
file write "$::tvdb::icache/$banner" $ret
}
}
}
proc {tvdb bannerurl} {banner} {
return "http://$::tvdb::mirror/banners/$banner"
return "/cgi-bin/tvdbimg.jim?file=[cgi_quote_url $banner]"
}
proc {tvdb seriesurl} {seriesid} {