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

[V3 Audio] Playlist download addition #2482

Merged
merged 2 commits into from Mar 3, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
40 changes: 40 additions & 0 deletions redbot/cogs/audio/audio.py
Expand Up @@ -4,6 +4,8 @@
import discord
from fuzzywuzzy import process
import heapq
from io import StringIO
import json
import lavalink
import logging
import math
Expand Down Expand Up @@ -1194,6 +1196,44 @@ async def _playlist_delete(self, ctx, playlist_name):
return await self._embed_msg(ctx, _("No playlist with that name."))
await self._embed_msg(ctx, _("{name} playlist deleted.").format(name=playlist_name))

@checks.is_owner()
@playlist.command(name="download")
async def _playlist_download(self, ctx, playlist_name, v2=False):
"""Download a copy of a playlist.

These files can be used with the [p]playlist upload command.
Red v2-compatible playlists can be generated by passing True
for the v2 variable."""
if not await self._playlist_check(ctx):
return
playlists = await self.config.guild(ctx.guild).playlists.get_raw()
v2_valid_urls = ["https://www.youtube.com/watch?v=", "https://soundcloud.com/"]
song_list = []
playlist_url = None

try:
if playlists[playlist_name]["playlist_url"]:
playlist_url = playlists[playlist_name]["playlist_url"]
for track in playlists[playlist_name]["tracks"]:
if v2:
if track["info"]["uri"].startswith(tuple(v2_valid_urls)):
song_list.append(track["info"]["uri"])
else:
song_list.append(track["info"]["uri"])
except TypeError:
return await self._embed_msg(ctx, _("That playlist has no tracks."))
except KeyError:
return await self._embed_msg(ctx, _("That playlist doesn't exist."))

playlist_data = json.dumps(
{"author": ctx.author.id, "link": playlist_url, "playlist": song_list}
)
to_write = StringIO()
to_write.write(playlist_data)
to_write.seek(0)
await ctx.send(file=discord.File(to_write, filename=f"{playlist_name}.txt"))
aikaterna marked this conversation as resolved.
Show resolved Hide resolved
to_write.close()

@playlist.command(name="info")
async def _playlist_info(self, ctx, playlist_name):
"""Retrieve information from a saved playlist."""
Expand Down