Strip HTML from playlist descriptions

This commit is contained in:
sigma67 2020-02-26 21:22:48 +01:00
commit fefd96c53a
No known key found for this signature in database
GPG key ID: 1545A01D4474BAF0
3 changed files with 20 additions and 5 deletions

View file

@ -1 +1 @@
__version__ = "0.4.0"
__version__ = "0.4.1"

View file

@ -1,4 +1,7 @@
## Static helper methods
import re
# Static helper methods
def parse_songs(results):
songs = []
@ -76,4 +79,11 @@ def parse_search_result(data, resultType = None):
def get_item_text(item, index):
return item['flexColumns'][index]['musicResponsiveListItemFlexColumnRenderer']['text']['runs'][0]['text']
return item['flexColumns'][index]['musicResponsiveListItemFlexColumnRenderer']['text']['runs'][0]['text']
def html_to_txt(html_text):
tags = re.findall("<[^>]+>",html_text)
for tag in tags:
html_text = html_text.replace(tag,'')
return html_text

View file

@ -1,7 +1,8 @@
import requests
import json
import pkg_resources
from ytmusicapi.helpers import parse_songs, parse_search_result
from ytmusicapi.helpers import \
parse_songs, parse_search_result, html_to_txt
params = '?alt=json&key=AIzaSyC9XL3ZjWddXya6X74dJoCTL-WEYFDNX30'
base_url = 'https://music.youtube.com/youtubei/v1/'
@ -273,7 +274,11 @@ class YTMusic:
:return: ID of the YouTube playlist
"""
self.__check_auth()
body = {'title': title, 'description': description, 'privacyStatus': privacy_status}
body = {
'title': title,
'description': html_to_txt(description), # YT does not allow HTML tags
'privacyStatus': privacy_status
}
endpoint = 'playlist/create'
response = self.__send_request(endpoint, body)
return response['playlistId']