[GH-ISSUE #601] Edge case in edit_playlist: moving a title to the end of the playlist #413

Closed
opened 2026-02-27 23:00:39 +03:00 by kerem · 3 comments
Owner

Originally created by @AltoRetrato on GitHub (Jun 16, 2024).
Original GitHub issue: https://github.com/sigma67/ytmusicapi/issues/601

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.

Originally created by @AltoRetrato on GitHub (Jun 16, 2024). Original GitHub issue: https://github.com/sigma67/ytmusicapi/issues/601 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: ```python moveItem: Optional[Tuple[str, str]] = None, [...] if moveItem: actions.append( { "action": "ACTION_MOVE_VIDEO_BEFORE", "setVideoId": moveItem[0], "movedSetVideoIdSuccessor": moveItem[1], } ) ``` to: ```python 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.
kerem 2026-02-27 23:00:39 +03:00
  • closed this issue
  • added the
    bug
    label
Author
Owner

@sigma67 commented on GitHub (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.

<!-- gh-comment-id:2171793628 --> @sigma67 commented on GitHub (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.
Author
Owner

@sigma67 commented on GitHub (Jun 16, 2024):

Contribution welcome.

<!-- gh-comment-id:2171793684 --> @sigma67 commented on GitHub (Jun 16, 2024): Contribution welcome.
Author
Owner

@AltoRetrato commented on GitHub (Jun 16, 2024):

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.

<!-- gh-comment-id:2171919549 --> @AltoRetrato commented on GitHub (Jun 16, 2024): > 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 in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/ytmusicapi#413
No description provided.