Skip to content

Commit

Permalink
Fix download error
Browse files Browse the repository at this point in the history
  • Loading branch information
Simatwa committed Jul 8, 2023
1 parent 9051609 commit 671b853
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 8 deletions.
1 change: 1 addition & 0 deletions Docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,4 @@
# v1.0.0
**What's new?**
- User warning on possible download failure
- Fake-headers on download - minimize failures
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<p align="center">
<a href="https://github.com/Simatwa/y2mate-api/actions/workflows/python-test.yml"><img src="https://github.com/Simatwa/y2mate-api/actions/workflows/python-test.yml/badge.svg" alt="Python Test"/></a>
<a href="LICENSE"><img alt="License" src="https://img.shields.io/static/v1?logo=GPL&color=Blue&message=MIT&label=License"/></a>
<a href="https://pypi.org/project/y2mate-api"><img alt="PyPi" src="https://img.shields.io/static/v1?logo=pypi&label=Pypi&message=v0.0.9&color=green"/></a>
<a href="https://pypi.org/project/y2mate-api"><img alt="PyPi" src="https://img.shields.io/static/v1?logo=pypi&label=Pypi&message=v1.0.0&color=green"/></a>
<a href="https://github.com/psf/black"><img alt="Black" src="https://img.shields.io/static/v1?logo=Black&label=Code-style&message=Black"/></a>
<a href="#"><img alt="Passing" src="https://img.shields.io/static/v1?logo=Docs&label=Docs&message=Passing&color=green"/></a>
<a href="#"><img alt="coverage" src="https://img.shields.io/static/v1?logo=Coverage&label=Coverage&message=90%&color=yellowgreen"/></a>
Expand Down
9 changes: 5 additions & 4 deletions y2mate_api/downloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
second_query,
third_query,
session,
headers,
)
from tqdm import tqdm
from colorama import Fore
Expand Down Expand Up @@ -70,10 +71,10 @@ def __init__(
def __str__(self):
return self.query

def __enter__(self):
pass
def __enter__(self, *args, **kwargs):
return self

def __exit__(self):
def __exit__(self, *args, **kwargs):
self.vitems.clear()
self.total = 1

Expand Down Expand Up @@ -375,7 +376,7 @@ def save(
), "The video selected does not support that quality, try lower qualities."
if third_dict.get("mess"):
logging.warning(third_dict.get("mess"))
resp = requests.get(third_dict["dlink"], stream=True)
resp = requests.get(third_dict["dlink"], stream=True, headers=headers)
default_content_length = 1000000000
size_in_bytes = int(
resp.headers.get("content-length", default_content_length)
Expand Down
7 changes: 4 additions & 3 deletions y2mate_api/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"User-Agent": "Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Mobile Safari/537.36",
"Accept-Encoding": "gzip, deflate, br",
"Accept-Language": "en-US,en;q=0.9",
"referer": "https://y2mate.com",
}

session.headers.update(headers)
Expand Down Expand Up @@ -277,7 +278,7 @@ def __main__(self, *args, **kwargs):
def __enter__(self, *args, **kwargs):
return self.__main__(*args, **kwargs)

def __exit__(self):
def __exit__(self, *args, **kwargs):
self.processed = False

def main(self, item_no: int = 0, timeout: int = 30):
Expand Down Expand Up @@ -337,10 +338,10 @@ def __init__(self, query_two: object):
def __call__(self, *args, **kwargs):
return self.main(*args, **kwargs)

def __enter__(self):
def __enter__(self, *args, **kwargs):
return self

def __exit__(self):
def __exit__(self, *args, **kwargs):
pass

def __str__(self):
Expand Down

0 comments on commit 671b853

Please sign in to comment.