Created
January 30, 2011 05:04
-
-
Save oleander/802558 to your computer and use it in GitHub Desktop.
A callback script for Transmission. Run the gem install on line 3 to get the dependencies. It downloads a subtitle for the movie and unpackes it, if necessary. Tested using Ruby 1.9.2 in OS X 10.6.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env /Users/linus/.rvm/bin/ruby-1.9.2-p136 | |
# encoding: UTF-8 | |
# gem install unpack ruby-growl movie_searcher undertexter | |
require 'rubygems' | |
require 'unpack' | |
require 'ruby-growl' | |
require 'movie_searcher' | |
require 'undertexter' | |
# Om inga parametrar skickades med så gör vi inget | |
abort if ENV['TR_TORRENT_DIR'].nil? or ENV['TR_TORRENT_NAME'].nil? | |
growl = Growl.new("localhost", "ruby-growl", ["ruby-growl Notification"]) | |
growl.notify("ruby-growl Notification", "Movish", "Vänta...") | |
# Hela länkvägen till filen som laddades hem | |
full_path = "#{ENV['TR_TORRENT_DIR']}/#{ENV['TR_TORRENT_NAME']}" | |
# Absoluta länk-vägen till filen/mappen | |
path = File.directory?(full_path) ? full_path : File.dirname(full_path) | |
# Titlen på den nerladdade filen/mappen | |
title = ENV['TR_TORRENT_NAME'] | |
# Packar upp filerna, såvida det var en mapp vi laddade hem | |
files = File.directory?(full_path) ? Unpack.runner!(full_path) : [] | |
# Meddelar användaren om att nerladdningen är uppackad, om något fanns att packa upp | |
growl.notify("ruby-growl Notification", "Uppackat!", title) if files.any? | |
# Hämtar filmen från IMDB | |
movie = MovieSearcher.find_by_download(full_path) | |
# Avbryter om vi inte hittade någon film | |
if movie.nil? | |
growl.notify("ruby-growl Notification", "Inget hittades", title); abort | |
end | |
# Hämtar undertexten | |
subtitle = Undertexter.find(movie.imdb_id).based_on(title) | |
# Avbryter om vi inte hittade någon undertext | |
if subtitle.nil? | |
growl.notify("ruby-growl Notification", "Ingen undertext hittades", movie.title); abort | |
end | |
# Laddar ner undertexten | |
file = subtitle.download! | |
# Packar upp undertexten och skickar och skickar innehållet till den nerladdade mappen | |
Unpack.it!(file: file, to: path) unless file.nil? | |
# Meddelar användaren att allt gick bra | |
growl.notify("ruby-growl Notification", "Undertext hittades", subtitle.title) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment