Skip to content

Commit

Permalink
retrive metadata using GET if HEAD request fails(#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
mjishnu committed Apr 6, 2024
1 parent ec57533 commit fd06bf2
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions pypdl/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,15 +112,19 @@ def _multi_thread(self, segments, segement_table):
def _get_header(self, url):
kwargs = self._kwargs.copy()
kwargs.pop("params", None)
response = requests.head(url, **kwargs)

if response.status_code != 200:
self._interrupt.set()
raise ConnectionError(
f"Server Returned: {response.reason}({response.status_code}), Invalid URL"
)
with requests.head(url, **kwargs) as response:
if response.status_code == 200:
return response.headers

with requests.get(url, stream=True, **self._kwargs) as response:
if response.status_code == 200:
return response.headers

return response.headers
self._interrupt.set()
raise ConnectionError(
f"Server Returned: {response.reason}({response.status_code}), Invalid URL"
)

def _get_info(self, url, file_path, multithread, etag):
header = self._get_header(url)
Expand Down

0 comments on commit fd06bf2

Please sign in to comment.