Ejemplo n.º 1
0
async def searchSpotifyPlaylist(self, ctx, args):
    """Get Spotify links from a playlist link."""
    await ctx.send(f"{self.bot.emojiList.spotifyLogo} Searching...", delete_after=10)
    # Get palylist's id
    playlistId = tekore.from_url(args)
    try:
        playlist = await self.bot.spotify.playlist(playlistId[1])
    except:
        await ctx.send(f"{self.bot.emojiList.false} {ctx.author.mention} The Spotify playlist is invalid!")
        return None

    trackLinks = []
    if self.playlistLimit != 0 and playlist.tracks.total > self.playlistLimit:
        await playlistTooLarge(self, ctx)
        return None
    await ctx.send(f"{self.bot.emojiList.spotifyLogo} Loading... (This process can take several seconds)", delete_after=60)
    for i in playlist.tracks.items:
        title = i.track.name
        artist = i.track.artists[0].name
        # Search on youtube
        track = await self.bot.wavelink.get_tracks(f'ytsearch:{title} {artist}')
        if track is None:
            await ctx.send(f"{self.bot.emojiList.false} {ctx.author.mention} No song found to : `{title} - {artist}` !")
        else:
            trackLinks.append(track[0])
    if not trackLinks: # if len(trackLinks) == 0:
        return None
    return trackLinks
Ejemplo n.º 2
0
 def add_url(self, url):
     try:
         type, id = tekore.from_url(url)
         uri = tekore.to_uri(type, id)
     except tekore.ConversionError:
         return False
     else:
         return self.add_to_queue(uri)
Ejemplo n.º 3
0
async def searchSpotifyTrack(self, ctx, args):
    """Get a YouTube link from a Spotify link."""
    await ctx.send(f"{self.bot.emojiList.spotifyLogo} Searching...", delete_after=10)
    # Get track's id
    trackId = tekore.from_url(args)
    try:
        track = await self.bot.spotify.track(trackId[1])
    except:
        await ctx.send(f"{self.bot.emojiList.false} {ctx.author.mention} The Spotify link is invalid!")
        return None
    title = track.name
    artist = track.artists[0].name
    # Search on youtube
    track = await self.bot.wavelink.get_tracks(f'ytsearch:{title} {artist}')
    if len(track) == 0:
        await noResultFound(self, ctx)
        return None
    return track[0]
Ejemplo n.º 4
0
 def test_invalid_id(self):
     with pytest.raises(ConversionError):
         from_url('http://open.spotify.com/track/n_b62')
Ejemplo n.º 5
0
 def _call(url, type_, id_) -> bool:
     t, i = from_url(url)
     return t == type_ and i == id_
Ejemplo n.º 6
0
 def test_totally_invalid(self):
     with pytest.raises(ConversionError):
         from_url('not-a-valid-url')
Ejemplo n.º 7
0
 def test_invalid_prefix(self):
     with pytest.raises(ConversionError):
         from_url('a.suspicious.site/track/b62')
Ejemplo n.º 8
0
 def test_invalid_type(self):
     with pytest.raises(ConversionError):
         from_url('http://open.spotify.com/invalid/b62')