[GH-ISSUE #6] Feature Suggestion #5

Closed
opened 2026-02-27 20:07:39 +03:00 by kerem · 6 comments
Owner

Originally created by @tomballgithub on GitHub (Mar 31, 2025).
Original GitHub issue: https://github.com/misiektoja/spotify_profile_monitor/issues/6

I made some edits to this tool to allow it to do a few things:

  1. flag to have -L (list tracks for playlist) output in a format that is directly importable into spotify_monitor so that it can be automated. This could be used to dump a private playlist that would not otherwise show up in the friends' info from spotify. You just have to not print all the header and footer messaging, strip the whitespace, and only use the first column.

  2. flag to dump the 'liked songs' playlist from the user associated with the SP_DC cookie. The intent is to be directly importable into spotify_monitor, but the code below actually does {p_artist} - {p_track} because I made a change to spotify_monitor to support that

My code for #1 isn't clean and there's no way you would leverage it.

Below is what I did for #2

Of course, feel free to delete this entire suggestion since we might be the only two using this tool :-) I added all the features of my Node.js tool into your code base since you are maintaining it, and Python is more straightforward.

# Function returning detailed info about tracks saved by current user
def spotify_get_user_saved_tracks(access_token):
    url2 = f"https://api.spotify.com/v1/me/tracks?market=EN&limit=50"
      
    headers = {
        "Authorization": f"Bearer {access_token}",
        "Client-Id": SP_CACHED_CLIENT_ID,
        "User-Agent": SP_CACHED_USER_AGENT,
    }
    # add si parameter so link opens in native Spotify app after clicking
    si = "?si=1"

    try:
        sp_playlist_tracks_concatenated_list = []
        next_url = url2
        while next_url:
            response2 = req.get(next_url, headers=headers, timeout=FUNCTION_TIMEOUT, verify=VERIFY_SSL)
            response2.raise_for_status()
            json_response2 = response2.json()
#            print(json.dumps(json_response2))

            for track in json_response2.get("items"):
                sp_playlist_tracks_concatenated_list.append(track)

            next_url = json_response2.get("next")

        sp_playlist_tracks = sp_playlist_tracks_concatenated_list
        if sp_playlist_tracks:
            sp_playlist_tracks_count_tmp = len(sp_playlist_tracks)
            if sp_playlist_tracks_count_tmp > 0:
                sp_playlist_tracks_count = sp_playlist_tracks_count_tmp

        return {"sp_playlist_tracks_count": sp_playlist_tracks_count, "sp_playlist_tracks": sp_playlist_tracks}

    except Exception:
        raise

# Function listing tracks for current user's saved tracks
def spotify_list_saved_tracks(sp_accessToken):

    user_id_name_mapping = {}

    sp_playlist_data = spotify_get_user_saved_tracks(sp_accessToken)

    p_tracks = sp_playlist_data.get("sp_playlist_tracks_count", 0)
    p_tracks_list = sp_playlist_data.get("sp_playlist_tracks", None)
    if p_tracks_list is not None:
        for index, track in enumerate(p_tracks_list):
            p_artist = track["track"]["artists"][0].get("name", None)
            p_track = track["track"].get("name", None)
            duration_ms = track["track"].get("duration_ms")
            if p_artist and p_track and int(duration_ms) >= 1000:
                artist_track = f"{p_artist} - {p_track}"
                line_new = f"{artist_track}"
                print(line_new)

    parser.add_argument("-r", "--list_saved_tracks", help="List all tracks for user associated with selected SP_DC_COOKIE", action='store_true')

    if args.list_saved_tracks:
        try:
            sp_accessToken = spotify_get_access_token(SP_DC_COOKIE)
            spotify_list_saved_tracks(sp_accessToken)
        except Exception as e:
            if 'Not Found' in str(e) or '400 Client' in str(e):
                print("* Error: playlist does not exist or is set to private")
            else:
                print(f"* Error - {e}")
            sys.exit(1)
        sys.exit(0)
      

Originally created by @tomballgithub on GitHub (Mar 31, 2025). Original GitHub issue: https://github.com/misiektoja/spotify_profile_monitor/issues/6 I made some edits to this tool to allow it to do a few things: 1. flag to have -L (list tracks for playlist) output in a format that is directly importable into spotify_monitor so that it can be automated. This could be used to dump a private playlist that would not otherwise show up in the friends' info from spotify. You just have to not print all the header and footer messaging, strip the whitespace, and only use the first column. 2. flag to dump the 'liked songs' playlist from the user associated with the SP_DC cookie. The intent is to be directly importable into spotify_monitor, but the code below actually does {p_artist} - {p_track} because I made a change to spotify_monitor to support that My code for #1 isn't clean and there's no way you would leverage it. Below is what I did for #2 Of course, feel free to delete this entire suggestion since we might be the only two using this tool :-) I added all the features of my Node.js tool into your code base since you are maintaining it, and Python is more straightforward. ``` # Function returning detailed info about tracks saved by current user def spotify_get_user_saved_tracks(access_token): url2 = f"https://api.spotify.com/v1/me/tracks?market=EN&limit=50" headers = { "Authorization": f"Bearer {access_token}", "Client-Id": SP_CACHED_CLIENT_ID, "User-Agent": SP_CACHED_USER_AGENT, } # add si parameter so link opens in native Spotify app after clicking si = "?si=1" try: sp_playlist_tracks_concatenated_list = [] next_url = url2 while next_url: response2 = req.get(next_url, headers=headers, timeout=FUNCTION_TIMEOUT, verify=VERIFY_SSL) response2.raise_for_status() json_response2 = response2.json() # print(json.dumps(json_response2)) for track in json_response2.get("items"): sp_playlist_tracks_concatenated_list.append(track) next_url = json_response2.get("next") sp_playlist_tracks = sp_playlist_tracks_concatenated_list if sp_playlist_tracks: sp_playlist_tracks_count_tmp = len(sp_playlist_tracks) if sp_playlist_tracks_count_tmp > 0: sp_playlist_tracks_count = sp_playlist_tracks_count_tmp return {"sp_playlist_tracks_count": sp_playlist_tracks_count, "sp_playlist_tracks": sp_playlist_tracks} except Exception: raise # Function listing tracks for current user's saved tracks def spotify_list_saved_tracks(sp_accessToken): user_id_name_mapping = {} sp_playlist_data = spotify_get_user_saved_tracks(sp_accessToken) p_tracks = sp_playlist_data.get("sp_playlist_tracks_count", 0) p_tracks_list = sp_playlist_data.get("sp_playlist_tracks", None) if p_tracks_list is not None: for index, track in enumerate(p_tracks_list): p_artist = track["track"]["artists"][0].get("name", None) p_track = track["track"].get("name", None) duration_ms = track["track"].get("duration_ms") if p_artist and p_track and int(duration_ms) >= 1000: artist_track = f"{p_artist} - {p_track}" line_new = f"{artist_track}" print(line_new) parser.add_argument("-r", "--list_saved_tracks", help="List all tracks for user associated with selected SP_DC_COOKIE", action='store_true') if args.list_saved_tracks: try: sp_accessToken = spotify_get_access_token(SP_DC_COOKIE) spotify_list_saved_tracks(sp_accessToken) except Exception as e: if 'Not Found' in str(e) or '400 Client' in str(e): print("* Error: playlist does not exist or is set to private") else: print(f"* Error - {e}") sys.exit(1) sys.exit(0) ```
kerem 2026-02-27 20:07:39 +03:00
  • closed this issue
  • added the
    Stale
    label
Author
Owner

@misiektoja commented on GitHub (Mar 31, 2025):

Hey, I like the ideas! Please open pull requests for both of them, so you take credits for it.

Even if the code for number 1 is not clean, please also share as PR, I will try to consolidate it so it fits into the base code.

<!-- gh-comment-id:2765943618 --> @misiektoja commented on GitHub (Mar 31, 2025): Hey, I like the ideas! Please open pull requests for both of them, so you take credits for it. Even if the code for number 1 is not clean, please also share as PR, I will try to consolidate it so it fits into the base code.
Author
Owner

@tomballgithub commented on GitHub (Mar 31, 2025):

I need to figure out how to use git again but will get around to it this
week.

  • Jeoff

On Mon, Mar 31, 2025, 6:27 AM Michal Szymanski @.***>
wrote:

Hey, I like the ideas! Please open pull requests for both of them, so you
take credits for it.

Even if the code for number 1 is not clean, please also share as PR, I
will try to consolidate it so it fits into the base code.


Reply to this email directly, view it on GitHub
https://github.com/misiektoja/spotify_profile_monitor/issues/6#issuecomment-2765943618,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/ADVRWS7QTG7FJ7TC2GUENB32XERDBAVCNFSM6AAAAAB2DHG7ZWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDONRVHE2DGNRRHA
.
You are receiving this because you authored the thread.Message ID:
@.***>
[image: misiektoja]misiektoja left a comment
(misiektoja/spotify_profile_monitor#6)
https://github.com/misiektoja/spotify_profile_monitor/issues/6#issuecomment-2765943618

Hey, I like the ideas! Please open pull requests for both of them, so you
take credits for it.

Even if the code for number 1 is not clean, please also share as PR, I
will try to consolidate it so it fits into the base code.


Reply to this email directly, view it on GitHub
https://github.com/misiektoja/spotify_profile_monitor/issues/6#issuecomment-2765943618,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/ADVRWS7QTG7FJ7TC2GUENB32XERDBAVCNFSM6AAAAAB2DHG7ZWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDONRVHE2DGNRRHA
.
You are receiving this because you authored the thread.Message ID:
@.***>

<!-- gh-comment-id:2766532989 --> @tomballgithub commented on GitHub (Mar 31, 2025): I need to figure out how to use git again but will get around to it this week. - Jeoff On Mon, Mar 31, 2025, 6:27 AM Michal Szymanski ***@***.***> wrote: > Hey, I like the ideas! Please open pull requests for both of them, so you > take credits for it. > > Even if the code for number 1 is not clean, please also share as PR, I > will try to consolidate it so it fits into the base code. > > — > Reply to this email directly, view it on GitHub > <https://github.com/misiektoja/spotify_profile_monitor/issues/6#issuecomment-2765943618>, > or unsubscribe > <https://github.com/notifications/unsubscribe-auth/ADVRWS7QTG7FJ7TC2GUENB32XERDBAVCNFSM6AAAAAB2DHG7ZWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDONRVHE2DGNRRHA> > . > You are receiving this because you authored the thread.Message ID: > ***@***.***> > [image: misiektoja]*misiektoja* left a comment > (misiektoja/spotify_profile_monitor#6) > <https://github.com/misiektoja/spotify_profile_monitor/issues/6#issuecomment-2765943618> > > Hey, I like the ideas! Please open pull requests for both of them, so you > take credits for it. > > Even if the code for number 1 is not clean, please also share as PR, I > will try to consolidate it so it fits into the base code. > > — > Reply to this email directly, view it on GitHub > <https://github.com/misiektoja/spotify_profile_monitor/issues/6#issuecomment-2765943618>, > or unsubscribe > <https://github.com/notifications/unsubscribe-auth/ADVRWS7QTG7FJ7TC2GUENB32XERDBAVCNFSM6AAAAAB2DHG7ZWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDONRVHE2DGNRRHA> > . > You are receiving this because you authored the thread.Message ID: > ***@***.***> >
Author
Owner

@tomballgithub commented on GitHub (Apr 9, 2025):

Question. Would you mind sharing how you are using git with your repository yet not checking in your custom info such as your cookie and smtp information? None of the normal ways I know for doing this seem to apply here. There must be something I'm missing.

<!-- gh-comment-id:2788243602 --> @tomballgithub commented on GitHub (Apr 9, 2025): Question. Would you mind sharing how you are using git with your repository yet not checking in your custom info such as your cookie and smtp information? None of the normal ways I know for doing this seem to apply here. There must be something I'm missing.
Author
Owner

@misiektoja commented on GitHub (Apr 9, 2025):

I have prepared a script that replaces all the secrets with some generic ones (just simple sed processing).

Here is the gist.

I have it set up in my Git client (I use Sublime Merge) and it runs before any push.

I also use this script to quickly reverse the changes and input some real data.

<!-- gh-comment-id:2789717903 --> @misiektoja commented on GitHub (Apr 9, 2025): I have prepared a script that replaces all the secrets with some generic ones (just simple sed processing). Here is the [gist](https://gist.github.com/misiektoja/fa31d0cd0905e3309cf0aead21e097a1). I have it set up in my Git client (I use Sublime Merge) and it runs before any push. I also use this script to quickly reverse the changes and input some real data.
Author
Owner

@tomballgithub commented on GitHub (Apr 10, 2025):

Thanks for sharing that with me. I will set something up similar

On Wed, Apr 9, 2025 at 8:25 AM Michal Szymanski @.***>
wrote:

I have prepared a script that replaces all the secrets with some generic
ones (just simple sed processing).

Here is the gist
https://gist.github.com/misiektoja/fa31d0cd0905e3309cf0aead21e097a1.

I have it set up in my Git client (I use Sublime Merge) and it runs before
any push.

I also use this script to quickly reverse the changes and input some real
data.


Reply to this email directly, view it on GitHub
https://github.com/misiektoja/spotify_profile_monitor/issues/6#issuecomment-2789717903,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/ADVRWS6PU7BQMZ4MKUQOOO32YUNUVAVCNFSM6AAAAAB2DHG7ZWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDOOBZG4YTOOJQGM
.
You are receiving this because you authored the thread.Message ID:
@.***>
misiektoja left a comment (misiektoja/spotify_profile_monitor#6)
https://github.com/misiektoja/spotify_profile_monitor/issues/6#issuecomment-2789717903

I have prepared a script that replaces all the secrets with some generic
ones (just simple sed processing).

Here is the gist
https://gist.github.com/misiektoja/fa31d0cd0905e3309cf0aead21e097a1.

I have it set up in my Git client (I use Sublime Merge) and it runs before
any push.

I also use this script to quickly reverse the changes and input some real
data.


Reply to this email directly, view it on GitHub
https://github.com/misiektoja/spotify_profile_monitor/issues/6#issuecomment-2789717903,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/ADVRWS6PU7BQMZ4MKUQOOO32YUNUVAVCNFSM6AAAAAB2DHG7ZWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDOOBZG4YTOOJQGM
.
You are receiving this because you authored the thread.Message ID:
@.***>

<!-- gh-comment-id:2791478372 --> @tomballgithub commented on GitHub (Apr 10, 2025): Thanks for sharing that with me. I will set something up similar On Wed, Apr 9, 2025 at 8:25 AM Michal Szymanski ***@***.***> wrote: > I have prepared a script that replaces all the secrets with some generic > ones (just simple sed processing). > > Here is the gist > <https://gist.github.com/misiektoja/fa31d0cd0905e3309cf0aead21e097a1>. > > I have it set up in my Git client (I use Sublime Merge) and it runs before > any push. > > I also use this script to quickly reverse the changes and input some real > data. > > — > Reply to this email directly, view it on GitHub > <https://github.com/misiektoja/spotify_profile_monitor/issues/6#issuecomment-2789717903>, > or unsubscribe > <https://github.com/notifications/unsubscribe-auth/ADVRWS6PU7BQMZ4MKUQOOO32YUNUVAVCNFSM6AAAAAB2DHG7ZWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDOOBZG4YTOOJQGM> > . > You are receiving this because you authored the thread.Message ID: > ***@***.***> > *misiektoja* left a comment (misiektoja/spotify_profile_monitor#6) > <https://github.com/misiektoja/spotify_profile_monitor/issues/6#issuecomment-2789717903> > > I have prepared a script that replaces all the secrets with some generic > ones (just simple sed processing). > > Here is the gist > <https://gist.github.com/misiektoja/fa31d0cd0905e3309cf0aead21e097a1>. > > I have it set up in my Git client (I use Sublime Merge) and it runs before > any push. > > I also use this script to quickly reverse the changes and input some real > data. > > — > Reply to this email directly, view it on GitHub > <https://github.com/misiektoja/spotify_profile_monitor/issues/6#issuecomment-2789717903>, > or unsubscribe > <https://github.com/notifications/unsubscribe-auth/ADVRWS6PU7BQMZ4MKUQOOO32YUNUVAVCNFSM6AAAAAB2DHG7ZWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDOOBZG4YTOOJQGM> > . > You are receiving this because you authored the thread.Message ID: > ***@***.***> >
Author
Owner

@github-actions[bot] commented on GitHub (May 11, 2025):

This issue has been marked as stale because it has been inactive for 30 days. It will be closed in 7 days if no further activity occurs.

<!-- gh-comment-id:2869321298 --> @github-actions[bot] commented on GitHub (May 11, 2025): This issue has been marked as stale because it has been inactive for 30 days. It will be closed in 7 days if no further activity occurs.
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/spotify_profile_monitor#5
No description provided.