add youtube-dl options

#258
This commit is contained in:
Azlux 2021-04-03 13:39:47 +02:00
parent 582b0b58da
commit ee5a54b33b
4 changed files with 51 additions and 22 deletions

View File

@ -123,7 +123,10 @@ luna = http://radio.ponyvillelive.com:8002/stream "calm and orchestra music"
radiobrony = http://62.210.138.34:8000/live "Brony music of a friend" radiobrony = http://62.210.138.34:8000/live "Brony music of a friend"
jazz = http://jazz-wr04.ice.infomaniak.ch/jazz-wr04-128.mp3 "Jazz Yeah !" jazz = http://jazz-wr04.ice.infomaniak.ch/jazz-wr04-128.mp3 "Jazz Yeah !"
[youtube_dl]
source_address =
cookiefile =
user_agent =

View File

@ -168,6 +168,14 @@ port = 64738
# one line by entrie # one line by entrie
#jazz = http://jazz-wr04.ice.infomaniak.ch/jazz-wr04-128.mp3 "Jazz Yeah !" #jazz = http://jazz-wr04.ice.infomaniak.ch/jazz-wr04-128.mp3 "Jazz Yeah !"
# [youtube_dl] are option to custom youtube-dl (optionnal)
[youtube_dl]
# source_address , use '::' to force ipv6, "0.0.0.0" to force ipv4, or put the ip addresse you want to use.
# source_address = '::'
# cookiefile , path of the cookie file (usefull if you reach youtube limits https://github.com/ytdl-org/youtube-dl#http-error-429-too-many-requests-or-402-payment-required)
# cookiefile = '/tmp/cooke_ydl'
# user-agent allow the user to force the user-agent of youtube-dl
# user-agent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:87.0) Gecko/20100101 Firefox/87.0"
# [commands] is settings related to user command sent via mumble message. # [commands] is settings related to user command sent via mumble message.
[commands] [commands]

View File

@ -170,11 +170,19 @@ class URLItem(BaseItem):
'verbose': var.config.getboolean('debug', 'youtube_dl') 'verbose': var.config.getboolean('debug', 'youtube_dl')
} }
cookie = var.config.get('youtube_dl', 'cookiefile', fallback=None)
if cookie:
ydl_opts['cookiefile'] = var.config.get('youtube_dl', 'cookiefile', fallback=None)
user_agent = var.config.get('youtube_dl', 'user_agent', fallback=None)
if user_agent:
youtube_dl.utils.std_headers['User-Agent'] = var.config.get('youtube_dl', 'user_agent')
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)
download_succeed = False download_succeed = False
for i in range(attempts): for i in range(attempts):
self.log.info("bot: download attempts %d / %d" % (i+1, attempts)) self.log.info("bot: download attempts %d / %d" % (i + 1, attempts))
try: try:
ydl.extract_info(self.url) ydl.extract_info(self.url)
download_succeed = True download_succeed = True

View File

@ -8,8 +8,18 @@ from media.url import URLItem, url_item_id_generator
def get_playlist_info(url, start_index=0, user=""): def get_playlist_info(url, start_index=0, user=""):
items = [] items = []
ydl_opts = { ydl_opts = {
'extract_flat': 'in_playlist' 'extract_flat': 'in_playlist',
'verbose': var.config.getboolean('debug', 'youtube_dl')
} }
cookie = var.config.get('youtube_dl', 'cookiefile', fallback=None)
if cookie:
ydl_opts['cookiefile'] = var.config.get('youtube_dl', 'cookiefile', fallback=None)
user_agent = var.config.get('youtube_dl', 'user_agent', fallback=None)
if user_agent:
youtube_dl.utils.std_headers['User-Agent'] = var.config.get('youtube_dl', 'user_agent')
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):
@ -45,7 +55,7 @@ def get_playlist_info(url, start_index=0, user=""):
} }
items.append(music) items.append(music)
except: except: # todo need to be specified
pass pass
return items return items
@ -82,11 +92,11 @@ class PlaylistURLItem(URLItem):
self.type = "url_from_playlist" self.type = "url_from_playlist"
def to_dict(self): def to_dict(self):
dict = super().to_dict() tmp_dict = super().to_dict()
dict['playlist_url'] = self.playlist_url tmp_dict['playlist_url'] = self.playlist_url
dict['playlist_title'] = self.playlist_title tmp_dict['playlist_title'] = self.playlist_title
return dict return tmp_dict
def format_debug_string(self): def format_debug_string(self):
return "[url] {title} ({url}) from playlist {playlist}".format( return "[url] {title} ({url}) from playlist {playlist}".format(