mirror of
https://gitea.phreedom.club/localhost_frssoft/funkwlmpv
synced 2024-11-16 04:03:01 +00:00
23 lines
628 B
Python
23 lines
628 B
Python
|
from src.fw_api import s
|
||
|
from urllib.parse import unquote
|
||
|
|
||
|
|
||
|
def get_remote_file_name(url):
|
||
|
'''This function return filename by content-disposition header'''
|
||
|
r = s.head(url)
|
||
|
content_dispos = r.headers.get('content-disposition')
|
||
|
if content_dispos.startswith('attachment; filename*=UTF-8\'\''):
|
||
|
return unquote(content_dispos.split('attachment; filename*=UTF-8\'\'')[-1])
|
||
|
|
||
|
|
||
|
def download_track(url, name=None):
|
||
|
r = s.get(url)
|
||
|
if not name:
|
||
|
name = get_remote_file_name(url)
|
||
|
if not name:
|
||
|
name = url.split(r'/')[-1]
|
||
|
|
||
|
with open(name, 'wb') as f:
|
||
|
f.write(r.content)
|
||
|
|