get_playlist: add 'views' for owned playlists, fix trackCount (closes #365)
This commit is contained in:
parent
19ad424e0e
commit
e14abac69d
3 changed files with 19 additions and 13 deletions
|
|
@ -372,23 +372,23 @@ class TestYTMusic(unittest.TestCase):
|
|||
|
||||
# end to end test adding playlist, adding item, deleting item, deleting playlist
|
||||
def test_end2end(self):
|
||||
playlistId = self.yt_auth.create_playlist(
|
||||
playlistId = self.yt_brand.create_playlist(
|
||||
"test",
|
||||
"test description",
|
||||
source_playlist="OLAK5uy_lGQfnMNGvYCRdDq9ZLzJV2BJL2aHQsz9Y")
|
||||
self.assertEqual(len(playlistId), 34, "Playlist creation failed")
|
||||
response = self.yt_auth.add_playlist_items(
|
||||
response = self.yt_brand.add_playlist_items(
|
||||
playlistId, [sample_video, sample_video],
|
||||
source_playlist='OLAK5uy_nvjTE32aFYdFN7HCyMv3cGqD3wqBb4Jow',
|
||||
duplicates=True)
|
||||
self.assertEqual(response["status"], 'STATUS_SUCCEEDED', "Adding playlist item failed")
|
||||
self.assertGreater(len(response["playlistEditResults"]), 0, "Adding playlist item failed")
|
||||
time.sleep(2)
|
||||
playlist = self.yt_auth.get_playlist(playlistId, related=True)
|
||||
playlist = self.yt_brand.get_playlist(playlistId, related=True)
|
||||
self.assertEqual(len(playlist['tracks']), 46, "Getting playlist items failed")
|
||||
response = self.yt_auth.remove_playlist_items(playlistId, playlist['tracks'])
|
||||
response = self.yt_brand.remove_playlist_items(playlistId, playlist['tracks'])
|
||||
self.assertEqual(response, 'STATUS_SUCCEEDED', "Playlist item removal failed")
|
||||
response = self.yt_auth.delete_playlist(playlistId)
|
||||
response = self.yt_brand.delete_playlist(playlistId)
|
||||
self.assertEqual(response['command']['handlePlaylistDeletionCommand']['playlistId'],
|
||||
playlistId, "Playlist removal failed")
|
||||
|
||||
|
|
|
|||
|
|
@ -4,6 +4,9 @@ from http.cookies import SimpleCookie
|
|||
from hashlib import sha1
|
||||
import time
|
||||
import locale
|
||||
|
||||
import unicodedata
|
||||
|
||||
from ytmusicapi.constants import *
|
||||
|
||||
|
||||
|
|
@ -56,7 +59,8 @@ def get_authorization(auth):
|
|||
|
||||
|
||||
def to_int(string):
|
||||
number_string = re.sub('[^\\d]', '', string)
|
||||
string = unicodedata.normalize("NFKD", string)
|
||||
number_string = re.sub(r'\D', '', string)
|
||||
try:
|
||||
int_value = locale.atoi(number_string)
|
||||
except ValueError:
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
import unicodedata
|
||||
from typing import Dict, Union, Tuple
|
||||
from ._utils import *
|
||||
|
||||
|
|
@ -133,15 +132,18 @@ class PlaylistsMixin:
|
|||
if run_count == 5:
|
||||
playlist['year'] = nav(header, SUBTITLE3)
|
||||
|
||||
song_count = to_int(
|
||||
unicodedata.normalize("NFKD", header['secondSubtitle']['runs'][0]['text']))
|
||||
if len(header['secondSubtitle']['runs']) > 1:
|
||||
playlist['duration'] = header['secondSubtitle']['runs'][2]['text']
|
||||
second_subtitle_runs = header['secondSubtitle']['runs']
|
||||
own_offset = (own_playlist and len(second_subtitle_runs) > 3) * 2
|
||||
song_count = to_int(second_subtitle_runs[own_offset]['text'])
|
||||
if len(second_subtitle_runs) > 1:
|
||||
playlist['duration'] = second_subtitle_runs[own_offset + 2]['text']
|
||||
|
||||
playlist['trackCount'] = song_count
|
||||
playlist['views'] = None
|
||||
if own_playlist:
|
||||
playlist['views'] = to_int(second_subtitle_runs[0]['text'])
|
||||
|
||||
request_func = lambda additionalParams: self._send_request(endpoint, body, additionalParams
|
||||
)
|
||||
request_func = lambda additionalParams: self._send_request(endpoint, body, additionalParams)
|
||||
|
||||
# suggestions and related are missing e.g. on liked songs
|
||||
section_list = nav(response, SINGLE_COLUMN_TAB + ['sectionListRenderer'])
|
||||
|
|
|
|||
Loading…
Reference in a new issue