Skip to content

Implemented youtube command#586

Closed
SuperMaZingCoder wants to merge 27 commits into
python-discord:mainfrom
SuperMaZingCoder:feature/youtube
Closed

Implemented youtube command#586
SuperMaZingCoder wants to merge 27 commits into
python-discord:mainfrom
SuperMaZingCoder:feature/youtube

Conversation

@SuperMaZingCoder
Copy link
Copy Markdown

Relevant Issues

Closes #585

Description

Implemented a new youtube cog which has a youtube (alias: yt) command to search youtube from a specified query. Additionally, there is a fifteen-second cooldown.

Reasoning

This allows users to share videos with each other and search for tutorials relevant to a conversation. I imagine staff might find this useful for linking tutorials that they recommend to other users.

Screenshots

image

image

Did you:

  • Join the Python Discord Community?
  • If dependencies have been added or updated, run pipenv lock?
  • Lint your code (pipenv run lint)?
  • Set the PR to allow edits from contributors?

Comment thread bot/exts/evergreen/youtube.py Outdated
Comment thread bot/exts/evergreen/youtube.py Outdated
Comment thread bot/exts/evergreen/youtube.py Outdated
Comment thread bot/exts/evergreen/youtube.py Outdated
Comment thread bot/exts/evergreen/youtube.py Outdated
Comment thread bot/exts/evergreen/youtube.py Outdated
Comment thread bot/exts/evergreen/youtube.py
Comment thread bot/exts/evergreen/youtube.py Outdated
Comment thread bot/exts/evergreen/youtube.py Outdated
Comment thread bot/exts/evergreen/youtube.py
Comment thread bot/exts/evergreen/youtube.py Outdated
@SuperMaZingCoder
Copy link
Copy Markdown
Author

@ChrisLovering it seems like it isn't possible for an error to occur on the users end: https://developers.google.com/youtube/v3/docs/errors#search, so I'll only implement the catchall.

Copy link
Copy Markdown
Member

@ChrisLovering ChrisLovering left a comment

Choose a reason for hiding this comment

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

LGTM! 🚢

Comment thread bot/exts/evergreen/youtube.py Outdated
Copy link
Copy Markdown
Contributor

@decorator-factory decorator-factory left a comment

Choose a reason for hiding this comment

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

LGTM

Comment thread bot/exts/evergreen/youtube.py Outdated
Comment thread bot/exts/evergreen/youtube.py Outdated
Comment thread bot/exts/evergreen/youtube.py
Copy link
Copy Markdown
Contributor

@Shivansh-007 Shivansh-007 left a comment

Choose a reason for hiding this comment

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

Like said before (in Dev contribute) it would be good if this command acts like Reddit one, showing the viewcount and upvote.

@SuperMaZingCoder
Copy link
Copy Markdown
Author

SuperMaZingCoder commented Feb 12, 2021

Personally, I'm opposed to displaying the like/dislike ratio and view count because it seems like unnecessary info, but I'm totally up for your ideas. I think it would be helpful to show how useful it is, but I'm not sure if it is worth the space.

@Shivansh-007
Copy link
Copy Markdown
Contributor

Let’s give it a try and see how it looks.

@SuperMaZingCoder
Copy link
Copy Markdown
Author

Alright, I'll have the time to implement it in an hour or so.

@Xithrius Xithrius added area: backend Related to internal functionality and utilities needs 2 approvals labels Feb 12, 2021
Comment thread bot/exts/evergreen/youtube.py Outdated
Comment thread bot/exts/evergreen/youtube.py Outdated
Comment thread bot/exts/evergreen/youtube.py Outdated
Comment thread bot/exts/evergreen/youtube.py Outdated
Comment thread bot/exts/evergreen/youtube.py Outdated
Comment thread bot/exts/evergreen/youtube.py Outdated
Comment thread bot/exts/evergreen/youtube.py
Comment thread bot/exts/evergreen/youtube.py
Comment thread bot/exts/evergreen/youtube.py Outdated
Comment thread bot/exts/evergreen/youtube.py
Comment thread bot/exts/evergreen/youtube.py Outdated
@Shivansh-007
Copy link
Copy Markdown
Contributor

There is a typo in the word succesful, it should be: successful

@SuperMaZingCoder SuperMaZingCoder added the status: needs review Author is waiting for someone to review and approve label Feb 15, 2021

log = logging.getLogger(__name__)

KEY = Tokens.youtube
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please remove this wrapper

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

^ +1

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

@ks129 specifically you meant the token wrapper, correct?


async def format_search_result(self, index: int, result: List[Video]) -> str:
"""Formats search result to put in embed."""
return RESULT.format(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Maybe this is just my personal bias, but I think it's hard to read formatting code if the formatting template is in a different castle. Maybe put it nearby, or even inline it (as an f-string?)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Does this include the SEARCH_API, STATS_API, YOUTUBE_VIDEO_URL, and YOUTUBE_SEARCH_URL constants too? Or are those fine as is considering that their names are self-explanatory compared to the RESULT f-string.

STATS_API,
params={"part": "statistics", "id": id, "key": KEY},
) as response:
if response.status != 200:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

As discussed in discord, maybe such errors should be left to a top-level handler

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

@decorator-factory As it's been a bit since I've worked on this, were we thinking about making the request, and if it fails, just tell the user "Something went wrong!"

"""Sends the top 5 results of a query from YouTube with fifteen second cool down per user."""
results = await self.search_youtube(search)

if results:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

  1. I would rewrite it as
if not results:
    ... # sad path
    return
    
# happy path

but it's more of a taste question, I guess

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

  1. If you don't ever differentiate between [] or None, why does search_youtube return Optional[List[...]]? Maybe you should show different errors in each case, or return just [] or just None in case of error

Comment thread bot/exts/evergreen/youtube.py
@Xithrius Xithrius added status: waiting for author Waiting for author to address a review or respond to a comment and removed status: WIP Work In Progress status: needs review Author is waiting for someone to review and approve labels Feb 19, 2021
Base automatically changed from master to main March 13, 2021 20:09
@Xithrius
Copy link
Copy Markdown
Contributor

Xithrius commented Apr 2, 2021

@SuperMaZingCoder Still planning on finishing this off?

@SuperMaZingCoder
Copy link
Copy Markdown
Author

@Xithrius I'm going to finish this off today.

@Xithrius
Copy link
Copy Markdown
Contributor

Xithrius commented May 29, 2021

@SuperMaZingCoder what's the status on this?

If you can't work on this anymore for any reason, I can pass it on to another person if needed.

If you're planning on continuing this in the future, take your time.

@Xithrius
Copy link
Copy Markdown
Contributor

@SuperMaZingCoder are you still interested in doing this feature? If not, that's completely fine, happens to a lot of people including myself.

As always, take the time that you need.

@Xithrius
Copy link
Copy Markdown
Contributor

Xithrius commented Sep 5, 2021

I will be closing this PR due to inactivity, I know you'd like to finish this feature yourself but no progress has been made.

Due to this project being restructured, the target file needs to be moved from bot/exts/evergreen/youtube.py to bot/exts/utilities/youtube.py.

You can reopen this when you'd like to continue this feature.

@Xithrius Xithrius closed this Sep 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: backend Related to internal functionality and utilities status: waiting for author Waiting for author to address a review or respond to a comment type: feature Relating to the functionality of the application.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Youtube Command

8 participants