Skip to content

Instantly share code, notes, and snippets.

@rkujawa
Last active August 29, 2015 14:07
Show Gist options
  • Save rkujawa/de50040caccc23e9ccfd to your computer and use it in GitHub Desktop.
Save rkujawa/de50040caccc23e9ccfd to your computer and use it in GitHub Desktop.
Download anime torrents via RSS
#!/usr/bin/env /opt/groovy/bin/groovy
import gstorm.*
/**
* ObtainAnimuTorrentViaRss
* @version 0.1
* @author rkujawa
*/
@GrabResolver(name='gstorm', root='http://dl.bintray.com/kdabir/maven')
@GrabConfig(systemClassLoader = true)
@Grab('gstorm:gstorm:0.7')
cli = new CliBuilder()
cli.with {
usage: 'Self'
u longOpt: 'url', 'RSS URL', args: 1
d longOpt: 'dir', 'Torrent files cache dir', args: 1
}
if(args.length == 0) {
cli.usage()
System.exit(1)
}
def opt = cli.parse(args)
def tmpdir = opt.d //"/tmp/baka/"
def rssurl = opt.u // "http://tokyotosho.info/rss.php?filter=1"
def rss = new XmlSlurper().parse(rssurl)
def g = new Gstorm()
g.setCsvFile(DownloadedTorrent, 'downloaded.csv;ignore_first=false')
g.stormify(DownloadedTorrent)
rss.channel.item.each {
println "${it.title}\t${it.link}"
def file = new File(tmpdir + it.title + '.torrent')
if(!file.exists()) {
def stream = file.newOutputStream()
try {
stream << new URL(it.link.toString()).openStream()
} catch (Exception e) {
e.printStackTrace()
}
def dlt = new DownloadedTorrent(url: it.link)
dlt.save()
stream.close()
}
}
@Csv
class DownloadedTorrent {
String url
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment