Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Models #621

Open
wants to merge 4 commits into
base: v2
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
121 changes: 119 additions & 2 deletions pdm.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ classifiers = [
]
dependencies = [
"requests >= 2.22",
"pydantic>=2.8.2",
]
dynamic = ["version", "readme"]

Expand Down
8 changes: 6 additions & 2 deletions ytmusicapi/mixins/playlists.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@
from ytmusicapi.parsers.browsing import parse_content_list, parse_playlist
from ytmusicapi.parsers.playlists import *

from ..models.playlist import PlaylistResult
from ._protocol import MixinProtocol
from ._utils import *


class PlaylistsMixin(MixinProtocol):
def get_playlist(
self, playlistId: str, limit: Optional[int] = 100, related: bool = False, suggestions_limit: int = 0
) -> dict:
) -> PlaylistResult:
"""
Returns a list of playlist items

Expand Down Expand Up @@ -109,6 +110,7 @@ def get_playlist(

header_data = nav(response, [*TWO_COLUMN_RENDERER, *TAB_CONTENT, *SECTION_LIST_ITEM])
section_list = nav(response, [*TWO_COLUMN_RENDERER, "secondaryContents", *SECTION])

playlist: dict = {}
playlist["owned"] = EDITABLE_PLAYLIST_DETAIL_HEADER[0] in header_data
if not playlist["owned"]:
Expand All @@ -132,6 +134,7 @@ def get_playlist(
if description_shelf
else None
)
playlist["thumbnails"] = nav(header, THUMBNAILS)
playlist["title"] = nav(header, TITLE_TEXT)
playlist.update(parse_song_runs(nav(header, SUBTITLE_RUNS)[2 + playlist["owned"] * 2 :]))

Expand Down Expand Up @@ -203,7 +206,8 @@ def get_playlist(
)

playlist["duration_seconds"] = sum_total_duration(playlist)
return playlist

return PlaylistResult(**playlist)

def get_liked_songs(self, limit: int = 100) -> dict:
"""
Expand Down
57 changes: 5 additions & 52 deletions ytmusicapi/mixins/search.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Any, Optional, Union
from typing import Any, Optional

from ytmusicapi.continuations import get_continuations
from ytmusicapi.exceptions import YTMusicUserError
Expand Down Expand Up @@ -258,19 +258,14 @@ def parse_func(contents):

return search_results

def get_search_suggestions(self, query: str, detailed_runs=False) -> Union[list[str], list[dict]]:
def get_search_suggestions(self, query: str) -> list[str]:
"""
Get Search Suggestions

:param query: Query string, i.e. 'faded'
:param detailed_runs: Whether to return detailed runs of each suggestion.
If True, it returns the query that the user typed and the remaining
suggestion along with the complete text (like many search services
usually bold the text typed by the user).
Default: False, returns the list of search suggestions in plain text.
:return: List of search suggestion results depending on ``detailed_runs`` param.
:return: List of search suggestions as strings.

Example response when ``query`` is 'fade' and ``detailed_runs`` is set to ``False``::
Example response when ``query`` is 'fade'::

[
"faded",
Expand All @@ -281,54 +276,12 @@ def get_search_suggestions(self, query: str, detailed_runs=False) -> Union[list[
"faded lyrics",
"faded instrumental"
]

Example response when ``detailed_runs`` is set to ``True``::

[
{
"text": "faded",
"runs": [
{
"text": "fade",
"bold": true
},
{
"text": "d"
}
]
},
{
"text": "faded alan walker lyrics",
"runs": [
{
"text": "fade",
"bold": true
},
{
"text": "d alan walker lyrics"
}
]
},
{
"text": "faded alan walker",
"runs": [
{
"text": "fade",
"bold": true
},
{
"text": "d alan walker"
}
]
},
...
]
"""

body = {"input": query}
endpoint = "music/get_search_suggestions"

response = self._send_request(endpoint, body)
search_suggestions = parse_search_suggestions(response, detailed_runs)
search_suggestions = parse_search_suggestions(response)

return search_suggestions
Empty file added ytmusicapi/models/__init__.py
Empty file.
Empty file.
24 changes: 24 additions & 0 deletions ytmusicapi/models/content/enums.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
from enum import Enum


class PrivacyStatus(str, Enum):
PUBLIC = "PUBLIC"
PRIVATE = "PRIVATE"
UNLISTED = "UNLISTED"


class LikeStatus(str, Enum):
LIKE = "LIKE"
DISLIKE = "DISLIKE"
INDIFFERENT = "INDIFFERENT"

@classmethod
def _missing_(cls, value):
return cls.INDIFFERENT


class VideoType(str, Enum):
OMV = "MUSIC_VIDEO_TYPE_OMV"
UGC = "MUSIC_VIDEO_TYPE_UGC"
ATV = "MUSIC_VIDEO_TYPE_ATV"
OFFICIAL_SOURCE_MUSIC = "MUSIC_VIDEO_TYPE_OFFICIAL_SOURCE_MUSIC"
Loading
Loading