mirror of
https://github.com/indetectables-net/toolkit.git
synced 2026-10-30 04:10:51 +00:00
Add SF dynamic url dl
This commit is contained in:
1 parent
86cf4907ad
commit
8accee1b21
1 file changed
+28
-10
+28
-10
@@ -16,15 +16,25 @@ import py7zr
|
|||||||
|
|
||||||
|
|
||||||
# Helpers functions
|
# Helpers functions
|
||||||
def get_filename_from_url(url):
|
def get_filename_from_url(name, url):
|
||||||
fragment_removed = url.split('#')[0] # keep to left of first #
|
sourceforge_dynamic_url = config.get(name, 'sourceforge_dynamic_url', fallback=None)
|
||||||
query_string_removed = fragment_removed.split('?')[0]
|
if not sourceforge_dynamic_url:
|
||||||
scheme_removed = query_string_removed.split('://')[-1].split(':')[-1]
|
fragment_removed = url.split('#')[0] # keep to left of first #
|
||||||
|
query_string_removed = fragment_removed.split('?')[0]
|
||||||
|
scheme_removed = query_string_removed.split('://')[-1].split(':')[-1]
|
||||||
|
|
||||||
if scheme_removed.find('/') == -1:
|
if scheme_removed.find('/') == -1:
|
||||||
return ''
|
return ''
|
||||||
|
|
||||||
return os.path.basename(scheme_removed)
|
return os.path.basename(scheme_removed)
|
||||||
|
else:
|
||||||
|
# needed for sourceforge.net download from specific folder
|
||||||
|
if url.split('/')[-1] == 'download':
|
||||||
|
url_transform = url.strip('/download')
|
||||||
|
new_filename = url_transform.split('/')[-1]
|
||||||
|
else:
|
||||||
|
return ''
|
||||||
|
return os.path.basename(new_filename)
|
||||||
|
|
||||||
|
|
||||||
def cleanup_folder(path):
|
def cleanup_folder(path):
|
||||||
@@ -104,6 +114,8 @@ def get_download_url(name, html, from_url):
|
|||||||
# case 1: if update_url is set... download it!
|
# case 1: if update_url is set... download it!
|
||||||
update_download_url = config.get(name, 'update_url', fallback=None)
|
update_download_url = config.get(name, 'update_url', fallback=None)
|
||||||
re_download = config.get(name, 're_download', fallback=None)
|
re_download = config.get(name, 're_download', fallback=None)
|
||||||
|
sourceforge_dynamic_url = config.get(name, 'sourceforge_dynamic_url', fallback=None)
|
||||||
|
re_version = config.get(name, 're_version')
|
||||||
|
|
||||||
# case 2: if update_url is not set, scrape the link from html (ex: nirsoft)
|
# case 2: if update_url is not set, scrape the link from html (ex: nirsoft)
|
||||||
if not update_download_url:
|
if not update_download_url:
|
||||||
@@ -121,8 +133,14 @@ def get_download_url(name, html, from_url):
|
|||||||
html_regex_download = re.findall(re_download, html)
|
html_regex_download = re.findall(re_download, html)
|
||||||
if not html_regex_download:
|
if not html_regex_download:
|
||||||
raise Exception('{0}: re_download not match'.format(name))
|
raise Exception('{0}: re_download not match'.format(name))
|
||||||
|
if not sourceforge_dynamic_url:
|
||||||
update_download_url = '{0}{1}'.format(update_download_url, html_regex_download[0])
|
update_download_url = '{0}{1}'.format(update_download_url, html_regex_download[0])
|
||||||
|
else:
|
||||||
|
# sourceforge_dynamic_url download for specific folder /w regex
|
||||||
|
find_version = re.findall(re_version, html)
|
||||||
|
latest_re_version = find_version[0]
|
||||||
|
replace_version = re.findall(sourceforge_dynamic_url, update_download_url)
|
||||||
|
update_download_url = '{0}'.format(update_download_url.replace('.'.join(replace_version[0]), str(latest_re_version)))
|
||||||
|
|
||||||
if not update_download_url:
|
if not update_download_url:
|
||||||
raise Exception('{0}: update_download_url not generated!'.format(name))
|
raise Exception('{0}: update_download_url not generated!'.format(name))
|
||||||
@@ -132,7 +150,7 @@ def get_download_url(name, html, from_url):
|
|||||||
|
|
||||||
def download(name, url, download_path):
|
def download(name, url, download_path):
|
||||||
# prepare
|
# prepare
|
||||||
file_name = get_filename_from_url(url)
|
file_name = get_filename_from_url(name, url)
|
||||||
file_path = os.path.join(download_path, file_name)
|
file_path = os.path.join(download_path, file_name)
|
||||||
print('{0}: downloading update "{1}"'.format(name, file_name))
|
print('{0}: downloading update "{1}"'.format(name, file_name))
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user