Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgeajimenezl committed Nov 29, 2022
2 parents 3fdd5c9 + b67d548 commit cc7ba51
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 13 deletions.
2 changes: 1 addition & 1 deletion animeflv/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from .animeflv import AnimeFLV

__version__ = "0.2.1"
__version__ = "0.2.2"
__title__ = "animeflv"
__author__ = "Jorge Alejandro Jiménez Luna"
__license__ = "MIT"
Expand Down
26 changes: 22 additions & 4 deletions animeflv/animeflv.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,23 @@
from .exception import AnimeFLVParseError


def removeprefix(str: str, prefix: str) -> str:
"""
Remove the prefix of a given string if it contains that
prefix for compatability with Python >3.9
:param _str: string to remove prefix from.
:param episode: prefix to remove from the string.
:rtype: str
"""

if type(str) is type(prefix):
if str.startswith(prefix):
return str[len(prefix) :]
else:
return str[:]


def parse_table(table: Tag):
columns = list([x.string for x in table.thead.tr.find_all("th")])
rows = []
Expand Down Expand Up @@ -218,7 +235,7 @@ def get_latest_episodes(self) -> List[Dict[str, str]]:
ret.append(
{
"id": id,
"anime": anime.removeprefix("/ver/"),
"anime": removeprefix(anime, "/ver/"),
"image_preview": f"{BASE_URL}{element.select_one('span.Image img')['src']}",
}
)
Expand Down Expand Up @@ -277,9 +294,10 @@ def _process_anime_list_info(self, elements: ResultSet) -> List[Dict[str, str]]:
try:
ret.append(
{
"id": element.select_one("div.Description a.Button")["href"][
1:
].removeprefix("anime/"),
"id": removeprefix(
element.select_one("div.Description a.Button")["href"][1:],
"anime/",
),
"title": element.select_one("a h3").string,
"poster": (
element.select_one("a div.Image figure img").get(
Expand Down
17 changes: 9 additions & 8 deletions tests.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
import unittest
import time
from animeflv import AnimeFLV
from cloudscraper.exceptions import CloudflareChallengeError


def wrap_request(func, *args, count: int = 5):
notes = []

while True:
for _ in range(count):
try:
r = func(*args)
return r
except CloudflareChallengeError:
# cloudscraper will error because this feature isn't free, ignore this for the Tests
return ["Lorem Ipsum"]
except Exception as e:
if count > 0:
count -= 1
notes.append(e)

time.sleep(5)
else:
raise Exception([e] + notes)
notes.append(e)
time.sleep(5)
else: # If the loop doesn't `break`, raise the Exception
raise Exception(notes)


class AnimeFLVTest(unittest.TestCase):
Expand Down

0 comments on commit cc7ba51

Please sign in to comment.