ytmusicapi/tests/mixins/test_playlists.py
fischcode d143480ae4
Fix parsing of album and views in parse_playlist_items (#552)
* Fix parsing of album and views in parse_playlist_items

Parse album and views columns as a function of flex column count and is_album property to cater for varying layouts with three and four flex columns

* Add "own_playlist" attribute to playlists

To allow for an easy distinction between owned / editable and community / non-editable playlists,in applications incorporating ytmusicapi, a boolean "own_playlist" dictionary entry is added to playlists based on existing code already identifying this property.

* Add thumbnails to episodes

Add thumbnails to episodes for visual rendering in Kodi etc.

* Add unit test for playlist "own_playlist" attribut

Add unit test for playlist "own_playlist" attribut

* Improvements as requested

- rename attribute for own playlists to playlist("owned")
- filter out episode thumbnails with an non-functional URL

* Fix linter in test_playlists.py

Fix test for playlist["owned"]

* Auto-Formatting on playlists.py

* format parsers/podcasts.py

* Remove filtering of podcast thumbnails

No idea why I had seen useless images for those thumbnails before - maybe Google fixed something to make them work?
2024-02-27 09:23:09 +01:00

77 lines
3.2 KiB
Python

import time
import pytest
class TestPlaylists:
def test_get_playlist_foreign(self, yt, yt_auth, yt_oauth):
with pytest.raises(Exception):
yt.get_playlist("PLABC")
playlist = yt_auth.get_playlist("PLk5BdzXBUiUe8Q5I13ZSCD8HbxMqJUUQA", limit=300, suggestions_limit=7)
assert len(playlist["duration"]) > 5
assert len(playlist["tracks"]) > 200
assert "suggestions" not in playlist
assert playlist["owned"] is False
yt.get_playlist("RDATgXd-")
assert len(playlist["tracks"]) >= 100
playlist = yt_oauth.get_playlist("PLj4BSJLnVpNyIjbCWXWNAmybc97FXLlTk", limit=None, related=True)
assert len(playlist["tracks"]) > 200
assert len(playlist["related"]) == 0
def test_get_playlist_owned(self, config, yt_brand):
playlist = yt_brand.get_playlist(config["playlists"]["own"], related=True, suggestions_limit=21)
assert len(playlist["tracks"]) < 100
assert len(playlist["suggestions"]) == 21
assert len(playlist["related"]) == 10
assert playlist["owned"] is True
def test_edit_playlist(self, config, yt_brand):
playlist = yt_brand.get_playlist(config["playlists"]["own"])
response = yt_brand.edit_playlist(
playlist["id"],
title="",
description="",
privacyStatus="PRIVATE",
moveItem=(
playlist["tracks"][1]["setVideoId"],
playlist["tracks"][0]["setVideoId"],
),
)
assert response == "STATUS_SUCCEEDED", "Playlist edit failed"
yt_brand.edit_playlist(
playlist["id"],
title=playlist["title"],
description=playlist["description"],
privacyStatus=playlist["privacy"],
moveItem=(
playlist["tracks"][0]["setVideoId"],
playlist["tracks"][1]["setVideoId"],
),
)
assert response == "STATUS_SUCCEEDED", "Playlist edit failed"
def test_end2end(self, config, yt_brand, sample_video):
playlist_id = yt_brand.create_playlist(
"test",
"test description",
source_playlist="OLAK5uy_lGQfnMNGvYCRdDq9ZLzJV2BJL2aHQsz9Y",
)
assert len(playlist_id) == 34, "Playlist creation failed"
yt_brand.edit_playlist(playlist_id, addToTop=True)
response = yt_brand.add_playlist_items(
playlist_id,
[sample_video, sample_video],
source_playlist="OLAK5uy_nvjTE32aFYdFN7HCyMv3cGqD3wqBb4Jow",
duplicates=True,
)
assert response["status"] == "STATUS_SUCCEEDED", "Adding playlist item failed"
assert len(response["playlistEditResults"]) > 0, "Adding playlist item failed"
time.sleep(3)
yt_brand.edit_playlist(playlist_id, addToTop=False)
playlist = yt_brand.get_playlist(playlist_id, related=True)
assert len(playlist["tracks"]) == 46, "Getting playlist items failed"
response = yt_brand.remove_playlist_items(playlist_id, playlist["tracks"])
assert response == "STATUS_SUCCEEDED", "Playlist item removal failed"
yt_brand.delete_playlist(playlist_id)