mediafire 1.2.1 → 1.3.0
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.
- data/README.md +4 -1
- data/examples/create_folder.rb +5 -4
- data/examples/delete_file.rb +8 -10
- data/examples/download.rb +8 -9
- data/examples/download_image.rb +5 -8
- data/examples/downloads.rb +10 -20
- data/examples/dropbox_setup.rb +7 -4
- data/examples/dropbox_setup_option.rb +4 -4
- data/examples/dropbox_upload.rb +4 -3
- data/examples/edit_fileoption.rb +8 -17
- data/examples/get_myfile_list.rb +10 -3
- data/examples/image_rotation.rb +8 -9
- data/examples/move_file.rb +9 -7
- data/examples/save_file.rb +6 -3
- data/examples/toggle_acl.rb +4 -4
- data/examples/update.rb +7 -17
- data/examples/upload_file.rb +8 -10
- data/examples/upload_file_with_upload-progress.rb +2 -2
- data/lib/mediafire.rb +1 -0
- data/lib/mediafire/api.rb +388 -161
- data/lib/mediafire/connection.rb +1 -0
- data/lib/mediafire/store_object.rb +118 -86
- data/lib/mediafire/version.rb +1 -1
- data/mediafire.gemspec +1 -0
- metadata +19 -10
- data/examples/common.rb +0 -27
- data/examples/edit_note.rb +0 -16
data/README.md
CHANGED
data/examples/create_folder.rb
CHANGED
@@ -1,7 +1,8 @@
|
|
1
|
-
require '
|
1
|
+
require 'mediafire'
|
2
2
|
|
3
|
-
m =
|
3
|
+
m = Mediafire.new
|
4
|
+
m.login("<account>", "<password>")
|
5
|
+
|
6
|
+
folder = m.create_folder("<folder_name>")
|
4
7
|
|
5
|
-
uuid = create_uuid
|
6
|
-
folder = m.create_folder(uuid, root_folder)
|
7
8
|
puts "folder name : #{folder.name}"
|
data/examples/delete_file.rb
CHANGED
@@ -1,15 +1,13 @@
|
|
1
|
-
require '
|
1
|
+
require 'mediafire'
|
2
2
|
|
3
|
-
m =
|
3
|
+
m = Mediafire.new
|
4
|
+
m.login("<account>", "<password>")
|
4
5
|
|
5
|
-
|
6
|
-
|
6
|
+
folder = m.create_folder("<folder_name>")
|
7
|
+
re = m.delete(folder)
|
7
8
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
end
|
12
|
-
file = m.upload(uuid1)
|
13
|
-
File.delete(uuid1)
|
9
|
+
filepath = "testfile"
|
10
|
+
file = m.upload(filepath)
|
11
|
+
folder = m.create_folder("delete_test")
|
14
12
|
|
15
13
|
re = m.delete([file, folder])
|
data/examples/download.rb
CHANGED
@@ -1,13 +1,12 @@
|
|
1
|
-
require '
|
1
|
+
require 'mediafire'
|
2
2
|
|
3
3
|
m = Mediafire.new
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
puts pritty_format_datafile(file1)
|
5
|
+
filepath = "testfile"
|
6
|
+
file = m.upload(filepath)
|
7
|
+
out = "filename:#{file.name} "
|
8
|
+
out << "size:#{file.size} "
|
9
|
+
out << "link:http://www.mediafire.com/download.php?#{file.key}"
|
10
|
+
puts out
|
12
11
|
|
13
|
-
puts m.download(
|
12
|
+
puts m.download(file)
|
data/examples/download_image.rb
CHANGED
@@ -1,12 +1,9 @@
|
|
1
|
-
require '
|
1
|
+
require 'mediafire'
|
2
2
|
|
3
|
-
m =
|
3
|
+
m = Mediafire.new
|
4
|
+
m.login("<account>", "<password>")
|
4
5
|
|
5
|
-
|
6
|
-
|
7
|
-
f.write(File.open('./pic.gif').read)
|
8
|
-
end
|
9
|
-
pic = m.upload(uuid)
|
10
|
-
File.delete(uuid)
|
6
|
+
filepath = "testfile.gif"
|
7
|
+
pic = m.upload(filepath)
|
11
8
|
|
12
9
|
puts m.download_image(pic)
|
data/examples/downloads.rb
CHANGED
@@ -1,24 +1,14 @@
|
|
1
|
-
require '
|
1
|
+
require 'mediafire'
|
2
2
|
|
3
|
-
m =
|
3
|
+
m = Mediafire.new
|
4
|
+
m.login("<account>", "<password>")
|
4
5
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
end
|
9
|
-
file1 = m.upload(uuid)
|
10
|
-
File.delete(uuid)
|
11
|
-
puts 'upload file1'
|
6
|
+
filepath1 = "testfile1"
|
7
|
+
file1 = m.upload(filepath1)
|
8
|
+
puts "upload complete #{file1.name}"
|
12
9
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
end
|
17
|
-
file2 = m.upload(uuid)
|
18
|
-
File.delete(uuid)
|
19
|
-
puts 'upload file2'
|
10
|
+
filepath2 = "testfile2"
|
11
|
+
file2 = m.upload(filepath2)
|
12
|
+
puts "upload complete #{file2.name}"
|
20
13
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
m.downloads(files)
|
14
|
+
m.downloads([file1, file2])
|
data/examples/dropbox_setup.rb
CHANGED
@@ -1,8 +1,11 @@
|
|
1
|
-
require '
|
1
|
+
require 'mediafire'
|
2
2
|
|
3
|
-
m =
|
3
|
+
m = Mediafire.new
|
4
|
+
m.login("<account>", "<password>")
|
4
5
|
|
5
|
-
|
6
|
-
folder = m.create_folder(uuid, root_folder)
|
6
|
+
folder = m.create_folder("<folder_name>")
|
7
7
|
m.dropbox_setup(folder, true)
|
8
8
|
|
9
|
+
folder = m.create_folder("<folder_name>")
|
10
|
+
m.dropbox_setup(folder, true)
|
11
|
+
m.dropbox_setup(folder, false)
|
@@ -1,9 +1,9 @@
|
|
1
|
-
require '
|
1
|
+
require 'mediafire'
|
2
2
|
|
3
|
-
m =
|
3
|
+
m = Mediafire.new
|
4
|
+
m.login("<account>", "<password>")
|
4
5
|
|
5
|
-
|
6
|
-
folder = m.create_folder(uuid, root_folder)
|
6
|
+
folder = m.create_folder("<folder_name>")
|
7
7
|
m.dropbox_setup(folder, true)
|
8
8
|
options = {
|
9
9
|
:header => 'edited',
|
data/examples/dropbox_upload.rb
CHANGED
data/examples/edit_fileoption.rb
CHANGED
@@ -1,20 +1,11 @@
|
|
1
|
-
require '
|
1
|
+
require 'mediafire'
|
2
2
|
|
3
|
-
m =
|
3
|
+
m = Mediafire.new
|
4
|
+
m.login("<account>", "<password>")
|
4
5
|
|
5
|
-
|
6
|
-
|
7
|
-
f.write(uuid)
|
8
|
-
end
|
6
|
+
filepath = "testfile"
|
7
|
+
file = m.upload(filepath)
|
9
8
|
|
10
|
-
|
11
|
-
file = m.
|
12
|
-
|
13
|
-
:filename => 'edited',
|
14
|
-
:description => 'edited',
|
15
|
-
:tags => 'edited',
|
16
|
-
:password => 'edited',
|
17
|
-
}
|
18
|
-
m.edit_fileoption(file, options)
|
19
|
-
|
20
|
-
File.delete(uuid)
|
9
|
+
file = m.rename(file, 'edited')
|
10
|
+
file = m.description(file, 'edited')
|
11
|
+
file = m.password(file, 'edited')
|
data/examples/get_myfile_list.rb
CHANGED
@@ -1,4 +1,11 @@
|
|
1
|
-
require '
|
1
|
+
require 'mediafire'
|
2
2
|
|
3
|
-
m =
|
4
|
-
m.
|
3
|
+
m = Mediafire.new
|
4
|
+
m.login("<account>", "<password>")
|
5
|
+
|
6
|
+
m.file_list.each do |n|
|
7
|
+
out = "filename:#{n.name} "
|
8
|
+
out << "size:#{n.size} "
|
9
|
+
out << "link:http://www.mediafire.com/download.php?#{n.key}"
|
10
|
+
puts out
|
11
|
+
end
|
data/examples/image_rotation.rb
CHANGED
@@ -1,13 +1,12 @@
|
|
1
|
-
require '
|
1
|
+
require 'mediafire'
|
2
2
|
|
3
|
-
m =
|
3
|
+
m = Mediafire.new
|
4
|
+
m.login("<account>", "<password>")
|
4
5
|
|
5
|
-
|
6
|
-
|
7
|
-
f.write(File.open('pic.gif').read)
|
8
|
-
end
|
9
|
-
pic = m.upload(uuid)
|
10
|
-
File.delete(uuid)
|
6
|
+
filepath = "testfile.gif"
|
7
|
+
pic = m.upload(filepath)
|
11
8
|
|
12
9
|
m.image_rotation(pic, 90)
|
13
|
-
|
10
|
+
#m.image_rotation(pic, 180)
|
11
|
+
#m.image_rotation(pic, 270)
|
12
|
+
#m.image_rotation(pic, 0)
|
data/examples/move_file.rb
CHANGED
@@ -1,10 +1,12 @@
|
|
1
|
-
require '
|
1
|
+
require 'mediafire'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
m = login
|
6
|
-
folder = m.create_folder(uuid, root_folder)
|
7
|
-
file = m.create_folder(uuid1, root_folder)
|
3
|
+
m = Mediafire.new
|
4
|
+
m.login("<account>", "<password>")
|
8
5
|
|
9
|
-
|
6
|
+
filepath = "testfile"
|
7
|
+
file = m.upload(filepath)
|
10
8
|
|
9
|
+
folder1 = m.create_folder("<folder_name>")
|
10
|
+
folder2 = m.create_folder("<folder_name>")
|
11
|
+
|
12
|
+
re = m.move([file, folder1], folder2)
|
data/examples/save_file.rb
CHANGED
@@ -1,6 +1,9 @@
|
|
1
|
-
require '
|
1
|
+
require 'mediafire'
|
2
2
|
|
3
|
-
m =
|
4
|
-
|
3
|
+
m = Mediafire.new
|
4
|
+
m.login("<account>", "<password>")
|
5
|
+
|
6
|
+
download_url = 'http://www.mediafire.com/?xxxxxxxxxxxxxxx'
|
7
|
+
quickkey = download_url.match(/\?(.*)/)[1]
|
5
8
|
m.save_file_to_my_account(quickkey)
|
6
9
|
|
data/examples/toggle_acl.rb
CHANGED
data/examples/update.rb
CHANGED
@@ -1,22 +1,12 @@
|
|
1
|
-
require '
|
1
|
+
require 'mediafire'
|
2
2
|
|
3
|
-
m =
|
3
|
+
m = Mediafire.new
|
4
|
+
m.login("<account>", "<password>")
|
4
5
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
file_a = m.upload(uuid)
|
10
|
-
File.delete(uuid)
|
6
|
+
filepath1 = "testfile1"
|
7
|
+
filepath2 = "testfile2"
|
8
|
+
file_a = m.upload(filepath1)
|
9
|
+
file_b = m.upload(filepath2)
|
11
10
|
|
12
|
-
uuid = create_uuid
|
13
|
-
File.open(uuid, "w") do |f|
|
14
|
-
f.write(uuid)
|
15
|
-
end
|
16
|
-
file_b = m.upload(uuid)
|
17
|
-
File.delete(uuid)
|
18
|
-
|
19
|
-
puts pritty_format_datafile(file_a)
|
20
|
-
puts pritty_format_datafile(file_b)
|
21
11
|
m.update(file_a, file_b)
|
22
12
|
|
data/examples/upload_file.rb
CHANGED
@@ -1,12 +1,10 @@
|
|
1
|
-
require '
|
1
|
+
require 'mediafire'
|
2
2
|
|
3
|
-
|
4
|
-
File.open(uuid, "w") do |f|
|
5
|
-
f.write(uuid)
|
6
|
-
end
|
3
|
+
m = Mediafire.new
|
7
4
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
5
|
+
filepath = "testfile"
|
6
|
+
file = m.upload(filepath)
|
7
|
+
out = "filename:#{file.name} "
|
8
|
+
out << "size:#{file.size} "
|
9
|
+
out << "link:http://www.mediafire.com/download.php?#{file.quickkey}"
|
10
|
+
puts out
|
@@ -9,8 +9,8 @@ queue = Queue.new
|
|
9
9
|
|
10
10
|
file = ARGV[0]
|
11
11
|
filename = File.basename(file)
|
12
|
-
puts "Filename: " + filename
|
13
12
|
filesize = File.stat(file).size
|
13
|
+
puts "Filename: " + filename
|
14
14
|
puts "Filesize: " + filesize.to_s
|
15
15
|
|
16
16
|
m = Mediafire.new
|
@@ -31,7 +31,7 @@ while upload_t.nil?
|
|
31
31
|
sleep 0.1
|
32
32
|
end
|
33
33
|
|
34
|
-
pbar = ProgressBar.new(
|
34
|
+
pbar = ProgressBar.new("#{filename}(bytes)", filesize)
|
35
35
|
pbar.file_transfer_mode
|
36
36
|
while upload_t.alive?
|
37
37
|
uploadsize = m.upload_size filename
|
data/lib/mediafire.rb
CHANGED
data/lib/mediafire/api.rb
CHANGED
@@ -2,10 +2,6 @@ module Mediafire
|
|
2
2
|
module API
|
3
3
|
include Mediafire::Connection
|
4
4
|
|
5
|
-
def toppage
|
6
|
-
get('')
|
7
|
-
end
|
8
|
-
|
9
5
|
def login(account, password)
|
10
6
|
@cookie = {}
|
11
7
|
toppage
|
@@ -14,8 +10,6 @@ module Mediafire
|
|
14
10
|
:login_email => account,
|
15
11
|
:login_pass => password,
|
16
12
|
:login_remember => 'on',
|
17
|
-
"submit_login.x" => 0,
|
18
|
-
"submit_login.y" => 0,
|
19
13
|
}
|
20
14
|
post("dynamic/login.php", options)
|
21
15
|
end
|
@@ -24,145 +18,129 @@ module Mediafire
|
|
24
18
|
end
|
25
19
|
end
|
26
20
|
|
27
|
-
def list
|
21
|
+
def list(options={})
|
28
22
|
raise NeedLogin unless is_loggedin?
|
29
23
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
24
|
+
folder = options['folder']
|
25
|
+
filter = options['filter']
|
26
|
+
recursive = options['recursive'] || true
|
27
|
+
|
28
|
+
if folder.nil?
|
29
|
+
response = myfiles(recursive, filter)
|
30
|
+
else
|
31
|
+
response = info(folder.key, recursive)
|
36
32
|
end
|
37
|
-
|
38
|
-
@root_folder = StoreObject.new(root_folder)
|
39
|
-
return datas
|
33
|
+
StoreFolder.new(response)
|
40
34
|
end
|
41
35
|
|
42
|
-
def
|
43
|
-
|
44
|
-
|
45
|
-
form_option = {
|
46
|
-
:form_todolist1 => create_list(files),
|
47
|
-
:form_todolist2 => '',
|
48
|
-
:form_todotype => 1,
|
49
|
-
:form_todoparent => '',
|
50
|
-
:form_todoconfirm => '',
|
51
|
-
}
|
52
|
-
options = api_options[:doselected].merge(form_option)
|
53
|
-
response = post('dynamic/doselected.php', options)
|
36
|
+
def folder_list
|
37
|
+
list('recursive' => true, 'filter' => 'folders').folders
|
38
|
+
end
|
54
39
|
|
55
|
-
|
56
|
-
|
57
|
-
else
|
58
|
-
false
|
59
|
-
end
|
40
|
+
def file_list
|
41
|
+
list('recursive' => true, 'filter' => 'files').files
|
60
42
|
end
|
61
43
|
|
62
|
-
def
|
44
|
+
def delete(objs)
|
63
45
|
raise NeedLogin unless is_loggedin?
|
64
46
|
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
47
|
+
file_response = true
|
48
|
+
folder_response = true
|
49
|
+
|
50
|
+
obj = separate_store_object(objs)
|
51
|
+
|
52
|
+
file_response = delete_files(obj[:files]) unless obj[:files].empty?
|
53
|
+
folder_response = delete_folders(obj[:folders]) unless obj[:folders].empty?
|
54
|
+
|
55
|
+
if file_response and folder_response
|
73
56
|
true
|
74
57
|
else
|
75
58
|
false
|
76
59
|
end
|
77
60
|
end
|
78
61
|
|
79
|
-
|
80
|
-
def edit_fileoption(file, options)
|
62
|
+
def move(src, dest)
|
81
63
|
raise NeedLogin unless is_loggedin?
|
82
64
|
|
83
|
-
|
84
|
-
|
85
|
-
:todoquickkey => file.quickkey,
|
86
|
-
:todofilename => file.name,
|
87
|
-
:filename => options[:filename] || file.name,
|
88
|
-
:desc => options[:description] || file.description,
|
89
|
-
:tags => options[:tags] || file.tags,
|
90
|
-
:password => options[:password] || file.password,
|
91
|
-
}
|
65
|
+
file_response = true
|
66
|
+
folder_response = true
|
92
67
|
|
93
|
-
|
94
|
-
puts 'Error: description too long'
|
95
|
-
return
|
96
|
-
end
|
68
|
+
obj = separate_store_object(src)
|
97
69
|
|
98
|
-
|
99
|
-
|
100
|
-
return
|
101
|
-
end
|
70
|
+
file_response = move_files(obj[:files], dest) unless obj[:files].empty?
|
71
|
+
folder_response = move_folders(obj[:folders], dest) unless obj[:folders].empty?
|
102
72
|
|
103
|
-
|
104
|
-
if response.body.match(/et ?= ?15;/)
|
73
|
+
if file_response and folder_response
|
105
74
|
true
|
106
75
|
else
|
107
76
|
false
|
108
77
|
end
|
109
78
|
end
|
110
79
|
|
111
|
-
|
112
|
-
def edit_note(file, note)
|
113
|
-
raise NeedLogin unless is_loggedin?
|
114
|
-
|
80
|
+
def rename(file, name)
|
115
81
|
options = {
|
116
|
-
|
117
|
-
|
82
|
+
'filename' => name,
|
83
|
+
'description' => file.description,
|
118
84
|
}
|
119
|
-
if options
|
120
|
-
|
121
|
-
|
85
|
+
if file_update(file, options)
|
86
|
+
pick_object(file.key, 'file')
|
87
|
+
else
|
88
|
+
nil
|
122
89
|
end
|
123
|
-
type = file.is_folder? ? 'folder' : 'file'
|
124
|
-
post("dynamic/editfilenotes.php?quickkey=#{file.quickkey}&t=#{type}", options)
|
125
|
-
return true
|
126
90
|
end
|
127
91
|
|
128
|
-
def
|
129
|
-
raise NeedLogin unless is_loggedin?
|
130
|
-
|
92
|
+
def description(file, desc)
|
131
93
|
options = {
|
132
|
-
|
133
|
-
|
94
|
+
'filename' => file.name,
|
95
|
+
'description' => desc,
|
134
96
|
}
|
135
|
-
|
136
|
-
|
137
|
-
|
97
|
+
if file_update(file, options)
|
98
|
+
pick_object(file.key, 'file')
|
99
|
+
else
|
100
|
+
nil
|
138
101
|
end
|
102
|
+
end
|
139
103
|
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
104
|
+
def password(file, pass)
|
105
|
+
options = {
|
106
|
+
'password' => pass,
|
107
|
+
}
|
108
|
+
if file_update(file, options)
|
109
|
+
pick_object(file.key, 'file')
|
110
|
+
else
|
111
|
+
nil
|
112
|
+
end
|
147
113
|
end
|
148
114
|
|
149
|
-
def
|
115
|
+
def create_folder(newname, folder=nil)
|
150
116
|
raise NeedLogin unless is_loggedin?
|
151
117
|
|
152
|
-
|
153
|
-
|
118
|
+
options = base_query
|
119
|
+
options << "foldername=#{newname}"
|
120
|
+
options << "parent_key=#{folder.key}" unless folder.nil?
|
121
|
+
|
122
|
+
response = get("api/folder/create.php?#{options.join('&')}")
|
123
|
+
response = JSON.parse(response.body)['response']
|
124
|
+
if response['result'] == 'Success'
|
125
|
+
pick_object(response['folder_key'], 'folder', folder)
|
154
126
|
else
|
155
|
-
|
127
|
+
nil
|
156
128
|
end
|
157
|
-
|
158
|
-
|
159
|
-
|
129
|
+
end
|
130
|
+
|
131
|
+
def toggle_acl(file, recursive=false)
|
132
|
+
options = {}
|
133
|
+
if file.is_public?
|
134
|
+
options['privacy'] = 'private'
|
135
|
+
else
|
136
|
+
options['privacy'] = 'public'
|
160
137
|
end
|
161
|
-
|
162
|
-
|
163
|
-
|
138
|
+
options['privacy_recursive'] = 'yes' if recursive
|
139
|
+
|
140
|
+
if file_update(file, options)
|
141
|
+
pick_object(file.key, 'file')
|
164
142
|
else
|
165
|
-
|
143
|
+
nil
|
166
144
|
end
|
167
145
|
end
|
168
146
|
|
@@ -179,19 +157,22 @@ module Mediafire
|
|
179
157
|
if folder.nil?
|
180
158
|
keys[:folderkey] = c.xpath('./folderkey').text
|
181
159
|
else
|
182
|
-
keys[:folderkey] = folder.
|
160
|
+
keys[:folderkey] = folder.key
|
183
161
|
end
|
184
162
|
end
|
185
163
|
keys[:mful_config] = doc.xpath('//mediafire/MFULConfig').text
|
186
164
|
|
187
|
-
query =
|
188
|
-
query << "
|
189
|
-
query << "
|
190
|
-
query << "
|
191
|
-
query << "
|
165
|
+
query = []
|
166
|
+
query << "type=basic"
|
167
|
+
query << "ukey=#{keys[:ukey]}"
|
168
|
+
query << "user=#{keys[:user]}"
|
169
|
+
query << "uploadkey=#{keys[:folderkey]}"
|
170
|
+
query << "filenum=0"
|
171
|
+
query << "uploader=0"
|
172
|
+
query << "MFULConfig=#{keys[:mful_config]}"
|
192
173
|
response = File.open(filepath) do |f|
|
193
174
|
options = {:Filedata => UploadIO.new(f, 'application/octet-stream', filename)}
|
194
|
-
post("douploadtoapi?#{query}", options)
|
175
|
+
post("douploadtoapi?#{query.join('&')}", options)
|
195
176
|
end
|
196
177
|
doc = Nokogiri::XML(response.body)
|
197
178
|
keys[:filekey] = doc.xpath('//response/doupload/key').text
|
@@ -202,31 +183,22 @@ module Mediafire
|
|
202
183
|
end
|
203
184
|
|
204
185
|
keys[:quickkey] = nil
|
205
|
-
|
186
|
+
|
187
|
+
query = []
|
188
|
+
query << "key=#{keys[:filekey]}"
|
189
|
+
query << "MFULConfig=#{keys[:mful_config]}"
|
206
190
|
while keys[:quickkey] == nil || keys[:quickkey] == ''
|
207
|
-
response = get("basicapi/pollupload.php?#{query}")
|
191
|
+
response = get("basicapi/pollupload.php?#{query.join('&')}")
|
208
192
|
doc = Nokogiri::XML(response.body)
|
209
193
|
keys[:quickkey] = doc.xpath('//response/doupload/quickkey').text
|
210
194
|
keys[:size] = doc.xpath('//response/doupload/size').text
|
211
195
|
sleep 0.5
|
212
196
|
end
|
213
197
|
|
214
|
-
|
215
|
-
:filename => filename,
|
216
|
-
:quickkey => keys[:quickkey],
|
217
|
-
}
|
218
|
-
response = post("basicapi/getfiletype.php?MFULConfig=#{keys[:mful_config]}", options)
|
219
|
-
doc = Nokogiri::XML(response.body)
|
220
|
-
keys[:filetype] = doc.xpath('//response/file/filetype').text
|
221
|
-
keys[:sharekey] = doc.xpath('//response/file/sharekey').text
|
222
|
-
keys[:r_size], keys[:r_sizeunit] = filesize_to_readable_filesize(keys[:size].to_i)
|
223
|
-
|
224
|
-
data = ['1', '1', keys[:filetype], keys[:quickkey], '', filename, keys[:size],
|
225
|
-
keys[:r_size], keys[:r_sizeunit], '0', Time.now.gmtime.strftime("%m/%d/%Y"),
|
226
|
-
'0', '', '', '', keys[:sharekey], '0', '0', '', '', '']
|
227
|
-
StoreObject.new(data)
|
198
|
+
pick_object(keys[:quickkey], 'file', folder)
|
228
199
|
end
|
229
200
|
|
201
|
+
|
230
202
|
#def webupload(url, folder)
|
231
203
|
#end
|
232
204
|
|
@@ -235,15 +207,20 @@ module Mediafire
|
|
235
207
|
return downloads(file)
|
236
208
|
end
|
237
209
|
|
238
|
-
|
210
|
+
if file.is_a?(StoreFile)
|
211
|
+
response = get("?#{file.key}")
|
212
|
+
else
|
213
|
+
response = get("?#{file}")
|
214
|
+
end
|
239
215
|
if response.code.to_i == 302
|
240
216
|
return response['Location']
|
241
217
|
end
|
242
218
|
|
243
219
|
body = response.body
|
244
|
-
funcbody = body.scan(/
|
220
|
+
funcbody = body.scan(/function .*?for.*?eval/)
|
245
221
|
functions = funcbody.map {|n| n.match(/function (.*?)\(/).to_a[1]}
|
246
222
|
decrypt_str = funcbody.map {|n| find_encrypt_string_and_decrypt(n)}
|
223
|
+
[body, funcbody, functions, decrypt_str]
|
247
224
|
|
248
225
|
t = decrypt_str.last
|
249
226
|
funcname = t.match(/(.*?)\(/)[1]
|
@@ -296,23 +273,7 @@ module Mediafire
|
|
296
273
|
return
|
297
274
|
end
|
298
275
|
|
299
|
-
|
300
|
-
response['Location']
|
301
|
-
end
|
302
|
-
|
303
|
-
def update(src, dest)
|
304
|
-
raise NeedLogin unless is_loggedin?
|
305
|
-
|
306
|
-
option = {
|
307
|
-
"file_a" => src.quickkey,
|
308
|
-
"file_b" => dest.quickkey,
|
309
|
-
}
|
310
|
-
response = post('dynamic/updatefile.php', option)
|
311
|
-
if response.body.match(/et ?= ?15;/)
|
312
|
-
true
|
313
|
-
else
|
314
|
-
false
|
315
|
-
end
|
276
|
+
"#{ENDPOINT}imgbnc.php/#{file.hash}#{size.to_s}g.jpg"
|
316
277
|
end
|
317
278
|
|
318
279
|
def image_rotation(file, rotation)
|
@@ -323,19 +284,41 @@ module Mediafire
|
|
323
284
|
return
|
324
285
|
end
|
325
286
|
|
326
|
-
unless
|
287
|
+
unless rotation == 0 || rotation == 90 || rotation == 180 || rotation == 270
|
327
288
|
puts "Error: rotation need 0 or 90 or 180 or 270"
|
328
289
|
return
|
329
290
|
end
|
330
291
|
|
331
|
-
|
292
|
+
query = []
|
293
|
+
query << "imgkey=#{file.hash}"
|
294
|
+
query << "newrotation=#{rotation.to_s}"
|
295
|
+
query << "nocache=#{rand.to_s}"
|
296
|
+
|
297
|
+
get("dynamic/imagerotation.php?#{query.join('&')}")
|
332
298
|
return true
|
333
299
|
end
|
334
300
|
|
301
|
+
def update(dest, src)
|
302
|
+
raise NeedLogin unless is_loggedin?
|
303
|
+
|
304
|
+
query = base_query
|
305
|
+
query << "r=#{r(4)}"
|
306
|
+
query << "from_quickkey=#{src.key}"
|
307
|
+
query << "to_quickkey=#{dest.key}"
|
308
|
+
query << "quickkey=#{src.key}"
|
309
|
+
|
310
|
+
response = get("api/file/update_file.php?#{query.join('&')}")
|
311
|
+
if JSON.parse(response.body)['response']['result'] == 'Success'
|
312
|
+
true
|
313
|
+
else
|
314
|
+
false
|
315
|
+
end
|
316
|
+
end
|
317
|
+
|
335
318
|
def save_file_to_my_account(quickkey)
|
336
319
|
raise NeedLogin unless is_loggedin?
|
337
320
|
|
338
|
-
response = get("dynamic/savefile.php?qk=#{quickkey}
|
321
|
+
response = get("dynamic/savefile.php?qk=#{quickkey}")
|
339
322
|
if response.body.match(/et ?= ?15;/)
|
340
323
|
true
|
341
324
|
else
|
@@ -349,28 +332,34 @@ module Mediafire
|
|
349
332
|
options = {
|
350
333
|
:dbx_status_enable => status ? 1 : 0,
|
351
334
|
:dbx_silent_return => 0,
|
352
|
-
:dbx_status_id => folder.
|
335
|
+
:dbx_status_id => folder.key,
|
353
336
|
}
|
354
337
|
response = post('dropbox/dosetupdropbox.php', options)
|
355
338
|
if response.body.match(/et ?= ?15[012];/)
|
356
|
-
true
|
339
|
+
return true unless status
|
357
340
|
else
|
358
|
-
false
|
341
|
+
return false
|
342
|
+
end
|
343
|
+
|
344
|
+
if dropbox_setup_option(folder)
|
345
|
+
return true
|
346
|
+
else
|
347
|
+
return false
|
359
348
|
end
|
360
349
|
end
|
361
350
|
|
362
351
|
# return Dropbox ID
|
363
|
-
def dropbox_setup_option(folder, options)
|
352
|
+
def dropbox_setup_option(folder, options={})
|
364
353
|
raise NeedLogin unless is_loggedin?
|
365
354
|
|
366
|
-
response = post('dropbox/dosetupdropbox.php', {:dbx_folderid => folder.
|
355
|
+
response = post('dropbox/dosetupdropbox.php', {:dbx_folderid => folder.key})
|
367
356
|
folder_options = eval("[#{response.body.match(/parent.Bl\((.*?)\);break;/)[1]}]")
|
368
357
|
|
369
358
|
allow_add_description = options[:allow_add_description] ? 1 : 0
|
370
359
|
multiple_upload = options[:multiple_upload] ? 1 : 0
|
371
360
|
email_notification = options[:email_notification] ? 1 : 0
|
372
361
|
form_options = {
|
373
|
-
:dbx_folder => folder.
|
362
|
+
:dbx_folder => folder.key,
|
374
363
|
:dbx_text1 => options[:header] || folder_options[2],
|
375
364
|
:dbx_text2 => options[:message] || folder_options[3],
|
376
365
|
:dbx_text3 => options[:completion_message] || folder_options[4],
|
@@ -405,13 +394,17 @@ module Mediafire
|
|
405
394
|
keys[:trackkey] = c.xpath('./trackkey').text
|
406
395
|
end
|
407
396
|
|
408
|
-
query =
|
409
|
-
query << "
|
410
|
-
query << "
|
411
|
-
query << "
|
397
|
+
query = []
|
398
|
+
query << "type=basic"
|
399
|
+
query << "track=#{keys[:trackkey]}"
|
400
|
+
query << "dropbox=1"
|
401
|
+
query << "ukey=#{keys[:ukey]}"
|
402
|
+
query << "user=#{keys[:user]}"
|
403
|
+
query << "uploadkey=#{dropbox_id}"
|
404
|
+
query << "upload=0"
|
412
405
|
response = File.open(filepath) do |f|
|
413
406
|
options = {:Filedata => UploadIO.new(f, 'application/octet-stream', filename)}
|
414
|
-
post("douploadtoapi?#{query}", options)
|
407
|
+
post("douploadtoapi?#{query.join('&')}", options)
|
415
408
|
end
|
416
409
|
doc = Nokogiri::XML(response.body)
|
417
410
|
keys[:filekey] = doc.xpath('//response/doupload/key').text
|
@@ -434,21 +427,255 @@ module Mediafire
|
|
434
427
|
puts "#{ENDPOINT}?#{keys[:quickkey]}"
|
435
428
|
end
|
436
429
|
|
430
|
+
def revision(folder_key="myfiles", recursive=false)
|
431
|
+
query = base_query
|
432
|
+
query << "r=#{r(4)}"
|
433
|
+
query << "recursive=#{recursive ? 'yes' : 'no'}"
|
434
|
+
query << "folder_key=#{folder_key}"
|
435
|
+
|
436
|
+
response = get("api/folder/get_revision.php?#{query.join('&')}").body
|
437
|
+
JSON.parse(response)['response']['revision']
|
438
|
+
end
|
439
|
+
|
437
440
|
def is_loggedin?
|
438
441
|
@loggedin
|
439
442
|
end
|
440
443
|
|
441
444
|
private
|
442
445
|
|
446
|
+
# Low level APIs
|
447
|
+
|
448
|
+
def toppage
|
449
|
+
get('')
|
450
|
+
end
|
451
|
+
|
452
|
+
# @param token session token
|
453
|
+
# @param recursive [true|false]
|
454
|
+
# @param filter ['folder']
|
455
|
+
def myfiles(recursive=false, filter=nil)
|
456
|
+
query = base_query
|
457
|
+
query << "r=#{r(4)}"
|
458
|
+
query << "recursive=#{recursive ? 'yes' : 'no'}" unless recursive.nil?
|
459
|
+
query << "content_filter=#{filter}" unless filter.nil?
|
460
|
+
|
461
|
+
response = get("api/user/myfiles.php?#{query.join('&')}").body
|
462
|
+
JSON.parse(response)['response']['myfiles']
|
463
|
+
end
|
464
|
+
|
465
|
+
def info(folder_keys, recursive=false)
|
466
|
+
if folder_keys.is_a?(String)
|
467
|
+
folder_keys = [folder_keys]
|
468
|
+
end
|
469
|
+
|
470
|
+
query = base_query
|
471
|
+
query << "r=#{r(4)}"
|
472
|
+
query << "folder_key=#{folder_keys.join(',')}"
|
473
|
+
query << "recursive=#{recursive ? 'yes' : 'no'}"
|
474
|
+
|
475
|
+
response = get("api/folder/get_info.php?#{query.join('&')}").body
|
476
|
+
response = JSON.parse(response)['response']
|
477
|
+
|
478
|
+
if response.key?('folder_info')
|
479
|
+
return response['folder_info']
|
480
|
+
elsif response.key?('folder_infos')
|
481
|
+
return response['folder_infos']
|
482
|
+
end
|
483
|
+
end
|
484
|
+
|
485
|
+
def file_update(file, options={})
|
486
|
+
if options.key?('password')
|
487
|
+
return password_update(file, options['password'])
|
488
|
+
end
|
489
|
+
|
490
|
+
query = base_query
|
491
|
+
query << "filename=#{options['filename']}" if options.key?('filename')
|
492
|
+
query << "description=#{options['description']}" if options.key?('description')
|
493
|
+
if options.key?('privacy')
|
494
|
+
query << "privacy=#{options['privacy']}"
|
495
|
+
query << "r=#{r(4)}"
|
496
|
+
end
|
497
|
+
if !file.is_folder? && options.key?('privacy_recursive')
|
498
|
+
query << "privacy_recursive=#{options['privacy_recursive']}"
|
499
|
+
end
|
500
|
+
query << "quick_key=#{file.key}"
|
501
|
+
|
502
|
+
if file.is_folder?
|
503
|
+
response = get("api/folder/update.php?#{query.join('&')}")
|
504
|
+
else
|
505
|
+
response = get("api/file/update.php?#{query.join('&')}")
|
506
|
+
end
|
507
|
+
|
508
|
+
return false if response.code.to_i == 400
|
509
|
+
if JSON.parse(response.body)['response']['result'] == 'Success'
|
510
|
+
return true
|
511
|
+
else
|
512
|
+
return false
|
513
|
+
end
|
514
|
+
end
|
515
|
+
|
516
|
+
def password_update(file, password)
|
517
|
+
query = base_query
|
518
|
+
query << "r=#{r(4)}"
|
519
|
+
query << "quick_key=#{file.key}"
|
520
|
+
query << "password=#{password}"
|
521
|
+
|
522
|
+
if file.is_folder?
|
523
|
+
response = get("api/folder/update_password.php?#{query.join('&')}")
|
524
|
+
else
|
525
|
+
response = get("api/file/update_password.php?#{query.join('&')}")
|
526
|
+
end
|
527
|
+
|
528
|
+
return false if response.code.to_i == 400
|
529
|
+
if JSON.parse(response.body)['response']['result'] == 'Success'
|
530
|
+
return true
|
531
|
+
else
|
532
|
+
return false
|
533
|
+
end
|
534
|
+
end
|
535
|
+
|
536
|
+
def delete_files(files)
|
537
|
+
options = base_query(true)
|
538
|
+
options[:quick_key] = quick_keys(files).join(',')
|
539
|
+
|
540
|
+
response = post('api/file/delete.php', options)
|
541
|
+
if JSON.parse(response.body)['response']['result'] == 'Success'
|
542
|
+
true
|
543
|
+
else
|
544
|
+
false
|
545
|
+
end
|
546
|
+
end
|
547
|
+
|
548
|
+
def delete_folders(folders)
|
549
|
+
options = base_query(true)
|
550
|
+
options[:folder_key] = quick_keys(folders).join(',')
|
551
|
+
|
552
|
+
response = post('api/folder/delete.php', options)
|
553
|
+
if JSON.parse(response.body)['response']['result'] == 'Success'
|
554
|
+
true
|
555
|
+
else
|
556
|
+
false
|
557
|
+
end
|
558
|
+
end
|
559
|
+
|
560
|
+
def move_files(files, dest)
|
561
|
+
options = base_query(true)
|
562
|
+
options[:quick_key] = quick_keys(files).join(',')
|
563
|
+
options[:folder_key] = dest.key
|
564
|
+
|
565
|
+
response = post('api/file/move.php', options)
|
566
|
+
if JSON.parse(response.body)['response']['result'] == 'Success'
|
567
|
+
true
|
568
|
+
else
|
569
|
+
false
|
570
|
+
end
|
571
|
+
end
|
572
|
+
|
573
|
+
def move_folders(folders, dest)
|
574
|
+
options = base_query(true)
|
575
|
+
options[:folder_key_src] = quick_keys(folders).join(',')
|
576
|
+
options[:folder_key_dst] = dest.key
|
577
|
+
|
578
|
+
response = post('api/folder/move.php', options)
|
579
|
+
if JSON.parse(response.body)['response']['result'] == 'Success'
|
580
|
+
true
|
581
|
+
else
|
582
|
+
false
|
583
|
+
end
|
584
|
+
end
|
585
|
+
|
586
|
+
# Utilities
|
587
|
+
|
588
|
+
def session_token
|
589
|
+
if defined?(@token)
|
590
|
+
return @token
|
591
|
+
end
|
592
|
+
|
593
|
+
response = get('myfiles.php')
|
594
|
+
@token = /[0-9a-f]{144}/.match(response.body)[0]
|
595
|
+
return @token
|
596
|
+
end
|
597
|
+
|
443
598
|
def create_list(files)
|
444
599
|
f = files
|
445
600
|
f = [f] unless f.is_a?(Array)
|
446
|
-
f.map {|n| "#{n.
|
601
|
+
f.map {|n| "#{n.is_folder? ? '2' : '1'}:#{n.key}"}.join(';')
|
447
602
|
end
|
448
603
|
|
449
|
-
def
|
450
|
-
|
451
|
-
|
604
|
+
def separate_store_object(objs)
|
605
|
+
files = []
|
606
|
+
folders = []
|
607
|
+
|
608
|
+
objs = [objs] unless objs.is_a?(Array)
|
609
|
+
objs.each do |obj|
|
610
|
+
files << obj if obj.is_a?(StoreFile)
|
611
|
+
folders << obj if obj.is_a?(StoreFolder)
|
612
|
+
end
|
613
|
+
|
614
|
+
return {
|
615
|
+
:files => files,
|
616
|
+
:folders => folders,
|
617
|
+
}
|
618
|
+
end
|
619
|
+
|
620
|
+
def r(len)
|
621
|
+
r = ''
|
622
|
+
while (len > 0)
|
623
|
+
r << (((rand * 1000).to_i % 26) + 97).chr
|
624
|
+
len -= 1
|
625
|
+
end
|
626
|
+
return r
|
627
|
+
end
|
628
|
+
|
629
|
+
def base_query(hash=false)
|
630
|
+
if hash
|
631
|
+
return {
|
632
|
+
:session_token => session_token,
|
633
|
+
:response_format => 'json',
|
634
|
+
:version => 1,
|
635
|
+
}
|
636
|
+
else
|
637
|
+
return [
|
638
|
+
"session_token=#{session_token}",
|
639
|
+
"response_format=json",
|
640
|
+
"version=1",
|
641
|
+
]
|
642
|
+
end
|
643
|
+
end
|
644
|
+
|
645
|
+
def quick_keys(files)
|
646
|
+
return [files.key] unless files.is_a?(Array)
|
647
|
+
|
648
|
+
quick_keys = []
|
649
|
+
files.each do |f|
|
650
|
+
quick_keys << f.key
|
651
|
+
end
|
652
|
+
|
653
|
+
quick_keys
|
654
|
+
end
|
655
|
+
|
656
|
+
def pick_object(key, type, folder=nil)
|
657
|
+
if folder.nil?
|
658
|
+
datas = myfiles
|
659
|
+
if type == 'file' and datas.key?('files')
|
660
|
+
datas['files'].each {|f| return StoreFile.new(f) if f['quickkey'] == key}
|
661
|
+
elsif type == 'folder' and datas.key?('folders')
|
662
|
+
datas['folders'].each {|f| return StoreFolder.new(f) if f['folderkey'] == key}
|
663
|
+
else
|
664
|
+
return nil
|
665
|
+
end
|
666
|
+
|
667
|
+
else
|
668
|
+
sf = StoreFolder.new(info(folder.key))
|
669
|
+
if type == 'file'
|
670
|
+
objs = sf.files
|
671
|
+
elsif type == 'folder'
|
672
|
+
objs = sf.folders
|
673
|
+
else
|
674
|
+
return nil
|
675
|
+
end
|
676
|
+
|
677
|
+
objs.each {|f| return f if f.key == key}
|
678
|
+
end
|
452
679
|
end
|
453
680
|
|
454
681
|
def filesize_to_readable_filesize(size)
|