Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scrape anime and play episodes on browser without ads from terminal #5975

Merged
merged 9 commits into from
Feb 1, 2022

Conversation

saptarshi1996
Copy link
Contributor

Describe your change:

  • Add an algorithm?
  • Fix a bug or typo in an existing algorithm?
  • Documentation change?

Checklist:

  • I have read CONTRIBUTING.md.
  • This pull request is all my own work -- I have not plagiarized.
  • I know that pull requests will not be merged if they fail the automated tests.
  • This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms.
  • All new Python files are placed inside an existing directory.
  • All filenames are in all lowercase characters with no spaces or dashes.
  • All functions and variable names follow Python naming conventions.
  • All function parameters and return values are annotated with Python type hints.
  • All functions have doctests that pass the automated testing.
  • All new algorithms have a URL in its comments that points to Wikipedia or other similar explanation.
  • If this pull request resolves one or more open issues then the commit message contains Fixes: #{$ISSUE_NO}.

@ghost ghost added the require tests Tests [doctest/unittest/pytest] are required label Feb 1, 2022
Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Click here to look at the relevant links ⬇️

🔗 Relevant Links

Repository:

Python:

Automated review generated by algorithms-keeper. If there's any problem regarding this review, please open an issue about it.

algorithms-keeper commands and options

algorithms-keeper actions can be triggered by commenting on this PR:

  • @algorithms-keeper review to trigger the checks for only added pull request files
  • @algorithms-keeper review-all to trigger the checks for all the pull request files, including the modified files. As we cannot post review comments on lines not part of the diff, this command will post all the messages in one comment.

NOTE: Commands are in beta and so this feature is restricted only to a member or owner of the organization.

)
chosen_anime = anime_list[anime_choice - 1]
print(
"You chose {}. Searching for episodes...".format(chosen_anime["title"])
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As mentioned in the Contributing Guidelines, please do not use printf style formatting or str.format(). Use f-string instead to be more readable and efficient.

else:
print(f"Found {len(episode_list)} results: ")
for (i, episode) in enumerate(episode_list):
print(("{}. {}").format(i + 1, episode["title"]))
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As mentioned in the Contributing Guidelines, please do not use printf style formatting or str.format(). Use f-string instead to be more readable and efficient.

input("\nChoose an episode by serial no: ").strip()
)
chosen_episode = episode_list[episode_choice - 1]
print("You chose {}. Searching...".format(chosen_episode["title"]))
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As mentioned in the Contributing Guidelines, please do not use printf style formatting or str.format(). Use f-string instead to be more readable and efficient.

@ghost ghost added the awaiting reviews This PR is ready to be reviewed label Feb 1, 2022
@ghost ghost removed the require tests Tests [doctest/unittest/pytest] are required label Feb 1, 2022
@@ -0,0 +1,203 @@
from urllib.error import HTTPError
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
from urllib.error import HTTPError
from requests.exceptions import HTTPError, RequestException

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed with from requests.exceptions import RequestException


return anime_list

except (requests.exceptions.RequestException, HTTPError, TypeError) as e:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
except (requests.exceptions.RequestException, HTTPError, TypeError) as e:
except (HTTPError, RequestException, TypeError) as e:

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed to RequestException

[list]: [List of animes]
"""

try:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

try / except block should be just around critical areas of code. They should not be 30 lines long!!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed the long try catches with critical ones

KeyError,
NotFoundErr,
TypeError,
requests.exceptions.RequestException,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Long try / except blocks lead to many different exceptions which confuses the reader of the code. It also slows down debugging when one of them is raised.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed multiple exceptions

@ghost ghost added awaiting changes A maintainer has requested changes to this PR and removed awaiting reviews This PR is ready to be reviewed labels Feb 1, 2022
@ghost ghost added awaiting reviews This PR is ready to be reviewed and removed awaiting changes A maintainer has requested changes to this PR labels Feb 1, 2022
@saptarshi1996 saptarshi1996 requested a review from cclauss February 1, 2022 21:41
@saptarshi1996
Copy link
Contributor Author

@cclauss . I have made the changes

Comment on lines 41 to 42
except RequestException as e:
raise e
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no need to catch an Exception if you are only going to raise the same Exception unmodified.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok. i've used response.raise_for_status() instead.

@saptarshi1996 saptarshi1996 requested a review from cclauss February 1, 2022 21:53
Comment on lines 107 to 115
for children in episode_page_li:
try:
if not isinstance(children, NavigableString):
episode_list.append(
{
"title": children.find("div", {"class": "name"}).text.replace(
" ", ""
),
"url": children.find("a")["href"],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It confuses the reader that children is plural yet these items are singular. It is easier to understand when each item is an episode...

Suggested change
for children in episode_page_li:
try:
if not isinstance(children, NavigableString):
episode_list.append(
{
"title": children.find("div", {"class": "name"}).text.replace(
" ", ""
),
"url": children.find("a")["href"],
for episode in episode_page_li:
try:
if not isinstance(episode, NavigableString):
episode_list.append(
{
"title": episode.find("div", {"class": "name"}).text.replace(
" ", ""
),
"url": episode.find("a")["href"],

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for episode in episode_page_li:
for anime in anime_li:
Like this now


"""[summary]

This function will take an url and
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
This function will take an url and
Take an url and


"""[summary]

This function will take an url and
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
This function will take an url and
Take an url and

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed them

Comment on lines 193 to 194
except (ValueError, IndexError, TypeError) as e:
raise e
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can lose the try / except if we are not going to handle the errors.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed the block.

@saptarshi1996 saptarshi1996 requested a review from cclauss February 1, 2022 22:06
Comment on lines +33 to +35
response = requests.get(
search_url, headers={"UserAgent": UserAgent().chrome}
) # request the url.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't wrap a line just for a comment.

Suggested change
response = requests.get(
search_url, headers={"UserAgent": UserAgent().chrome}
) # request the url.
# request the url.
response = requests.get(search_url, headers={"UserAgent": UserAgent().chrome})

@ghost ghost removed the awaiting reviews This PR is ready to be reviewed label Feb 1, 2022
@cclauss cclauss merged commit d28ac64 into TheAlgorithms:master Feb 1, 2022
@saptarshi1996 saptarshi1996 deleted the download-anime-url branch February 1, 2022 22:26
@saptarshi1996 saptarshi1996 restored the download-anime-url branch February 1, 2022 22:26
@saptarshi1996 saptarshi1996 deleted the download-anime-url branch February 1, 2022 22:26
@saptarshi1996 saptarshi1996 restored the download-anime-url branch February 1, 2022 22:26
@saptarshi1996
Copy link
Contributor Author

Thank you @cclauss

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants