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

Edge case in edit_playlist: moving a title to the end of the playlist #601

Closed
AltoRetrato opened this issue Jun 16, 2024 · 3 comments
Closed
Labels
bug Something isn't working

Comments

@AltoRetrato
Copy link
Contributor

Hello, and thanks for the ytmusicapi! :D

The edit_playlist() method currently includes ACTION_MOVE_VIDEO_BEFORE, setVideoId, and movedSetVideoIdSuccessor in body["actions"] whenever the moveItem argument is defined. This mirrors the behavior of the YouTube Music client when a title is moved to a position above another one in a playlist.

However, when moving a title to the end of a playlist, the YouTube Music client performs a similar action but omits the movedSetVideoIdSuccessor field.

In order to allow ytmusicapi to do this as well, I suggest changing the edit_playlist() function from:

        moveItem: Optional[Tuple[str, str]] = None,
[...]
        if moveItem:
            actions.append(
                {
                    "action": "ACTION_MOVE_VIDEO_BEFORE",
                    "setVideoId": moveItem[0],
                    "movedSetVideoIdSuccessor": moveItem[1],
                }
            )

to:

        moveItem: Optional[Union[str, Tuple[str, str]]] = None,
[...]
        if moveItem:
            action = {
                        "action": "ACTION_MOVE_VIDEO_BEFORE",
                        "setVideoId": moveItem if isinstance(moveItem, str) else moveItem[0],
                     }
            if isinstance(moveItem, tuple) and len(moveItem) > 1:
                action["movedSetVideoIdSuccessor"] = moveItem[1]
            actions.append(action)

This way, moveItem can be a Tuple[str,str] (as it is today), as well as a single str or a Tuple[str,], allowing to move a title to the end of the playlist.

@sigma67
Copy link
Owner

sigma67 commented Jun 16, 2024

Interesting that you're the first one to stumble upon this, I haven't looked at this function in ages. Will have a closer look the next few days.

You should definitely be able to move an item to the end, if not I'd consider that a bug.

@sigma67 sigma67 added the bug Something isn't working label Jun 16, 2024
@sigma67
Copy link
Owner

sigma67 commented Jun 16, 2024

Contribution welcome.

@AltoRetrato
Copy link
Contributor Author

You should definitely be able to move an item to the end, if not I'd consider that a bug.

If I understand this correctly, without this change, you can only move an item A above another item, so it can never be moved directly to the bottom of a playlist. You can do it with two steps, though - by first moving item A to the position above the last item in the list (L), and then moving L above A.

You can create a playlist with a few items and move one to the bottom to see the "action" parameters in the Javascript Console.

Anyway, I did pull request #602.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants