Feature: remove_history_items (closes #31)
This commit is contained in:
parent
3984341b15
commit
dad63116df
4 changed files with 31 additions and 3 deletions
|
|
@ -41,6 +41,7 @@ Library
|
||||||
.. automethod:: YTMusic.get_library_albums
|
.. automethod:: YTMusic.get_library_albums
|
||||||
.. automethod:: YTMusic.get_liked_songs
|
.. automethod:: YTMusic.get_liked_songs
|
||||||
.. automethod:: YTMusic.get_history
|
.. automethod:: YTMusic.get_history
|
||||||
|
.. automethod:: YTMusic.remove_history_items
|
||||||
.. automethod:: YTMusic.rate_song
|
.. automethod:: YTMusic.rate_song
|
||||||
.. automethod:: YTMusic.rate_playlist
|
.. automethod:: YTMusic.rate_playlist
|
||||||
.. automethod:: YTMusic.subscribe_artists
|
.. automethod:: YTMusic.subscribe_artists
|
||||||
|
|
|
||||||
|
|
@ -129,6 +129,12 @@ class TestYTMusic(unittest.TestCase):
|
||||||
songs = youtube_auth.get_history()
|
songs = youtube_auth.get_history()
|
||||||
self.assertGreater(len(songs), 0)
|
self.assertGreater(len(songs), 0)
|
||||||
|
|
||||||
|
@unittest.skip
|
||||||
|
def test_remove_history_items(self):
|
||||||
|
songs = youtube_auth.get_history()
|
||||||
|
response = youtube_auth.remove_history_items([songs[0]['feedbackToken'], songs[1]['feedbackToken']])
|
||||||
|
self.assertIn('feedbackResponses', response)
|
||||||
|
|
||||||
def test_rate_song(self):
|
def test_rate_song(self):
|
||||||
response = youtube_auth.rate_song('ZrOKjDZOtkA', 'LIKE')
|
response = youtube_auth.rate_song('ZrOKjDZOtkA', 'LIKE')
|
||||||
self.assertIn('actions', response)
|
self.assertIn('actions', response)
|
||||||
|
|
|
||||||
|
|
@ -154,7 +154,8 @@ class LibraryMixin:
|
||||||
Gets your play history in reverse chronological order
|
Gets your play history in reverse chronological order
|
||||||
|
|
||||||
:return: List of playlistItems, see :py:func:`get_playlist`
|
:return: List of playlistItems, see :py:func:`get_playlist`
|
||||||
The additional property 'played' indicates when the playlistItem was played
|
The additional property ``played`` indicates when the playlistItem was played
|
||||||
|
The additional property ``feedbackToken`` can be used to remove items with :py:func:`remove_history_item`
|
||||||
"""
|
"""
|
||||||
self._check_auth()
|
self._check_auth()
|
||||||
body = {'browseId': 'FEmusic_history'}
|
body = {'browseId': 'FEmusic_history'}
|
||||||
|
|
@ -164,13 +165,28 @@ class LibraryMixin:
|
||||||
songs = []
|
songs = []
|
||||||
for content in results:
|
for content in results:
|
||||||
data = content['musicShelfRenderer']['contents']
|
data = content['musicShelfRenderer']['contents']
|
||||||
songlist = parse_playlist_items(data)
|
menu_entries = [[-1] + MENU_SERVICE + ['feedbackEndpoint', 'feedbackToken']]
|
||||||
|
songlist = parse_playlist_items(data, menu_entries)
|
||||||
for song in songlist:
|
for song in songlist:
|
||||||
song['played'] = nav(content['musicShelfRenderer'], TITLE_TEXT)
|
song['played'] = nav(content['musicShelfRenderer'], TITLE_TEXT)
|
||||||
songs.extend(songlist)
|
songs.extend(songlist)
|
||||||
|
|
||||||
return songs
|
return songs
|
||||||
|
|
||||||
|
def remove_history_items(self, feedbackTokens: List[str]) -> Dict: # pragma: no cover
|
||||||
|
"""
|
||||||
|
Remove an item from the account's history. This method does currently not work with brand accounts
|
||||||
|
|
||||||
|
:param feedbackTokens: Token to identify the item to remove, obtained from :py:func:`get_history`
|
||||||
|
:return: Full response
|
||||||
|
"""
|
||||||
|
self._check_auth()
|
||||||
|
body = {'feedbackTokens': feedbackTokens}
|
||||||
|
endpoint = 'feedback'
|
||||||
|
response = self._send_request(endpoint, body)
|
||||||
|
|
||||||
|
return response
|
||||||
|
|
||||||
def rate_song(self, videoId: str, rating: str = 'INDIFFERENT') -> Dict:
|
def rate_song(self, videoId: str, rating: str = 'INDIFFERENT') -> Dict:
|
||||||
"""
|
"""
|
||||||
Rates a song ("thumbs up"/"thumbs down" interactions on YouTube Music)
|
Rates a song ("thumbs up"/"thumbs down" interactions on YouTube Music)
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,8 @@
|
||||||
from .utils import *
|
from .utils import *
|
||||||
|
from typing import List
|
||||||
|
|
||||||
|
|
||||||
def parse_playlist_items(results):
|
def parse_playlist_items(results, menu_entries: List[List] = None):
|
||||||
songs = []
|
songs = []
|
||||||
count = 1
|
count = 1
|
||||||
for result in results:
|
for result in results:
|
||||||
|
|
@ -65,6 +66,10 @@ def parse_playlist_items(results):
|
||||||
if setVideoId:
|
if setVideoId:
|
||||||
song['setVideoId'] = setVideoId
|
song['setVideoId'] = setVideoId
|
||||||
|
|
||||||
|
if menu_entries:
|
||||||
|
for menu_entry in menu_entries:
|
||||||
|
song[menu_entry[-1]] = nav(data, MENU_ITEMS + menu_entry)
|
||||||
|
|
||||||
songs.append(song)
|
songs.append(song)
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue