├── README.md ├── index.html └── mediafire.js /README.md: -------------------------------------------------------------------------------- 1 | # mediafire-bulk-importer 2 | Import mediafire links to your account in bulk 3 | 4 | https://anadius.github.io/mediafire-bulk-importer/ 5 | -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Mediafire bulk importer 5 | 6 | 26 | 27 | 28 | 29 |
30 |
31 | Log into your Mediafire account:
32 | Login:

33 | Password:

34 | 35 |
36 | 37 | 43 |
44 | 45 | 46 | 146 | 147 | 148 | -------------------------------------------------------------------------------- /mediafire.js: -------------------------------------------------------------------------------- 1 | /** 2 | * MediaFire JavaScript SDK 3 | * Licensed under the Apache License, Version 2.0 4 | */ 5 | 6 | (function() { 7 | "use strict"; 8 | 9 | /** 10 | * Initializes an application specific instance of MediaFire 11 | * @param {number} appId The supplied MediaFire application id 12 | * @param {object=} options Properties to override the default API SDK properties 13 | * @constructor 14 | */ 15 | function MediaFire(appId, options) { 16 | options = options || {}; 17 | 18 | /** 19 | * Path to the uploader resources 20 | * @constant 21 | * @type {string} 22 | * @private 23 | */ 24 | this._UPLOADER_RESOURCE_PATH = options.resourcePath || ''; 25 | 26 | /** 27 | * API version to use by default 28 | * @constant 29 | * @type {string} 30 | * @private 31 | */ 32 | this._API_VERSION = options.apiVersion || '1.3'; 33 | 34 | /** 35 | * Token version to use (default is 2) 36 | * @constant 37 | * @type {number} 38 | * @private 39 | */ 40 | this._TOKEN_VERSION = options.tokenVersion && options.tokenVersion < 3 ? options.tokenVersion : 2; 41 | 42 | /** 43 | * Path to the MediaFire API 44 | * @constant 45 | * @type {string} 46 | * @private 47 | */ 48 | this._API_PATH = '//www.mediafire.com/api/'; 49 | 50 | /** 51 | * Application ID 52 | * @type {number} 53 | * @private 54 | */ 55 | this._appId = appId; 56 | 57 | /** 58 | * Application Key 59 | * @type {string} 60 | * @private 61 | */ 62 | this._appKey = options.appKey || ''; 63 | 64 | /** 65 | * API Session Token 66 | * @type {string} 67 | * @private 68 | */ 69 | this._sessionToken = ''; 70 | 71 | /** 72 | * Number of v2 Session Tokens to storen (default is 3, max is 6) 73 | * @type {object} 74 | * @private 75 | */ 76 | this._v2SessionTokensNum = options.tokensStored && options.tokensStored<7 ? options.tokensStored : 3; 77 | 78 | /** 79 | * API v2 Session Tokens 80 | * @type {object} 81 | * @private 82 | */ 83 | this._v2SessionTokens = []; 84 | 85 | /** 86 | * API request queue 87 | * @type {object} 88 | * @private 89 | */ 90 | this._requestQueue = []; 91 | 92 | /** 93 | * Uploader instance 94 | * @type {MFUploader} 95 | * @private 96 | */ 97 | this._uploader; 98 | 99 | /** 100 | * Action token for the uploader 101 | * @type {string} 102 | * @private 103 | */ 104 | this._actionToken; 105 | 106 | /** 107 | * Asynchronously loads the necessary resources before performing an upload 108 | * @param {(object|function)=} callback The success and/or error callback functions 109 | * @private 110 | */ 111 | this._loadUploader = function(callback) { 112 | callback = this._parseCallback(callback); 113 | var self = this; 114 | 115 | // The uploader calls this global function when it is ready 116 | window.mfUploaderReady = function() { 117 | callback.success(); 118 | }; 119 | 120 | var id = 'mf-uploader'; 121 | // Script has already been injected, nothing to do here 122 | if(document.getElementById(id)) { 123 | return; 124 | } 125 | 126 | // Inject the uploader script 127 | var target = document.getElementsByTagName('script')[0]; 128 | var script = document.createElement('script'); 129 | script.id = id; 130 | script.async = true; 131 | script.src = this._UPLOADER_RESOURCE_PATH + 'mfuploader.js'; 132 | target.parentNode.insertBefore(script, target); 133 | }; 134 | 135 | /** 136 | * Conforms callback input into a standard for internal use 137 | * @param {(object|function)=} callback The success and/or error callback functions 138 | * @returns {object} Conformed callback 139 | * @private 140 | */ 141 | this._parseCallback = function(callback) { 142 | if(typeof callback === 'function') { 143 | callback = { success: callback }; 144 | } 145 | return callback || {}; 146 | }; 147 | 148 | /** 149 | * Extend or update the current session token 150 | * @private 151 | */ 152 | this._renew = function() { 153 | /** @this MediaFire */ 154 | var callbackRenewToken = { 155 | success: function(data) { 156 | this._sessionToken = data.response.session_token; 157 | } 158 | }; 159 | 160 | var versionPath = this._API_VERSION ? this._API_VERSION + '/' : ''; 161 | this._get(this._API_PATH + versionPath + 'user/renew_session_token.php', null, callbackRenewToken, this); 162 | }; 163 | 164 | /** 165 | * Core XHR functionality 166 | * @param {string} url An absolute or relative url for the XHR 167 | * @param {object=} params Parameters to include with the request 168 | * @param {object=} callback The success and/or error callback functions 169 | * @param {*=} scope A scope to call the callback functions with 170 | * @private 171 | */ 172 | this._get = function(url, params, callback, scope) { 173 | // Create XHR 174 | var xhr = new XMLHttpRequest(), 175 | oThis = this; 176 | 177 | // Make sure params exists 178 | if(!params) { 179 | params = {}; 180 | } 181 | 182 | // Augment parameters 183 | params.response_format = 'json'; 184 | if(this._TOKEN_VERSION == 1 && this._sessionToken) { 185 | // v1 session token 186 | params.session_token = this._sessionToken; 187 | }else if(this._TOKEN_VERSION == 2){ 188 | // v2 session token 189 | var session = this._getAvailableSessionToken(); 190 | if(session){ // v2 session token found 191 | xhr.session = session; 192 | params = session.authenticateParams(url, params); 193 | }else{ // v2 session token not found 194 | if(this._v2SessionTokens.length>0){ // make sure we actually have some v2 session tokens to choose from 195 | this._requestQueue.push({ 196 | qUrl: url, 197 | qParams: params, 198 | qCallback: callback, 199 | qScope: scope 200 | }); 201 | return; 202 | }else{ // we haven't gotten any v2 session tokens yet, just use a v1 for now 203 | params.session_token = this._sessionToken; 204 | } 205 | } 206 | } 207 | 208 | // Construct parameters 209 | url += '?' + Object.keys(params).map(function(key) { 210 | return encodeURIComponent(key) + '=' + encodeURIComponent(params[key]); 211 | }).join('&'); 212 | 213 | // Handle callbacks 214 | xhr.onreadystatechange = function() { 215 | if (xhr.readyState === 4) { 216 | // Return raw response if we cannot parse JSON. 217 | var response = (typeof JSON === 'undefined') ? xhr.responseText : JSON.parse(xhr.responseText); 218 | if (xhr.status === 200) { 219 | // Success 220 | if(callback.success) { 221 | // handle v2 session token on return 222 | if(oThis._TOKEN_VERSION == 2){ 223 | // Secret key needs to be updated 224 | if(response.response.new_key === 'yes' && this.session) { 225 | this.session.updateSecret(); 226 | // A new session was created 227 | } else if(response.response.secret_key) { 228 | var newSession = new Session(response.response); 229 | oThis._v2SessionTokens.push(newSession); 230 | } 231 | } 232 | callback.success.call(scope, response, xhr); 233 | } 234 | } else { 235 | // Error 236 | if(callback.error) { 237 | callback.error.call(scope, response, xhr); 238 | } 239 | } 240 | oThis._processQueue(); 241 | } 242 | }; 243 | 244 | // Send request 245 | xhr.open('GET', url, true); 246 | xhr.send(null); 247 | }; 248 | 249 | /** 250 | * Generates an upload action token 251 | * @param {(object|function)=} callback The success and/or error callback functions 252 | * @private 253 | */ 254 | this._getUploadActionToken = function(callback) { 255 | var options = {type: 'upload', lifespan: 1440}; 256 | var versionPath = this._API_VERSION ? this._API_VERSION + '/' : ''; 257 | this._get(this._API_PATH + versionPath + 'user/get_action_token.php', options, this._parseCallback(callback), this); 258 | }; 259 | 260 | /** 261 | * Find an available v2 session token (returns Session object or false) 262 | * @private 263 | */ 264 | this._getAvailableSessionToken = function(callback) { 265 | for (var i = 0, len = this._v2SessionTokens.length; i < len; i++) { 266 | var session = this._v2SessionTokens[i]; 267 | // Found an available session, stop looking and mark this one unavailable 268 | if(session.available) { 269 | session.available = false; 270 | return session; 271 | } 272 | } 273 | return false; 274 | }; 275 | 276 | /** 277 | * If any calls in queue, run them 278 | * @private 279 | */ 280 | this._processQueue = function() { 281 | if(this._requestQueue.length>0){ 282 | var req = this._requestQueue[0]; 283 | this._get(req.qUrl, req.qParams, req.qCallback, req.qScope); 284 | this._requestQueue.splice(0,1); 285 | } 286 | }; 287 | 288 | /** 289 | * If any calls in queue, run them 290 | * @private 291 | */ 292 | this._getV2SessionTokens = function() { 293 | if(this._sessionToken && this._v2SessionTokens.length == 0){ 294 | var versionPath = this._API_VERSION ? this._API_VERSION + '/' : ''; 295 | for(var x=0; x>16)+(b>>16)+(c>>16);return d<<16|65535&c}function c(a,b){return a<>>32-b}function d(a,d,e,f,g,h){return b(c(b(b(d,a),b(f,h)),g),e)}function e(a,b,c,e,f,g,h){return d(b&c|~b&e,a,b,f,g,h)}function f(a,b,c,e,f,g,h){return d(b&e|c&~e,a,b,f,g,h)}function g(a,b,c,e,f,g,h){return d(b^c^e,a,b,f,g,h)}function h(a,b,c,e,f,g,h){return d(c^(b|~e),a,b,f,g,h)}function i(a,c){a[c>>5]|=128<>>9<<4)+14]=c;var d,i,j,k,l,m=1732584193,n=-271733879,o=-1732584194,p=271733878;for(d=0;d>5]>>>b%32&255);return c}function k(a){var b,c=[];for(c[(a.length>>2)-1]=void 0,b=0;b>5]|=(255&a.charCodeAt(b/8))<16&&(e=i(e,8*a.length)),c=0;16>c;c+=1)f[c]=909522486^e[c],g[c]=1549556828^e[c];return d=i(f.concat(k(b)),512+8*b.length),j(i(g.concat(d),640))}function n(a){var b,c,d="0123456789abcdef",e="";for(c=0;c>>4&15)+d.charAt(15&b);return e}function o(a){return unescape(encodeURIComponent(a))}function p(a){return l(o(a))}function q(a){return n(p(a))}function r(a,b){return m(o(a),o(b))}function s(a,b){return n(r(a,b))}function t(a,b,c){return b?c?r(b,a):s(b,a):c?p(a):q(a)}"function"==typeof define&&define.amd?define(function(){return t}):a.md5=t}(this); 515 | // usage Session.md5(string, key, raw) // key and raw are optional 516 | } 517 | 518 | /** 519 | * Updates a the secret key of a Session. 520 | */ 521 | Session.prototype.updateSecret = function() { 522 | this.available = true; 523 | this.secretKey = (this.secretKey * 16807) % 2147483647; 524 | }; 525 | 526 | /** 527 | * Updates a the secret key of a Session. 528 | * @param {string} url of http request 529 | * @param {object} params 530 | */ 531 | Session.prototype.authenticateParams = function(requestUrl, params) { 532 | // Append session token first, it's used in url verification 533 | params.session_token = this.sessionToken; 534 | // Build url exactly how it will be sent 535 | var url = this._createUrl(requestUrl, params, true); 536 | // Append signature hash 537 | params.signature = this.md5((this.secretKey % 256) + this.initTime + url); 538 | return params; 539 | }; 540 | 541 | window.MF = MediaFire; 542 | })(); 543 | 544 | /** 545 | * Copyright (c) 2013 Sam Rijs (http://awesam.de) 546 | * Licensed under the MIT License (MIT) 547 | */ 548 | (function(){ 549 | if(typeof FileReaderSync!=='undefined'){var reader=new FileReaderSync(),hasher=new Rusha(4*1024*1024);self.onmessage=function onMessage(event){var hash,data=event.data.data;if(data instanceof Blob){try{data=reader.readAsBinaryString(data);}catch(e){self.postMessage({id:event.data.id,error:e.name});return;}} 550 | hash=hasher.digest(data);self.postMessage({id:event.data.id,hash:hash});};} 551 | function Rusha(sizeHint){"use strict";var self={fill:0};var padlen=function(len){return len+1+((len)%64<56?56:56+64)-(len)%64+8;};var padZeroes=function(bin,len){for(var i=len>>2;i>2]|=0x80<<(24-(len%4<<3));bin[(((len>>2)+2)&~0x0f)+15]=len<<3;};var convStr=function(str,bin,len){var i;for(i=0;i>2]=str.charCodeAt(i)<<24|str.charCodeAt(i+1)<<16|str.charCodeAt(i+2)<<8|str.charCodeAt(i+3);}};var convBuf=function(buf,bin,len){var i,m=len%4,j=len-m;for(i=0;i>2]=buf[i]<<24|buf[i+1]<<16|buf[i+2]<<8|buf[i+3];} 552 | switch(m){case 0:bin[j>>2]|=buf[j+3];case 3:bin[j>>2]|=buf[j+2]<<8;case 2:bin[j>>2]|=buf[j+1]<<16;case 1:bin[j>>2]|=buf[j]<<24;}};var conv=function(data,bin,len){if(typeof data==='string'){return convStr(data,bin,len);}else if(data instanceof Array||(typeof global!=='undefined'&&typeof global.Buffer!=='undefined'&&data instanceof global.Buffer)){return convBuf(data,bin,len);}else if(data instanceof ArrayBuffer){return convBuf(new Uint8Array(data),bin,len);}else if(data.buffer instanceof ArrayBuffer){return convBuf(new Uint8Array(data.buffer),bin,len);}else{throw new Error('Unsupported data type.');}};var hex=function(binarray){var i,x,hex_tab="0123456789abcdef",res=[];for(i=0;i>28)&0xF)+ 553 | hex_tab.charAt((x>>24)&0xF)+hex_tab.charAt((x>>20)&0xF)+hex_tab.charAt((x>>16)&0xF)+hex_tab.charAt((x>>12)&0xF)+hex_tab.charAt((x>>8)&0xF)+hex_tab.charAt((x>>4)&0xF)+hex_tab.charAt((x>>0)&0xF);} 554 | return res.join('');};var nextPow2=function(v){var p=1;while(pself.sizeHint){resize(len);} 555 | var view=new Int32Array(self.heap,0,padlen(len)>>2);padZeroes(view,len);conv(str,view,len);padData(view,len);coreCall(view.length);return new Int32Array(self.heap,0,5);};this.digest=this.digestFromString=this.digestFromBuffer=this.digestFromArrayBuffer=function(str){return hex(rawDigest(str));};};function RushaCore(stdlib,foreign,heap){"use asm";var H=new stdlib.Int32Array(heap);function hash(k){k=k|0;var i=0,j=0,y0=0,z0=0,y1=0,z1=0,y2=0,z2=0,y3=0,z3=0,y4=0,z4=0,t0=0,t1=0;y0=H[k+0<<2>>2]|0;y1=H[k+1<<2>>2]|0;y2=H[k+2<<2>>2]|0;y3=H[k+3<<2>>2]|0;y4=H[k+4<<2>>2]|0;for(i=0;(i|0)<(k|0);i=i+16|0){z0=y0;z1=y1;z2=y2;z3=y3;z4=y4;for(j=0;(j|0)<16;j=j+1|0){t1=H[i+j<<2>>2]|0;t0=((((y0)<<5|(y0)>>>27)+(y1&y2|~y1&y3)|0)+((t1+y4|0)+1518500249|0)|0);y4=y3;y3=y2;y2=((y1)<<30|(y1)>>>2);y1=y0;y0=t0;H[k+j<<2>>2]=t1;} 556 | for(j=k+16|0;(j|0)<(k+20|0);j=j+1|0){t1=(((H[j-3<<2>>2]^H[j-8<<2>>2]^H[j-14<<2>>2]^H[j-16<<2>>2])<<1|(H[j-3<<2>>2]^H[j-8<<2>>2]^H[j-14<<2>>2]^H[j-16<<2>>2])>>>31));t0=((((y0)<<5|(y0)>>>27)+(y1&y2|~y1&y3)|0)+((t1+y4|0)+1518500249|0)|0);y4=y3;y3=y2;y2=((y1)<<30|(y1)>>>2);y1=y0;y0=t0;H[j<<2>>2]=t1;} 557 | for(j=k+20|0;(j|0)<(k+40|0);j=j+1|0){t1=(((H[j-3<<2>>2]^H[j-8<<2>>2]^H[j-14<<2>>2]^H[j-16<<2>>2])<<1|(H[j-3<<2>>2]^H[j-8<<2>>2]^H[j-14<<2>>2]^H[j-16<<2>>2])>>>31));t0=((((y0)<<5|(y0)>>>27)+(y1^y2^y3)|0)+((t1+y4|0)+1859775393|0)|0);y4=y3;y3=y2;y2=((y1)<<30|(y1)>>>2);y1=y0;y0=t0;H[j<<2>>2]=t1;} 558 | for(j=k+40|0;(j|0)<(k+60|0);j=j+1|0){t1=(((H[j-3<<2>>2]^H[j-8<<2>>2]^H[j-14<<2>>2]^H[j-16<<2>>2])<<1|(H[j-3<<2>>2]^H[j-8<<2>>2]^H[j-14<<2>>2]^H[j-16<<2>>2])>>>31));t0=((((y0)<<5|(y0)>>>27)+(y1&y2|y1&y3|y2&y3)|0)+((t1+y4|0)-1894007588|0)|0);y4=y3;y3=y2;y2=((y1)<<30|(y1)>>>2);y1=y0;y0=t0;H[j<<2>>2]=t1;} 559 | for(j=k+60|0;(j|0)<(k+80|0);j=j+1|0){t1=(((H[j-3<<2>>2]^H[j-8<<2>>2]^H[j-14<<2>>2]^H[j-16<<2>>2])<<1|(H[j-3<<2>>2]^H[j-8<<2>>2]^H[j-14<<2>>2]^H[j-16<<2>>2])>>>31));t0=((((y0)<<5|(y0)>>>27)+(y1^y2^y3)|0)+((t1+y4|0)-899497514|0)|0);y4=y3;y3=y2;y2=((y1)<<30|(y1)>>>2);y1=y0;y0=t0;H[j<<2>>2]=t1;} 560 | y0=y0+z0|0;y1=y1+z1|0;y2=y2+z2|0;y3=y3+z3|0;y4=y4+z4|0;}H[0]=y0;H[1]=y1;H[2]=y2;H[3]=y3;H[4]=y4;}return{hash:hash};} 561 | window.SHA1=Rusha; 562 | })(); 563 | --------------------------------------------------------------------------------