Created
February 2, 2016 03:57
-
-
Save hthuong09/a3fc331b6ab3df0887d0 to your computer and use it in GitHub Desktop.
Recursively get download link mediafire folder
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from mediafire import MediaFireApi | |
import humanfriendly | |
import sys | |
import wget | |
api = MediaFireApi() | |
#folder_key = sys.argv[1] | |
folder_key = 'oct0x6rwhtkks'; | |
response = api.request("user/get_session_token", { | |
"application_id": '*filldis*', | |
"email": '*filldis*', | |
"password": '*filldis*', | |
"signature": '*filldis*' | |
}) | |
session_token = response['session_token'] | |
def get_folder_content(folder_key): | |
print('Getting folder', folder_key, 'info...') | |
folders = get_folder_list(folder_key) | |
print('Found', len(folders), 'folders') | |
files = get_file_list(folder_key) | |
print('Found', len(files), 'files') | |
if (len(files) > 0): | |
FILE_LIST.extend(files) | |
for folder in folders: | |
get_folder_content(folder['folderkey']) | |
def get_folder_list(folder_key): | |
folders = [] | |
response = api.request("folder/get_content", { | |
"folder_key": folder_key | |
}) | |
for folder in response['folder_content']['folders']: | |
folders.append({ | |
"name": folder['name'], | |
"folderkey": folder['folderkey'], | |
"folder_count": folder['folder_count'], | |
"file_count": folder['file_count'] | |
}) | |
return folders | |
def get_file_list(folder_key): | |
files = [] | |
response = api.request("folder/get_content", { | |
"folder_key": folder_key, | |
"content_type": "files" | |
}) | |
for file in response['folder_content']['files']: | |
files.append({ | |
'filename': file['filename'], | |
'quickkey': file['quickkey'], | |
'size': humanfriendly.format_size(int(file['size'])), | |
'download_link': file['links']['normal_download'] | |
}) | |
return files | |
FILE_LIST = [] | |
get_folder_content(folder_key) | |
for file in FILE_LIST: | |
response = api.request('file/get_links', { | |
"session_token": session_token, | |
"quick_key": file['quickkey'], | |
"signature": '*filldis*', | |
"link_type": 'direct_download' | |
}) | |
link = response['links'][0]['direct_download'] | |
fo = open("links.html", "a+") | |
fo.write('<a href="'+link+'">'+link+'</a><br />\n'); | |
fo.close() | |
print(response['direct_download_free_bandwidth']) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I need that in javascript
thank you