Skip to content

Commit

Permalink
Closes #26. Add YIFY Provider support.
Browse files Browse the repository at this point in the history
  • Loading branch information
Glavin001 committed Dec 26, 2014
1 parent 3950171 commit e6d5443
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 3 deletions.
1 change: 1 addition & 0 deletions server/bot/commands/searchForTorrents.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ module.exports = class SearchForTorrentsCommand extends Command
# console.log(query);
@torrentProvider.search query, {}, (err, results) =>
# console.log('searchForTorrents', err, results);
return callback(err, null) if err
# List the available Torrents
len = Math.min(@maxResults, results.length)
# Check if any torrents found
Expand Down
9 changes: 7 additions & 2 deletions server/providers/eztv.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,13 @@ module.exports = class EZTVProvider extends Provider
return eztvQuery(query, {
returnAll: true
}, (error, episodes) ->
# console.log(error, episodes)
return callback error, [] if error
# console.log("eztv", error, episodes)

# Mute errors:
# - EZTV goes down often
# - EZTV-Query errors undesirably
return callback null, [] if error

torrents = []
for episode in episodes
t = new Torrent \
Expand Down
4 changes: 4 additions & 0 deletions server/providers/index.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ async = require "async"
BaseProvider = require "./base"
Kickass = require "./kickass"
EZTV = require "./eztv"
YIFY = require "./yify"

module.exports = class Providers extends BaseProvider
allProviders: [
new EZTV()
new YIFY()
new Kickass()
]
search: (query, options, callback) ->
Expand All @@ -25,5 +27,7 @@ module.exports = class Providers extends BaseProvider
# console.log(tasks)
async.parallel tasks, (err, allResults) ->
# console.log "done", err, allResults
return callback err, [] if err
results = [].concat.apply([], allResults)
# console.log "results", results
return callback err, results
47 changes: 47 additions & 0 deletions server/providers/yify.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
Provider = require "./base"
Torrent = require "../torrent"
request = require "request"

module.exports = class YIFYProvider extends Provider
listUri: "https://yts.re/api/list.json"
sortBy: "seed"
limit: 20
search: (query, options, callback) ->
# See API docs: https://yts.re/api#listDocs
uri = "#{@listUri}?sort=#{@sortBy}&limit=#{@limit}&keywords=#{query}"
# Send request
request({
method: 'GET'
uri: uri
}, (err, response, body) =>
return callback(err, []) if err

# Parse body
data = JSON.parse(body)

# Check for failures
if data.status is "fail"
# Fail silently: likely because "No movies found"
return callback(null, [])

movieList = data.MovieList
torrents = []
for movie in movieList
t = new Torrent \
title: movie.MovieTitle,
torrentUrl: movie.TorrentUrl,
link: movie.MovieUrl,
verified: true,
seeders: movie.TorrentSeeds,
leechers: movie.TorrentPeers,
size: movie.SizeByte,
dateCreated: movie.DateUploaded,
hash: movie.TorrentHash,
category: "Movies",
meta: movie
torrents.push t

return callback null, torrents

)

5 changes: 4 additions & 1 deletion server/services/botService.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ module.exports = create: (data, params, callback) ->
meta: data
, (error, result) ->
if error
return callback null, "Please try again later. Error: #{error.message}"
message = "Please try again later. Error: #{error.message}"
response = response:
plain: message
return callback null, response
else
return callback null, result
return

0 comments on commit e6d5443

Please sign in to comment.