* refactoring

This commit is contained in:
Reinhard Pointner 2011-11-30 05:23:43 +00:00
parent 549209ac9c
commit 2bf8270b17
3 changed files with 34 additions and 43 deletions

View File

@ -62,10 +62,6 @@ def execute(String... args) {
}
// Script helper
def require(cond) { if (!cond()) throw new Exception('Require failed') }
// CLI bindings
def rename(args) { args = _defaults(args)
_guarded { _cli.rename(_files(args), args.query, args.format, args.db, args.lang, args.strict) }

View File

@ -2,144 +2,127 @@
<media-types>
<!-- Application -->
<type name="application/torrent">
<extension>torrent</extension>
<extension>tor</extension>
</type>
<type name="application/list">
<extension>list</extension>
<extension>txt</extension>
</type>
<type name="application/nfo">
<extension>nfo</extension>
</type>
<!-- Verification -->
<type name="verification/sfv">
<extension>sfv</extension>
</type>
<type name="verification/md5sum">
<extension>md5</extension>
</type>
<type name="verification/sha1sum">
<extension>sha1</extension>
<extension>sha</extension>
</type>
<!-- Archives -->
<type name="archive/zip">
<extension>zip</extension>
</type>
<type name="archive/rar">
<extension>rar</extension>
</type>
<type name="archive/gzip">
<extension>gzip</extension>
<extension>gz</extension>
</type>
<type name="archive/tar">
<extension>tar</extension>
</type>
<!-- Audio -->
<type name="audio/mp3">
<extension>mp3</extension>
</type>
<type name="audio/mp4">
<extension>mp4</extension>
<extension>m4a</extension>
</type>
<type name="audio/flac">
<extension>flac</extension>
</type>
<type name="audio/wma">
<extension>wma</extension>
</type>
<type name="audio/ogg">
<extension>ogg</extension>
</type>
<!-- Video -->
<type name="video/avi">
<extension>avi</extension>
</type>
<type name="video/mkv">
<extension>mkv</extension>
</type>
<type name="video/ogm">
<extension>ogm</extension>
</type>
<type name="video/mp4">
<extension>mp4</extension>
<extension>m4v</extension>
</type>
<type name="video/mov">
<extension>mov</extension>
</type>
<type name="video/divx">
<extension>divx</extension>
</type>
<type name="video/mpeg">
<extension>mpg</extension>
<extension>mpeg</extension>
<extension>ts</extension>
</type>
<type name="video/wmv">
<extension>wmv</extension>
</type>
<type name="video/flash">
<extension>flv</extension>
</type>
<type name="video/realmedia">
<extension>rm</extension>
<extension>rmvb</extension>
</type>
<type name="video/tivo">
<extension>tivo</extension>
</type>
<type name="video/WindowsRecordedTV">
<extension>wtv</extension>
</type>
<!-- Subtitles -->
<type name="subtitle/SubRip">
<extension>srt</extension>
</type>
<type name="subtitle/MicroDVD">
<extension>sub</extension>
</type>
<type name="subtitle/SubViewer">
<extension>sub</extension>
</type>
<type name="subtitle/SubStationAlpha">
<extension>ssa</extension>
<extension>ass</extension>
</type>
<type name="subtitle/SAMI">
<extension>smi</extension>
<extension>sami</extension>
</type>
<type name="subtitle/VobSub">
<extension>sub</extension>
<extension>idx</extension>
</type>
</media-types>

View File

@ -5,18 +5,30 @@ def movieDir = "X:/in/Movies"
def episodeFormat = "X:/out/TV/{n}{'/Season '+s}/{episode}"
def movieFormat = "X:/out/Movies/{movie}/{movie}"
def exclude(f) { f =~ /\p{Punct}(chunk|part)/ }
def incomplete(f) { f =~ /[.]chunk|[.]part$/ }
// run cmdline unrar (require -trust-script)
[episodeDir, movieDir].getFiles().findAll{ !exclude(it) && it.hasExtension('rar') }.each {
execute("unrar", "x", "-y", it.getAbsolutePath(), it.getPathWithoutExtension() + "/")
// run cmdline unrar (require -trust-script) on multi-volume rar files (foo.part1.rar, foo.part2.rar, ...)
[episodeDir, movieDir].getFiles().findAll{ it =~ /[.]part01[.]rar$/ }.each { rarP1 ->
// extract name from name.part01.rar
def name = rarP1.getName()[0 .. -12];
// find all volumes of the same name
def volumes = rarP1.getParentFile().listFiles{ it.getName().startsWith(name) && it =~ /[.]part\d{2}[.]rar/ }
// find all incomplete volumes
def incomplete = volumes.findAll{ incomplete(it) }
// all volumes complete, call unrar on first volume
if (incomplete.isEmpty()) {
execute("unrar", "x", "-y", "-p-", rarP1.getAbsolutePath(), rarP1.getPathWithoutExtension() + "/")
}
}
/*
* Fetch subtitles and sort into folders
*/
episodeDir.eachMediaFolder() { dir ->
def files = dir.listFiles { !exclude(it) }
def files = dir.listFiles { !incomplete(it) }
// fetch subtitles
files += getSubtitles(file:files)
@ -26,7 +38,7 @@ episodeDir.eachMediaFolder() { dir ->
}
movieDir.eachMediaFolder() { dir ->
def files = dir.listFiles { !exclude(it) }
def files = dir.listFiles { !incomplete(it) }
// fetch subtitles
files += getSubtitles(file:files)