浏览代码

rtorrent - Add a torrent

Boulet 11 年之前
父节点
当前提交
53faa2038a
共有 1 个文件被更改,包括 20 次插入0 次删除
  1. 20 0
      lib/rSeed/server.rb

+ 20 - 0
lib/rSeed/server.rb

@@ -110,6 +110,10 @@ module RSeed
 
     # Add Torrent File
     # ----------------
+    get '/add' do
+      haml :add
+    end
+
     post '/add/:type' do
       case params[:type]
       when 'file'
@@ -122,6 +126,22 @@ module RSeed
         # TODO
       when 'magnet'
         # TODO
+      when 't411'
+        throw(:halt, [404, "Ya pas d'id wesh ...."]) if params['lien'] == nil
+        if(URI(params['lien']).host == "www.t411.me")
+          throw(:halt, [401, "Go conf user/password pour t411 !"]) if @config.get("t411_username") == nil or @config.get("t411_password") == nil
+          id = /\d+/.match(Nokogiri::HTML(open(params['lien'])).css("a.btn.call").first.values[0]).to_s
+          token = JSON.parse(RestClient.post "https://api.t411.me/auth", :username => @config.get("t411_username"), :password => @config.get("t411_password"))['token']
+          torrentName = JSON.parse(RestClient.get "https://api.t411.me/torrents/details/#{id}", {'Authorization' => token})['rewritename']
+          torrentFileContent = RestClient.get "https://api.t411.me/torrents/download/#{id}", {'Authorization' => token}
+          torrentFile = @config.get("data_path") + "/" + torrentName + ".torrent"
+          File.open(torrentFile, 'wb') {|f| f.write(torrentFileContent) }
+          @rtorrent.add(torrentFile)
+          return "Torrent ajouté !"
+        else
+          torrentFile = @config.get("data_path") + "/" + File.basename(params['lien'])
+          File.open(torrentFile, 'wb') {|f| f.write(open(params['lien']).read)}
+        end
       else
         404
       end