1
0
mirror of https://github.com/azlux/botamusique synced 2024-11-23 13:56:17 +00:00

Compare commits

..

4 Commits

Author SHA1 Message Date
1c283654fd
Unescape HTML in URLs parsed from user input
Merge pull request #275 from mweinelt/url-unescape-html
2021-05-16 16:30:50 +02:00
Martin Weinelt
faddf4c6c2
Unescape HTML in URLs parsed from user input
Escapes tokens like & to &, so GET parameters are correctly preserved.

Fixes: #274
2021-05-16 15:04:50 +02:00
b0e3e65caf
Fix playlist items over multiple attemps
Merge pull request #276 from mweinelt/fix-playback-attempts
2021-05-16 15:04:25 +02:00
Martin Weinelt
e6d12e36c7
Don't accumulate playlist items over multiple attemps
Playlist items would previously have been added once for each attempt,
due to items being scoped differently than the playlist parsing
attempts. Each attempt would add to the playlist every time, since we
only returned outside the attempts loop.
2021-05-16 05:51:42 +02:00
2 changed files with 13 additions and 5 deletions

View File

@ -1,3 +1,4 @@
import logging
import youtube_dl import youtube_dl
from constants import tr_cli as tr from constants import tr_cli as tr
import variables as var import variables as var
@ -5,8 +6,10 @@ from media.item import item_builders, item_loaders, item_id_generators
from media.url import URLItem, url_item_id_generator from media.url import URLItem, url_item_id_generator
log = logging.getLogger("bot")
def get_playlist_info(url, start_index=0, user=""): def get_playlist_info(url, start_index=0, user=""):
items = []
ydl_opts = { ydl_opts = {
'extract_flat': 'in_playlist', 'extract_flat': 'in_playlist',
'verbose': var.config.getboolean('debug', 'youtube_dl') 'verbose': var.config.getboolean('debug', 'youtube_dl')
@ -23,6 +26,7 @@ def get_playlist_info(url, start_index=0, user=""):
with youtube_dl.YoutubeDL(ydl_opts) as ydl: with youtube_dl.YoutubeDL(ydl_opts) as ydl:
attempts = var.config.getint('bot', 'download_attempts', fallback=2) attempts = var.config.getint('bot', 'download_attempts', fallback=2)
for i in range(attempts): for i in range(attempts):
items = []
try: try:
info = ydl.extract_info(url, download=False) info = ydl.extract_info(url, download=False)
# # if url is not a playlist but a video # # if url is not a playlist but a video
@ -55,8 +59,10 @@ def get_playlist_info(url, start_index=0, user=""):
} }
items.append(music) items.append(music)
except: # todo need to be specified
pass except Exception as ex:
log.exception(ex, exc_info=True)
continue
return items return items

View File

@ -2,6 +2,7 @@
# coding=utf-8 # coding=utf-8
import hashlib import hashlib
import html
import magic import magic
import os import os
import io import io
@ -311,7 +312,8 @@ def get_url_from_input(string):
match = re.search("(http|https)://(\S*)?/(\S*)", string, flags=re.IGNORECASE) match = re.search("(http|https)://(\S*)?/(\S*)", string, flags=re.IGNORECASE)
if match: if match:
url = match[1].lower() + "://" + match[2].lower() + "/" + match[3] url = match[1].lower() + "://" + match[2].lower() + "/" + match[3]
return url # https://github.com/mumble-voip/mumble/issues/4999
return html.unescape(url)
else: else:
return "" return ""