Browse Source

Hotfix for an issue with multi-level directory creation

Hotfix for outright broken interaction with mediafire folder downloader and the main function

Known bugs:
- Too many downloads on Mediafire.com will result into Connection Reset
master
pleyar 3 years ago
parent
commit
313cc65bef
1 changed files with 10 additions and 12 deletions
  1. 10
    12
      filesfm.py

+ 10
- 12
filesfm.py View File

@@ -37,22 +37,20 @@ def _download_file(link, file_link, additional_header=None, additional_fold=''):
else:
_declare_opener([('Referer', link),])
with urllib.request.urlopen(file_link) as response:
folder = base_folder+additional_fold
Buffy = folder.split('/')
buf = ''
for i in range(len(Buffy)-1):
buf += Buffy[i] + '/'
check_folder(buf)
try:
_, params = cgi.parse_header(response.headers.get('Content-Disposition', ''))
print('Downloading file '+params['filename']+'...')
out_file = open(base_folder+additional_fold+params['filename'], 'wb')
out_file = open(folder+params['filename'], 'wb')
except KeyError:
filename = unquote(os.path.basename(urlparse(file_link).path))
print('Downloading file '+filename+'...')
out_file = open(base_folder+additional_fold+filename, 'wb')
except FileNotFoundError:
folder = base_folder+additional_fold
folder = folder.split('/')
buf = ''
for i in range(len(folder)):
buf += folder[i] + '/'
check_folder(buf)
out_file = open(folder+params['filename'], 'wb')
out_file = open(folder+filename, 'wb')
shutil.copyfileobj(response, out_file)
except ValueError:
raise ValueError
@@ -130,7 +128,7 @@ def __mediafire_folder(parsed, link):

_declare_opener([('Referer', link),('Content-Type','application/json')])
folder_info = get_json('https://www.mediafire.com/api/1.4/folder/get_info.php',(('folder_key', folder_key), ('response_format', 'json'), ('recursive','yes')))
file_array = __mediafire_crawler(folder_key, folder_info['response']['folder_info']['name']+'/',link)
__mediafire_crawler(folder_key, folder_info['response']['folder_info']['name']+'/',link)
return 0

def __mediafire_file(parsed, link):
@@ -168,7 +166,7 @@ def _parse_files(parsed, link, __func_host): #this function is intended for fold
print('Errored index, continuing...')
continue
_download_file(link,pull)
elif result == 0:
elif file_array == 0:
return 0
else:
for i in file_array:

Loading…
Cancel
Save