2022-03-14 09:16:22 +03:00
|
|
|
from typing import Optional
|
2019-05-04 22:38:06 +03:00
|
|
|
|
2022-03-14 09:16:22 +03:00
|
|
|
from ..settings import option
|
|
|
|
import requests
|
2019-05-04 22:38:06 +03:00
|
|
|
|
|
|
|
|
|
|
|
def torrent_file_fetch(url, referer, cookies):
|
|
|
|
headers = {
|
2022-03-14 09:16:22 +03:00
|
|
|
'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) '
|
|
|
|
'Chrome/37.0.2062.124 YaBrowser/14.10.2062.12061 Safari/537.36',
|
2019-05-04 22:38:06 +03:00
|
|
|
'Referer': referer
|
2022-03-14 09:16:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
resp = requests.get(url, cookies=cookies, headers=headers, proxies=proxies())
|
2019-05-04 22:38:06 +03:00
|
|
|
if resp.ok:
|
|
|
|
return resp.content
|
|
|
|
else:
|
|
|
|
return None
|
|
|
|
|
2022-03-14 09:16:22 +03:00
|
|
|
|
|
|
|
def proxies():
|
|
|
|
if option.get_boolean('use_socks'):
|
|
|
|
return {
|
|
|
|
'http': f'socks5://{option["socks_ip"]}:{option["socks_port"]}',
|
|
|
|
'https': f'socks5://{option["socks_ip"]}:{option["socks_port"]}'
|
|
|
|
}
|
|
|
|
else:
|
|
|
|
return None
|