mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-11-08 12:18:54 -05:00
Improved youtube playlist parsing, added !set avatar
Now it actually parse the whole playlist
This commit is contained in:
parent
12033f1746
commit
b1511984ec
@ -12,7 +12,6 @@ from __main__ import send_cmd_help
|
|||||||
import glob
|
import glob
|
||||||
import re
|
import re
|
||||||
import aiohttp
|
import aiohttp
|
||||||
from bs4 import BeautifulSoup
|
|
||||||
import json
|
import json
|
||||||
import time
|
import time
|
||||||
|
|
||||||
@ -618,7 +617,7 @@ class Audio:
|
|||||||
@commands.command(pass_context=True, no_pm=True)
|
@commands.command(pass_context=True, no_pm=True)
|
||||||
async def addplaylist(self, ctx, name : str, link : str): #CHANGE COMMAND NAME
|
async def addplaylist(self, ctx, name : str, link : str): #CHANGE COMMAND NAME
|
||||||
"""Adds tracks from youtube playlist link"""
|
"""Adds tracks from youtube playlist link"""
|
||||||
if self.is_playlist_name_valid(name) and len(name) < 25 and self.is_playlist_link_valid(link):
|
if self.is_playlist_name_valid(name) and len(name) < 25:
|
||||||
if fileIO("playlists/" + name + ".txt", "check"):
|
if fileIO("playlists/" + name + ".txt", "check"):
|
||||||
await self.bot.say("`A playlist with that name already exists.`")
|
await self.bot.say("`A playlist with that name already exists.`")
|
||||||
return False
|
return False
|
||||||
@ -632,7 +631,7 @@ class Audio:
|
|||||||
else:
|
else:
|
||||||
await self.bot.say("Something went wrong. Either the link was incorrect or I was unable to retrieve the page.")
|
await self.bot.say("Something went wrong. Either the link was incorrect or I was unable to retrieve the page.")
|
||||||
else:
|
else:
|
||||||
await self.bot.say("Something is wrong with the playlist's link or its filename. Remember, the name must be with only numbers, letters and underscores. Link must be this format: https://www.youtube.com/playlist?list=PLe8jmEHFkvsaDOOWcREvkgFoj6MD0pXXX")
|
await self.bot.say("Something is wrong with the playlist's link or its filename. Remember, the name must be with only numbers, letters and underscores.")
|
||||||
|
|
||||||
async def transfer_playlist(self, message):
|
async def transfer_playlist(self, message):
|
||||||
msg = message.attachments[0]
|
msg = message.attachments[0]
|
||||||
@ -680,20 +679,15 @@ class Audio:
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
async def parse_yt_playlist(self, url):
|
async def parse_yt_playlist(self, url):
|
||||||
headers = {'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36'}
|
|
||||||
try:
|
try:
|
||||||
page = await aiohttp.post(url, headers=headers)
|
if not "www.youtube.com/playlist?list=" in url:
|
||||||
page = await page.text()
|
url = url.split("&")
|
||||||
soup = BeautifulSoup(page, 'html.parser')
|
url = "https://www.youtube.com/playlist?" + [x for x in url if "list=" in x][0]
|
||||||
tags = soup.find_all("tr", class_="pl-video yt-uix-tile ")
|
playlist = []
|
||||||
links = []
|
yt = youtube_dl.YoutubeDL(youtube_dl_options)
|
||||||
|
for entry in yt.extract_info(url, download=False, process=False)["entries"]:
|
||||||
for tag in tags:
|
playlist.append("https://www.youtube.com/watch?v=" + entry["id"])
|
||||||
links.append("https://www.youtube.com/watch?v=" + tag['data-video-id'])
|
return playlist
|
||||||
if links != []:
|
|
||||||
return links
|
|
||||||
else:
|
|
||||||
return False
|
|
||||||
except:
|
except:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|||||||
13
red.py
13
red.py
@ -11,6 +11,7 @@ import os
|
|||||||
import time
|
import time
|
||||||
import sys
|
import sys
|
||||||
import logging
|
import logging
|
||||||
|
import aiohttp
|
||||||
|
|
||||||
#
|
#
|
||||||
# Red, a Discord bot by Twentysix, based on discord.py and its command extension
|
# Red, a Discord bot by Twentysix, based on discord.py and its command extension
|
||||||
@ -219,6 +220,18 @@ async def status(ctx, *status : str):
|
|||||||
await bot.change_status(None)
|
await bot.change_status(None)
|
||||||
await bot.say("Done.")
|
await bot.say("Done.")
|
||||||
|
|
||||||
|
@_set.command()
|
||||||
|
@checks.is_owner()
|
||||||
|
async def avatar(url : str):
|
||||||
|
"""Sets Red's avatar"""
|
||||||
|
try:
|
||||||
|
async with aiohttp.get(url) as r:
|
||||||
|
data = await r.read()
|
||||||
|
await bot.edit_profile(settings["PASSWORD"], avatar=data)
|
||||||
|
await bot.say("Done.")
|
||||||
|
except:
|
||||||
|
await bot.say("Error.")
|
||||||
|
|
||||||
@bot.command()
|
@bot.command()
|
||||||
@checks.is_owner()
|
@checks.is_owner()
|
||||||
async def shutdown():
|
async def shutdown():
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user