Skip to content

Instantly share code, notes, and snippets.

@pabloalba
Created January 12, 2013 19:53
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save pabloalba/4520199 to your computer and use it in GitHub Desktop.
Save pabloalba/4520199 to your computer and use it in GitHub Desktop.
Script para descargar automáticamente subtítulos de subtitulos.es. Hace un poco de web scraping para obtener el último subtítulo en inglés, que descarga con wget.
#!/usr/bin/groovy
//http://www.subtitulos.es/ajax_loadShow.php?show=1493&season=1
def shows = [
[id:1493, season:1, directory:"/media/data/Arrow"],
[id:382, season:4, directory:"/media/data/Modern.Family"]
]
def getSubtitleURL(feedUrl){
def data = new URL(feedUrl).getText()
int pos = data.lastIndexOf("English")
data = data.substring(pos)
pos = data.indexOf("<a") + 9
data = data.substring(pos)
pos = data.indexOf("\"")
data = data.substring(0,pos)
return data
}
def download(fileUrl, directory){
def proc = ['wget', '--content-disposition', '--referer="http://www.subtitulos.es"', '-nc', fileUrl].execute(null, new File(directory))
proc.waitFor()
}
def getSubtitle(show){
def url = "http://www.subtitulos.es/ajax_loadShow.php?show=${show.id}&season=${show.season}"
def fileUrl = getSubtitleURL(url)
download (fileUrl, show.directory)
}
//Main feature
//For each show, call to getSubtitle
shows.each{
getSubtitle(it)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment