diff --git a/command.py b/command.py index aadbe5f..6bcaaad 100644 --- a/command.py +++ b/command.py @@ -13,6 +13,7 @@ import util import variables as var from pyradios import RadioBrowser from database import SettingsDatabase, MusicDatabase, Condition +import media.playlist from media.item import item_id_generators, dict_to_item, dicts_to_items, ValidationFailedError from media.cache import get_cached_wrapper_from_scrap, get_cached_wrapper_by_id, get_cached_wrappers_by_tags, \ get_cached_wrapper, get_cached_wrappers, get_cached_wrapper_from_dict, get_cached_wrappers_from_dicts diff --git a/configuration.example.ini b/configuration.example.ini index d4a0780..d067e6f 100644 --- a/configuration.example.ini +++ b/configuration.example.ini @@ -116,6 +116,13 @@ port = 64738 # - leave empty (do nothing) #when_nobody_in_channel = +# 'youtube_query_cookie': Sometimes youtube will block the request of our bot and +# request the bot to complete a captcha to verify the request is not made by a +# bot. +# This problem can be resolved if the bot bears a valid cookie. +# If the bot complains "unable to query youtube", you may try to add your cookie here. +#youtube_query_cookie = {'CONSENT': 'paste your CONSENT cookie value here'} + # [webinterface] stores settings related to the web interface. [webinterface] # 'enable': Set 'enabled' to True if you'd like to use the web interface to manage diff --git a/util.py b/util.py index 9d1c440..59060a5 100644 --- a/util.py +++ b/util.py @@ -321,7 +321,9 @@ def youtube_search(query): import json try: - r = requests.get("https://www.youtube.com/results", params={'search_query': query}, timeout=5) + cookie = json.loads(var.config.get('bot', 'youtube_query_cookie', default='{}')) + r = requests.get("https://www.youtube.com/results", cookie=cookie, + params={'search_query': query}, timeout=5) result_json_match = re.findall(r">var ytInitialData = (.*?);", r.text) if not len(result_json_match):