lixian115 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 4e20cf9c1721d23641f109a9091127eb2fe2347a
4
+ data.tar.gz: 128116e42d95b838bd8f230367661832d95b687f
5
+ SHA512:
6
+ metadata.gz: 7feffbabfc177b1636d2ed5c2f89fd54e1c70e96ef27b1e7af9eed71b38323f27158415a8e6923723122ff0d6e3f217e6bf71da047f1fd31ea48f9d689f63ab4
7
+ data.tar.gz: 375e609151b6d4472d5966ba819dd8b3d14a1c0026da94b5b18184675c4ee8b80efd7416ae09a74fc1fab2871c0f31af7099de6908c46f9aa04b4449d6f00775
@@ -0,0 +1,17 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
15
+ *.swp
16
+ *~
17
+ *.gem
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'lixian115'
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2016 aiyanxu
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,31 @@
1
+ # Lixian115
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'lixian115'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install lixian115
20
+
21
+ ## Usage
22
+
23
+ TODO: Write usage instructions here
24
+
25
+ ## Contributing
26
+
27
+ 1. Fork it ( https://github.com/[my-github-username]/lixian115/fork )
28
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
29
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
30
+ 4. Push to the branch (`git push origin my-new-feature`)
31
+ 5. Create a new Pull Request
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,3 @@
1
+ require 'lixian115'
2
+
3
+ Lixian115::App.start ARGV
@@ -0,0 +1,28 @@
1
+ require 'restclient'
2
+
3
+ class Http_request
4
+ attr_accessor :cookies
5
+
6
+ def initialize()
7
+ @cookies = {}
8
+ end
9
+
10
+ def post(url,data=nil)
11
+ res = RestClient.post(url,data,cookies: @cookies,user_agent: "Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/27.0.1453.94 Safari/537.36")
12
+ @cookies = @cookies.merge(res.cookies)
13
+ return res
14
+ end
15
+
16
+ def get(url)
17
+ res = RestClient.get(url,cookies: @cookies,user_agent: "Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/27.0.1453.94 Safari/537.36")
18
+ @cookies = @cookies.merge(res.cookies)
19
+ return res
20
+ end
21
+
22
+ def upload(url,files)
23
+ res = RestClient.post(url,files,:user_agent => "Shockwave Flash")
24
+ @cookies = @cookies.merge(res.cookies)
25
+ return res
26
+ end
27
+ end
28
+
@@ -0,0 +1,204 @@
1
+ require 'uri'
2
+ require 'http_request.rb'
3
+ require 'json'
4
+ require 'pathname'
5
+
6
+
7
+ BT_API_URL = 'http://btapi.115.com'
8
+ UPLOAD_URL = 'http://upload.115.com'
9
+ BASE_URL = 'http://115.com'
10
+ PASSPORT_URL = 'http://passport.115.com'
11
+ WEB_API_URL = 'http://web.api.115.com'
12
+
13
+ class Lixian
14
+ attr_accessor :http, :time, :sign, :tasks
15
+
16
+ def initialize
17
+ @http = Http_request.new
18
+ end
19
+
20
+ def get_sign
21
+ get_url = BASE_URL + '/?ct=offline&ac=space&_=' + "%10.2f" % Time.now.to_f
22
+ ret = @http.get(get_url)
23
+ unless ret.code == 200
24
+ puts "get_sign失败:请求失败"
25
+ return
26
+ end
27
+ ret = JSON.parse(ret.to_str)
28
+ if ret['err_msg']
29
+ puts "get_sign失败: #{ret['err_msg']}"
30
+ return
31
+ else
32
+ @sign = ret['sign']
33
+ @time = ret['time']
34
+ end
35
+ end
36
+
37
+ def get_lixian_tasks_list
38
+ self.get_sign
39
+ tasks = []
40
+ post_url = BASE_URL + '/web/lixian/?ct=lixian&ac=task_lists'
41
+ current_page = 1
42
+ page_count = 1
43
+ while current_page <= page_count
44
+ data = {'page' => current_page, 'uid' => @http.cookies['UID'].split('_').first, 'sign' => self.sign, 'time' => self.time}
45
+ ret = @http.post(post_url, data)
46
+ unless ret.code == 200
47
+ self.tasks = nil
48
+ puts "获取列表失败:请求失败"
49
+ return
50
+ end
51
+ ret = JSON.parse(ret.to_str)
52
+ if ret['page_count']
53
+ page_count = ret['page_count']
54
+ end
55
+ ret['tasks'].each{|x| tasks << x} if ret['tasks']
56
+ current_page += 1
57
+ end
58
+ @tasks = tasks
59
+ end
60
+
61
+ def upload_torrent(torrent_file_path)
62
+ self.get_sign
63
+ ret = @http.get(BASE_URL + "/?ct=lixian&ac=get_id&torrent=1&_=" + @time.to_s)
64
+ ret = JSON.parse(ret.to_str)
65
+ cid = ret['cid']
66
+ #puts cid
67
+ ret = @http.get(BASE_URL + "/?tab=offline&mode=wangpan")
68
+ reg = /upload\?(\S+?)"/
69
+ ids = reg.match(ret.to_str)
70
+ unless ids
71
+ puts "没有找到上传入口"
72
+ return false
73
+ end
74
+ url = 'http://upload.115.com/upload?' + ids[0].chomp("\"")
75
+ torrent_file_name = Pathname.new(torrent_file_path).basename
76
+ post_url = url
77
+ params = {'Filename' => torrent_file_name, 'target' =>'U_1_' + cid,
78
+ 'Filedata' => open(torrent_file_path,'rb'),
79
+ 'Upload' =>'Submit Query'}
80
+ ret = @http.upload(post_url, params)
81
+ ret = JSON.parse(ret.to_str)
82
+ unless ret['state']
83
+ puts "上传种子step.3出错: #{ret}"
84
+ return false
85
+ end
86
+ url = WEB_API_URL + '/files/file'
87
+ data = {'file_id' => ret['data']['file_id']}
88
+ ret = @http.post(url, data)
89
+ ret = JSON.parse(ret.to_str)
90
+ unless ret['state']
91
+ puts "上传种子step.4出错: #{ret}"
92
+ return false
93
+ end
94
+ post_url = BASE_URL + '/web/lixian/?ct=lixian&ac=torrent'
95
+ data = {'pickcode' => ret['data'][0]['pick_code'],
96
+ 'sha1' => ret['data'][0]['sha1'],
97
+ 'uid' => @http.cookies['UID'].split('_').first,
98
+ 'sign' => self.sign,
99
+ 'time' => self.time}
100
+ ret = @http.post(post_url,data)
101
+ ret = JSON.parse(ret.to_str)
102
+ unless ret['state']
103
+ puts "上传种子step.5出错: #{ret}"
104
+ return false
105
+ end
106
+ wanted = nil
107
+ idx = 0
108
+ ret['torrent_filelist_web'].each do |item|
109
+ if item['wanted'] != -1
110
+ if !wanted
111
+ wanted = idx.to_s
112
+ else
113
+ wanted += ',' + idx.to_s
114
+ end
115
+ end
116
+ idx += 1
117
+ end
118
+
119
+ post_url = BASE_URL + '/web/lixian/?ct=lixian&ac=add_task_bt'
120
+ data = {'info_hash' => ret['info_hash'],
121
+ 'wanted' => wanted,
122
+ #115有个小bug,文件名包含'会出问题
123
+ 'savepath' => ret['torrent_name'].gsub('\'', ''),
124
+ 'uid' => @http.cookies['UID'].split("_").first,
125
+ 'sign' => self.sign,
126
+ 'time' => self.time}
127
+ ret = @http.post(post_url, data)
128
+ ret = JSON.parse(ret.to_str)
129
+ if ret['error_msg']
130
+ puts ret['error_msg']
131
+ return true
132
+ end
133
+
134
+ puts "任务 torrent=#{torrent_file_name} 提交成功"
135
+ return true
136
+ end
137
+
138
+ def upload_link(link)
139
+ self.get_sign
140
+ url = BASE_URL + "/web/lixian/?ct=lixian&ac=add_task_url"
141
+ data = {'url' => URI.escape(link),
142
+ 'uid' => @http.cookies['UID'].split('_').first,
143
+ 'sign' => @sign,
144
+ 'time' => @time}
145
+ ret = @http.post(url,data)
146
+ puts ret
147
+ ret = JSON.parse(ret.to_str)
148
+ unless ret['state']
149
+ puts "下载链接提交失败"
150
+ return false
151
+ end
152
+ puts "链接提交成功,开始下载"
153
+ return true
154
+ end
155
+
156
+ def current_tasks_count(refresh=true)
157
+ count = 0
158
+ if refresh
159
+ self.get_lixian_tasks_list
160
+ end
161
+ return 999 unless @tasks
162
+ @tasks.each do |task|
163
+ next if task['status'] == 2
164
+ count += 1
165
+ end
166
+ count
167
+ end
168
+
169
+ def list_tasks_info
170
+ self.get_lixian_tasks_list
171
+ @tasks.each do |task|
172
+ if task['status'] == 2
173
+ if task['file_id']
174
+ puts "#{task['file_id']} #{task['name'].encode('UTF-8')}"
175
+ end
176
+ end
177
+ end
178
+ end
179
+
180
+ def show_task(task_id)
181
+ url = "http://web.api.115.com/files?aid=1&cid=#{task_id}&o=user_ptime&asc=0&offset=0&show_dir=1&limit=40&code=&scid=&snap=0&natsort=1&source=&format=json&type=&star=&is_share="
182
+ ret = @http.get(url)
183
+ ret = JSON.parse(ret.to_str)
184
+ ret["data"].each do |term|
185
+ puts "#{term["pc"]} #{term["n"]}"
186
+ end
187
+ end
188
+
189
+ def get_file_download_url(pick_code)
190
+ self.get_sign
191
+ url = "http://web.api.115.com/files/download?pickcode=#{pick_code}&_=" + @time.to_s
192
+ ret = @http.get(url)
193
+ ret = JSON.parse(ret.to_s)
194
+ puts URI.unescape(ret['file_url'])
195
+ end
196
+
197
+ def get_video_m3u8(pick_code)
198
+ url = "http://115.com/api/video/m3u8/#{pick_code}.m3u8"
199
+ ret = @http.get(url)
200
+ File.open("#{pick_code}.m3u8",'wb'){|f| f.write(ret.to_str)}
201
+ puts "m3u8文件下载成功"
202
+ end
203
+ end
204
+
@@ -0,0 +1,49 @@
1
+ require "lixian115/version"
2
+ require "thor"
3
+ require "lixian.rb"
4
+
5
+ module Lixian115
6
+ LixianUtil = Lixian.new
7
+ res = JSON.parse(IO.read(File.expand_path('~/.115cookie')))
8
+ cookies = {}
9
+
10
+ res.each do |cookie|
11
+ cookies[cookie["name"]] = cookie["value"]
12
+ end
13
+ cookies['loginType'] = '0'
14
+ LixianUtil.http.cookies = cookies
15
+
16
+
17
+ class App < Thor
18
+
19
+ desc "list", "list completed tasks"
20
+ def list
21
+ LixianUtil.list_tasks_info
22
+ end
23
+
24
+ desc "upload file_path", "upload a torrent lixian task to 115"
25
+ def upload file_path
26
+ LixianUtil.upload_torrent(file_path)
27
+ end
28
+
29
+ desc "add link", "add a link lixian task to 115"
30
+ def add url_path
31
+ LixianUtil.upload_link(url_path)
32
+ end
33
+
34
+ desc "show task_id", "show files in a task"
35
+ def show(task_id)
36
+ LixianUtil.show_task(task_id)
37
+ end
38
+
39
+ desc "get_download_url file_id", "get the download url for a file in a task"
40
+ def download_url file_id
41
+ LixianUtil.get_file_download_url(file_id)
42
+ end
43
+
44
+ desc "play file_id(not works now)", "get the m3u8 file to play the video"
45
+ def play(file_id)
46
+ LixianUtil.get_video_m3u8(file_id)
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,3 @@
1
+ module Lixian115
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'lixian115/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "lixian115"
8
+ spec.version = Lixian115::VERSION
9
+ spec.authors = ["aiyanxu"]
10
+ spec.email = ["liqingyan1990@gmail.com"]
11
+ spec.summary = %q{ a command tool for 115 wangpan lixian util }
12
+ spec.description = %q{ a command tool for 115 wangpan lixian util }
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.7"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ spec.add_dependency "thor", ">= 0.17.0"
24
+ spec.add_dependency "rest-client", ">= 1.7.3"
25
+ end
metadata ADDED
@@ -0,0 +1,113 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: lixian115
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - aiyanxu
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-03-04 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: thor
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: 0.17.0
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: 0.17.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: rest-client
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: 1.7.3
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: 1.7.3
69
+ description: " a command tool for 115 wangpan lixian util "
70
+ email:
71
+ - liqingyan1990@gmail.com
72
+ executables:
73
+ - lixian
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - ".gitignore"
78
+ - Gemfile
79
+ - LICENSE.txt
80
+ - README.md
81
+ - Rakefile
82
+ - bin/lixian
83
+ - lib/http_request.rb
84
+ - lib/lixian.rb
85
+ - lib/lixian115.rb
86
+ - lib/lixian115/version.rb
87
+ - lixian115.gemspec
88
+ homepage: ''
89
+ licenses:
90
+ - MIT
91
+ metadata: {}
92
+ post_install_message:
93
+ rdoc_options: []
94
+ require_paths:
95
+ - lib
96
+ required_ruby_version: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
101
+ required_rubygems_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ requirements: []
107
+ rubyforge_project:
108
+ rubygems_version: 2.2.2
109
+ signing_key:
110
+ specification_version: 4
111
+ summary: a command tool for 115 wangpan lixian util
112
+ test_files: []
113
+ has_rdoc: