This repository has been archived by the owner on Aug 9, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from boatrite/master
Fixed a bug and stuff
- Loading branch information
Showing
12 changed files
with
155 additions
and
136 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
rotten_pirate |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
2.0.0 |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,15 @@ | ||
source :rubygems | ||
source 'https://rubygems.org' | ||
|
||
group :test do | ||
gem 'rspec', '~>2.7' | ||
gem 'awesome_print' | ||
gem 'rspec', '~>2.7' | ||
gem 'awesome_print' | ||
end | ||
|
||
gem 'torrent_api', '0.2.7' | ||
gem 'sequel', '~>3.2' | ||
gem 'sqlite3', '~>1.3' | ||
gem 'whenever' | ||
gem 'sqlite3' | ||
gem 'i18n' | ||
gem 'rake' | ||
gem 'prowl' | ||
gem 'pry' |
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,56 @@ | ||
require 'sequel' | ||
require 'uri' | ||
|
||
class Download | ||
def self.connection | ||
Sequel.sqlite('db/downloads.sqlite') | ||
end | ||
|
||
def self.exists? name | ||
db = connection | ||
!!(db[:downloads].filter(:name => name).first) | ||
end | ||
|
||
def self.insert name | ||
db = connection | ||
db[:downloads].insert(:name => name) | ||
end | ||
|
||
def self.delete name | ||
connection[:downloads].filter(:name => name).delete | ||
end | ||
|
||
def self.clean_title movie_title | ||
movie_title.gsub(/-/, '') | ||
end | ||
|
||
def self.download_directory | ||
config = YAML.load(File.open('config/config.yml').read) | ||
config = YAML.load(File.open(File.dirname(__FILE__) + '/../config/config.yml').read) | ||
download_dir = config["download_directory"] || 'tmp/torrent' | ||
dirs = download_dir.strip.split('/') | ||
# This converts any relative home directories to one ruby likes better (osx only probably) | ||
dirs.map { |dir| dir == "~" ? Dir.home : dir } | ||
dirs.map { |dir| dir == "~" ? Dir.home : dir } | ||
end | ||
|
||
def self.torrent_from_url url | ||
require 'net/http' | ||
|
||
|
||
|
||
torrent_filename_match = url.match(/.*\/(.*)/) | ||
torrent_name = torrent_filename_match.nil? ? "tmp.torrent" : torrent_filename_match[1] | ||
torrent_domain, torrent_uri = url.gsub(/https?:\/\//, '').split('.se') | ||
torrent_uri = URI.escape(torrent_uri) | ||
torrent_domain += '.se' | ||
|
||
FileUtils.mkdir_p File.join(self.download_directory) | ||
filename = File.join(self.download_directory, torrent_name) | ||
Net::HTTP.start(torrent_domain) do |http| | ||
resp = http.get(torrent_uri) | ||
open(filename, "wb") { |file| file.write(resp.body) } | ||
Net::HTTP.start(torrent_domain) do |http| | ||
resp = http.get(torrent_uri) | ||
if resp.msg == 'OK' | ||
open(filename, "wb") { |file| file.write(resp.body) } | ||
else | ||
puts "HTTP Response not OK; was #{resp.msg}: #{resp.code}" | ||
nil | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.