2013-08-10 03:56:11 -04:00
|
|
|
|
import org.tukaani.xz.*
|
2013-08-10 01:23:14 -04:00
|
|
|
|
|
2013-11-20 05:07:25 -05:00
|
|
|
|
|
|
|
|
|
/* ------------------------------------------------------------------------- */
|
2013-08-10 01:23:14 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def sortRegexList(path) {
|
|
|
|
|
def set = new TreeSet(String.CASE_INSENSITIVE_ORDER)
|
|
|
|
|
new File(path).eachLine('UTF-8'){
|
|
|
|
|
// check if regex compiles
|
|
|
|
|
set += java.util.regex.Pattern.compile(it.trim()).pattern()
|
|
|
|
|
}
|
|
|
|
|
def out = set.join('\n').saveAs(path)
|
2013-11-21 11:31:09 -05:00
|
|
|
|
println "${out}\n${out.text}\n"
|
2013-08-10 01:23:14 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// sort and check shared regex collections
|
|
|
|
|
sortRegexList("website/data/release-groups.txt")
|
|
|
|
|
sortRegexList("website/data/query-blacklist.txt")
|
|
|
|
|
sortRegexList("website/data/exclude-blacklist.txt")
|
|
|
|
|
sortRegexList("website/data/series-mappings.txt")
|
|
|
|
|
|
|
|
|
|
|
2013-11-20 05:07:25 -05:00
|
|
|
|
/* ------------------------------------------------------------------------- */
|
2013-08-10 01:23:14 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def reviews = []
|
2013-11-20 05:07:25 -05:00
|
|
|
|
new File('reviews.csv').eachLine('UTF-8'){
|
|
|
|
|
def s = it.split(';', 3)
|
|
|
|
|
reviews << [user: s[0], date: s[1], text: s[2].replaceAll(/^\"|\"$/, '').replaceAll(/["]{2}/, '"') ]
|
|
|
|
|
}
|
2013-08-10 01:23:14 -04:00
|
|
|
|
reviews = reviews.sort{ it.date }
|
|
|
|
|
|
|
|
|
|
def json = new groovy.json.JsonBuilder()
|
|
|
|
|
json.call(reviews as List)
|
|
|
|
|
json.toPrettyString().saveAs('website/reviews.json')
|
|
|
|
|
println "Reviews: " + reviews.size()
|
|
|
|
|
|
|
|
|
|
|
2013-11-20 05:07:25 -05:00
|
|
|
|
/* ------------------------------------------------------------------------- */
|
2013-08-10 01:23:14 -04:00
|
|
|
|
|
|
|
|
|
|
2013-11-21 11:31:09 -05:00
|
|
|
|
def moviedb_out = new File("website/data/moviedb.txt")
|
2013-08-10 03:56:11 -04:00
|
|
|
|
def thetvdb_out = new File("website/data/thetvdb.txt")
|
|
|
|
|
def anidb_out = new File("website/data/anidb.txt")
|
2013-08-10 01:23:14 -04:00
|
|
|
|
|
2013-08-10 03:56:11 -04:00
|
|
|
|
def pack(file, lines) {
|
|
|
|
|
new File(file.parentFile, file.name + '.xz').withOutputStream{ out ->
|
|
|
|
|
new XZOutputStream(out, new LZMA2Options(LZMA2Options.PRESET_DEFAULT)).withWriter('UTF-8'){ writer ->
|
2013-08-10 01:23:14 -04:00
|
|
|
|
lines.each{ writer.append(it).append('\n') }
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2013-11-20 05:07:25 -05:00
|
|
|
|
/* ------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// BUILD moviedb index
|
2013-11-21 09:31:31 -05:00
|
|
|
|
def isValidMovieName(s) {
|
|
|
|
|
return s=~ /^[A-Z0-9]/ && s =~ /[\p{Alpha}]{3}/
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-06 18:22:31 -05:00
|
|
|
|
def getNamePermutations(names) {
|
|
|
|
|
def fn1 = { s -> s.replaceAll(/^(?i)(The|A)\s/, '') }
|
|
|
|
|
def fn2 = { s -> s.replaceAll(/\s&\s/, ' and ') }
|
|
|
|
|
def fn3 = { s -> s.replaceAll(/\([^\)]*\)$/, '') }
|
|
|
|
|
|
|
|
|
|
def out = new LinkedHashSet()
|
|
|
|
|
out += names*.trim()
|
|
|
|
|
[fn1, fn2, fn3].each{ fn ->
|
|
|
|
|
def results = out.findResults{ fn(it) }
|
|
|
|
|
out += results*.trim();
|
|
|
|
|
}
|
|
|
|
|
return out.unique{ it.toLowerCase().normalizePunctuation() }.findAll{ it.length() > 0 }
|
|
|
|
|
}
|
|
|
|
|
|
2013-11-20 05:07:25 -05:00
|
|
|
|
def treeSort(list, keyFunction) {
|
|
|
|
|
def sorter = new TreeMap(String.CASE_INSENSITIVE_ORDER)
|
|
|
|
|
list.each{
|
|
|
|
|
sorter.put(keyFunction(it), it)
|
|
|
|
|
}
|
|
|
|
|
return sorter.values()
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-10 01:23:14 -04:00
|
|
|
|
|
2013-11-21 09:31:31 -05:00
|
|
|
|
def omdb = []
|
2013-08-10 01:23:14 -04:00
|
|
|
|
new File('omdb.txt').eachLine('Windows-1252'){
|
|
|
|
|
def line = it.split(/\t/)
|
|
|
|
|
if (line.length > 11 && line[0] ==~ /\d+/) {
|
|
|
|
|
def imdbid = line[1].substring(2).toInteger()
|
2013-09-10 06:12:55 -04:00
|
|
|
|
def name = line[2].replaceAll(/\s+/, ' ').trim()
|
2013-08-10 01:23:14 -04:00
|
|
|
|
def year = line[3].toInteger()
|
|
|
|
|
def runtime = line[5]
|
|
|
|
|
def rating = tryQuietly{ line[11].toFloat() } ?: 0
|
|
|
|
|
def votes = tryQuietly{ line[12].replaceAll(/\D/, '').toInteger() } ?: 0
|
|
|
|
|
|
2013-09-10 06:12:55 -04:00
|
|
|
|
if ((year >= 1970 && (runtime =~ /h/ || votes >= 200) && rating >= 1 && votes >= 50) || (year >= 1950 && votes >= 5000)) {
|
2013-11-20 05:07:25 -05:00
|
|
|
|
omdb << [imdbid.pad(7), name, year]
|
2013-08-10 01:23:14 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-11-20 05:07:25 -05:00
|
|
|
|
omdb = omdb.findAll{ (it[0] as int) <= 9999999 && isValidMovieName(it[1]) }
|
|
|
|
|
|
2013-08-10 01:23:14 -04:00
|
|
|
|
|
2013-11-20 05:07:25 -05:00
|
|
|
|
def tmdb_txt = new File('tmdb.txt')
|
|
|
|
|
def tmdb_index = csv(tmdb_txt, '\t', 1, [0..-1])
|
2013-08-10 01:23:14 -04:00
|
|
|
|
|
2013-11-20 05:07:25 -05:00
|
|
|
|
def tmdb = omdb.findResults{ m ->
|
|
|
|
|
if (tmdb_index.containsKey(m[0])) {
|
|
|
|
|
return tmdb_index[m[0]]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
def sync = System.currentTimeMillis()
|
|
|
|
|
def row = [sync, m[0].pad(7), 0, m[2], m[1]]
|
|
|
|
|
try {
|
|
|
|
|
def info = net.sourceforge.filebot.WebServices.TMDb.getMovieInfo("tt${m[0]}", Locale.ENGLISH, false)
|
|
|
|
|
def names = [info.name, info.originalName, m[1]]
|
|
|
|
|
row = [sync, m[0].pad(7), info.id.pad(7), info.released?.year ?: m[2]] + names.findResults{ it ?: '' }
|
|
|
|
|
} catch(FileNotFoundException e) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
println row
|
|
|
|
|
tmdb_txt << row.join('\t') << '\n'
|
|
|
|
|
return row
|
|
|
|
|
}
|
2013-11-21 09:31:31 -05:00
|
|
|
|
tmdb*.join('\t').join('\n').saveAs(tmdb_txt)
|
2013-11-20 05:07:25 -05:00
|
|
|
|
|
|
|
|
|
movies = tmdb.findResults{
|
|
|
|
|
def ity = it[1..3] // imdb id, tmdb id, year
|
2014-01-06 18:22:31 -05:00
|
|
|
|
def names = getNamePermutations(it[4..-1]).findAll{ isValidMovieName(it) }
|
2013-11-21 11:31:09 -05:00
|
|
|
|
if (ity[0].toInteger() > 0 && ity[1].toInteger() > 0 && names.size() > 0)
|
2013-11-20 05:07:25 -05:00
|
|
|
|
return ity + names
|
|
|
|
|
else
|
|
|
|
|
return null
|
|
|
|
|
}
|
|
|
|
|
movies = treeSort(movies, { it[3, 2].join(' ') })
|
|
|
|
|
|
2013-11-21 11:31:09 -05:00
|
|
|
|
pack(moviedb_out, movies*.join('\t'))
|
2013-08-10 01:23:14 -04:00
|
|
|
|
println "Movie Count: " + movies.size()
|
|
|
|
|
|
|
|
|
|
// sanity check
|
2013-11-21 09:31:31 -05:00
|
|
|
|
if (movies.size() < 50000) { throw new Exception('Movie index sanity failed') }
|
2013-11-20 05:07:25 -05:00
|
|
|
|
|
2013-08-10 01:23:14 -04:00
|
|
|
|
|
2013-11-20 05:07:25 -05:00
|
|
|
|
/* ------------------------------------------------------------------------- */
|
2013-08-10 01:23:14 -04:00
|
|
|
|
|
2013-11-20 05:07:25 -05:00
|
|
|
|
|
|
|
|
|
// BUILD tvdb index
|
2013-08-10 01:23:14 -04:00
|
|
|
|
def tvdb_txt = new File('tvdb.txt')
|
2013-12-02 13:25:06 -05:00
|
|
|
|
def tvdb = [:]
|
2013-08-10 01:23:14 -04:00
|
|
|
|
new File('tvdb.txt').eachLine{
|
|
|
|
|
def line = it.split('\t', 5).toList()
|
|
|
|
|
tvdb.put(line[0] as Integer, [line[0] as Integer, line[1], line[2], line[3], line[4] as Integer])
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
def tvdb_updates = new File('updates_all.xml').text.xml.'**'.Series.findResults{ s -> tryQuietly{ [id:s.id.text() as Integer, time:s.time.text() as Integer] } }
|
|
|
|
|
tvdb_updates.each{ update ->
|
|
|
|
|
if (tvdb[update.id] == null || update.time > tvdb[update.id][4]) {
|
|
|
|
|
try {
|
|
|
|
|
retry(2, 500) {
|
|
|
|
|
def xml = new URL("http://thetvdb.com/api/BA864DEE427E384A/series/${update.id}/en.xml").fetch().text.xml
|
|
|
|
|
def imdbid = xml.'**'.IMDB_ID.text()
|
|
|
|
|
def tvdb_name = xml.'**'.SeriesName.text()
|
|
|
|
|
def imdb_name = _guarded{
|
|
|
|
|
if (imdbid =~ /tt(\d+)/) {
|
|
|
|
|
def dom = IMDb.parsePage(IMDb.getMoviePageLink(imdbid.match(/tt(\d+)/) as int).toURL())
|
|
|
|
|
return net.sourceforge.tuned.XPathUtilities.selectString("//META[@property='og:title']/@content", dom)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
def data = [update.id, imdbid ?: '', tvdb_name ?: '', imdb_name ?: '', update.time]
|
|
|
|
|
tvdb.put(update.id, data)
|
|
|
|
|
println "Update $update => $data"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch(Throwable e) {
|
|
|
|
|
def data = [update.id, '', '', '', update.time]
|
|
|
|
|
tvdb.put(update.id, data)
|
|
|
|
|
println "Update $update => $data"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-12-02 13:25:06 -05:00
|
|
|
|
|
|
|
|
|
// remove entries that have become invalid
|
|
|
|
|
def tvdb_ids = tvdb_updates.findResults{ it.id } as HashSet
|
|
|
|
|
tvdb.keySet().toList().each{ id ->
|
|
|
|
|
if (!tvdb_ids.contains(id)) {
|
|
|
|
|
println "Invalid ID found: ${tvdb[id]}"
|
|
|
|
|
tvdb.remove(id)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-10 01:23:14 -04:00
|
|
|
|
tvdb.values().findResults{ it.join('\t') }.join('\n').saveAs(tvdb_txt)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def thetvdb_index = []
|
2014-01-06 18:22:31 -05:00
|
|
|
|
tvdb.values().each{ r ->
|
|
|
|
|
def tvdb_name = r[2]
|
|
|
|
|
def imdb_name = r[3].replaceAll(/\([^\)]*\)$/, '').trim()
|
2013-12-14 05:49:16 -05:00
|
|
|
|
|
2014-01-06 18:22:31 -05:00
|
|
|
|
getNamePermutations([tvdb_name, imdb_name]).each{ n ->
|
|
|
|
|
thetvdb_index << [r[0], n]
|
2013-08-10 01:23:14 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-12-14 05:49:16 -05:00
|
|
|
|
def addSeriesAlias = { from, to ->
|
2013-12-29 03:06:22 -05:00
|
|
|
|
def se = thetvdb_index.find{ from == it[1] && !it.contains(to) }
|
2013-12-15 22:59:55 -05:00
|
|
|
|
if (se == null) throw new Exception("Unabled to find series '${from}'")
|
2014-01-06 18:22:31 -05:00
|
|
|
|
getNamePermutations([to]).each{ n ->
|
|
|
|
|
thetvdb_index << [se[0], n]
|
|
|
|
|
}
|
2013-12-14 05:49:16 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// additional custom mappings
|
2013-12-15 13:35:41 -05:00
|
|
|
|
addSeriesAlias('Law & Order: Special Victims Unit', 'Law & Order SVU')
|
2013-12-14 05:49:16 -05:00
|
|
|
|
addSeriesAlias('CSI: Crime Scene Investigation', 'CSI')
|
|
|
|
|
addSeriesAlias('M*A*S*H', 'MASH')
|
|
|
|
|
addSeriesAlias('M*A*S*H', 'M.A.S.H.')
|
|
|
|
|
addSeriesAlias('NCIS: Los Angeles', 'NCIS LA')
|
2013-12-15 22:59:55 -05:00
|
|
|
|
addSeriesAlias('How I Met Your Mother', 'HIMYM')
|
|
|
|
|
addSeriesAlias('Battlestar Galactica (2003)', 'BSG')
|
2013-12-14 05:49:16 -05:00
|
|
|
|
addSeriesAlias('World Series of Poker', 'WSOP')
|
2013-12-15 22:59:55 -05:00
|
|
|
|
addSeriesAlias('English Premier League', 'EPL')
|
|
|
|
|
addSeriesAlias('House of Cards', 'HOC')
|
2014-01-03 09:20:05 -05:00
|
|
|
|
addSeriesAlias('The Big Bang Theory', 'TBBT')
|
2013-12-14 05:49:16 -05:00
|
|
|
|
|
2013-08-10 01:23:14 -04:00
|
|
|
|
|
2013-09-16 00:18:11 -04:00
|
|
|
|
thetvdb_index = thetvdb_index.findResults{ [it[0] as Integer, it[1].replaceAll(/\s+/, ' ').trim()] }.findAll{ !(it[1] =~ /(?i:duplicate)/ || it[1] =~ /\d{6,}/ || it[1].startsWith('*') || it[1].endsWith('*') || it[1].length() < 2) }
|
2013-12-15 13:35:41 -05:00
|
|
|
|
thetvdb_index = thetvdb_index.sort({ a, b -> a[0] <=> b[0] } as Comparator)
|
2013-08-10 01:23:14 -04:00
|
|
|
|
|
|
|
|
|
// join and sort
|
2013-12-15 13:35:41 -05:00
|
|
|
|
def thetvdb_txt = thetvdb_index.groupBy{ it[0] }.findResults{ k, v -> ([k.pad(6)] + v*.getAt(1).unique{ it.toLowerCase() }).join('\t') }
|
|
|
|
|
|
2013-08-10 03:56:11 -04:00
|
|
|
|
pack(thetvdb_out, thetvdb_txt)
|
2013-08-10 01:23:14 -04:00
|
|
|
|
println "TheTVDB Index: " + thetvdb_txt.size()
|
|
|
|
|
|
|
|
|
|
// sanity check
|
|
|
|
|
if (thetvdb_txt.size() < 30000) { throw new Exception('TheTVDB index sanity failed') }
|
|
|
|
|
|
|
|
|
|
|
2013-11-20 05:07:25 -05:00
|
|
|
|
/* ------------------------------------------------------------------------- */
|
|
|
|
|
|
2013-08-10 01:23:14 -04:00
|
|
|
|
|
2013-11-20 05:07:25 -05:00
|
|
|
|
// BUILD anidb index
|
2013-12-27 17:49:56 -05:00
|
|
|
|
def anidb = new net.sourceforge.filebot.web.AnidbClient('filebot', 4).getAnimeTitles()
|
2013-08-10 01:23:14 -04:00
|
|
|
|
|
2013-09-07 11:48:24 -04:00
|
|
|
|
def anidb_index = anidb.findResults{
|
|
|
|
|
def row = []
|
|
|
|
|
row += it.getAnimeId().pad(5)
|
2013-12-29 03:06:22 -05:00
|
|
|
|
row += it.effectiveNames*.replaceAll(/\s+/, ' ')*.replaceAll(/['`´‘’ʻ]+/, /'/)*.trim().unique{ it.toLowerCase() }
|
2013-09-07 11:48:24 -04:00
|
|
|
|
return row
|
|
|
|
|
}
|
2013-08-10 01:23:14 -04:00
|
|
|
|
|
|
|
|
|
// join and sort
|
2013-09-07 11:48:24 -04:00
|
|
|
|
def anidb_txt = anidb_index.findResults{ row -> row.join('\t') }.sort().unique()
|
2013-08-10 03:56:11 -04:00
|
|
|
|
pack(anidb_out, anidb_txt)
|
2013-08-10 01:23:14 -04:00
|
|
|
|
println "AniDB Index: " + anidb_txt.size()
|
|
|
|
|
|
|
|
|
|
// sanity check
|
2013-12-27 17:49:56 -05:00
|
|
|
|
if (anidb_txt.size() < 8000) { throw new Exception('AniDB index sanity failed') }
|