filebot/website/scripts/update-mes.groovy

39 lines
1.3 KiB
Groovy
Raw Normal View History

2012-12-07 10:04:29 +00:00
// filebot -script fn:update-mes "X:/path/to/episodes" --def login=user:pwd addshows=y tick=acquired
def mesacc = login.split(':')
def mesadd = tryQuietly{ addshows.toBoolean() }
def mesupdate = tryQuietly { tick } ?: 'acquired'
2013-04-16 17:30:51 +00:00
def mesvalue = tryQuietly { value } ?: '1'
2012-12-06 19:24:25 +00:00
2012-12-07 10:04:29 +00:00
// import myepisodes scraper
include('fn:lib/ws')
2012-12-06 19:24:25 +00:00
def mes = MyEpisodes(mesacc[0], mesacc[1])
def myshows = mes.getShowList()
2012-12-07 10:04:29 +00:00
// series name => series key (e.g. Doctor Who (2005) => doctorwho)
2013-04-16 17:30:51 +00:00
def collationKey = { s -> s == null ? '' : s.replaceAll(/^(?i)(The|A)\b/, '').replaceAll(/(?<!\d)\d{4}$/).replaceAll(/\W/).lower() }
2012-12-06 19:24:25 +00:00
2012-12-07 10:04:29 +00:00
args.getFiles{ it.isVideo() && parseEpisodeNumber(it) && detectSeriesName(it) }.groupBy{ detectSeriesName(it) }.each{ series, files ->
def show = myshows.find{ collationKey(it.name) == collationKey(series) }
if (show == null && mesadd) {
show = mes.getShows().find{ collationKey(it.name) == collationKey(series) }
if (show == null) {
println "[failure] '$series' not found"
return
2012-12-06 19:24:25 +00:00
}
2012-12-07 10:04:29 +00:00
mes.addShow(show.id)
println "[added] $show.name"
}
files.each{
if (show != null) {
2012-12-06 19:24:25 +00:00
def sxe = parseEpisodeNumber(it)
2013-04-16 17:30:51 +00:00
mes.update(show.id, sxe.season, sxe.episode, mesupdate, mesvalue)
2012-12-07 10:04:29 +00:00
println "[$mesupdate] $show.name $sxe [$it.name]"
} else {
println "[failure] '$series' has not been added [$it.name]"
2012-12-06 19:24:25 +00:00
}
}
}