Skip to content

Commit

Permalink
Merge pull request #78 from cnovel/AddUserAgent
Browse files Browse the repository at this point in the history
Add User agent
  • Loading branch information
cnovel authored Jul 21, 2024
2 parents cb2b849 + c60cb49 commit e705be9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
pbd_version = '0.8'
pbd_version = '0.10.0'
12 changes: 7 additions & 5 deletions src/bulk_downloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,10 @@ def download_with_resume(url: str, path: str, cb: Callback = None) -> bool:

if cb and cb.is_cancelled():
return False

s = requests.Session()
s.headers["User-Agent"] = f"PodcastBulkDownloader/{pbd_version}"
try:
r = requests.head(url, allow_redirects=True)
r = s.head(url, allow_redirects=True)
except requests.exceptions as e:
logging.error(e)
return False
Expand All @@ -70,8 +71,8 @@ def download_with_resume(url: str, path: str, cb: Callback = None) -> bool:
if cb and cb.is_cancelled():
return False
resume_header = {'Range': 'bytes=%d-' % last_byte}
resume_request = requests.get(url, headers=resume_header, stream=True,
verify=True, allow_redirects=True)
resume_request = s.get(url, headers=resume_header, stream=True,
verify=True, allow_redirects=True)
for data in resume_request.iter_content(chunk_size):
last_byte += len(data)
if cb and cb.is_cancelled():
Expand Down Expand Up @@ -261,7 +262,8 @@ def list_mp3(self, cb: Callback = None, verbose: bool = False) -> List[Episode]:
if self._is_url():
try:
headers = {'Accept': '*/*',
'User-Agent': 'PodcastBulkDownloader v' + pbd_version}
'User-Agent':
f'PodcastBulkDownloader/{pbd_version}'}
r = requests.get(self._url, headers=headers)
except requests.RequestException as exc:
err_str = 'Failed to connect to URL ({})'.format(exc)
Expand Down

0 comments on commit e705be9

Please sign in to comment.