-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrated to `py-cord`. Including: - hints, - exceptions, - improved embeds, - better project structure, - updated invitation link.
- Loading branch information
1 parent
22d9151
commit 9ea2c4b
Showing
22 changed files
with
395 additions
and
528 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,18 @@ | ||
# Spoyt | ||
|
||
Spotify to YouTube; Discord and Guilded link converter. | ||
Discord bot that allows you to "convert" Spotify links to YouTube videos. | ||
|
||
## Usage | ||
|
||
Just send a message with share link from Spotify. Bot will automatically find | ||
the track in Spotify database, and search its name and artists in YouTube. | ||
If possible, it will try to delete your message, but you can disable it | ||
by permitting permissions. | ||
1. Invite the bot with this link: <https://discord.com/api/oauth2/authorize?client_id=948274806325903410&permissions=2147485696&scope=bot%20applications.commands>. | ||
|
||
Invite the bot by one of following links: | ||
- Discord: https://discord.com/api/oauth2/authorize?client_id=948274806325903410&permissions=3072&scope=bot | ||
- Guilded: https://www.guilded.gg/b/93177486-3a1d-4464-a202-1ddd6354844b | ||
1. Use `/track` or `/playlist` command to search. Bot will try to find the track or playlist (respectively) using Spotify API, and search it in YouTube (also using API). | ||
|
||
## Support | ||
|
||
You can join one of my servers (or both): | ||
### Note | ||
|
||
- Discord: [discord.gg/SRdmrPpf2z](https://discord.gg/SRdmrPpf2z) | ||
- Guilded: [guilded.gg/Anonymous-Canteen](https://guilded.gg/Anonymous-Canteen) | ||
YouTube searching currently applies only to `/track`. I'm currently inspecting YouTube API limiations. | ||
|
||
## How to run | ||
## Support | ||
|
||
Make sure you have Python `>=3.8` installed. | ||
``` | ||
[py|python|python3] -(O|OO)m Spoyt.[Discord|Guilded] | ||
``` | ||
You can join my server: <https://discord.gg/SRdmrPpf2z>. | ||
|
Empty file.
This file was deleted.
Oops, something went wrong.
Empty file.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# -*- coding: utf-8 -*- | ||
from json import loads as json_loads | ||
|
||
from requests import get as requests_get | ||
|
||
from Spoyt.exceptions import YouTubeException, YouTubeForbiddenException | ||
from Spoyt.logging import log | ||
from Spoyt.settings import YOUTUBE_API_KEY | ||
|
||
|
||
class YouTubeVideo: | ||
def __init__(self, payload: dict) -> None: | ||
item: dict = payload.get('items', [{}])[0] | ||
snippet: dict = item.get('snippet', {}) | ||
self.video_id: str = item.get('id', {}).get('videoId') | ||
self.title: str = snippet.get('title') | ||
self.description: str = snippet.get('description') | ||
self.published_date: str = snippet.get('publishTime', '')[:10] | ||
|
||
@property | ||
def video_link(self) -> str: | ||
return f'https://www.youtube.com/watch?v={self.video_id}' | ||
|
||
@property | ||
def video_thumbnail(self) -> str: | ||
return f'https://i.ytimg.com/vi/{self.video_id}/default.jpg' | ||
|
||
|
||
def search_video(query: str) -> YouTubeVideo: | ||
log.info(f'Searching YouTube: "{query}"') | ||
yt_r = requests_get( | ||
'https://www.googleapis.com/youtube/v3/search' | ||
'?key={}' | ||
'&part=snippet' | ||
'&maxResults=1' | ||
'&q={}'.format(YOUTUBE_API_KEY, query) | ||
) | ||
content = json_loads(yt_r.content) | ||
if (error_code := yt_r.status_code) == 200: | ||
video = YouTubeVideo(content) | ||
log.info(f'Found YouTube video "{video.title}" ({video.video_link})') | ||
elif error_code == 403: | ||
log.critical(content['error']['message']) | ||
raise YouTubeForbiddenException | ||
else: | ||
log.error(content['error']['message']) | ||
raise YouTubeException | ||
return video |
Oops, something went wrong.