Arrange songs played on Spotify in order of number of views

Introduction

I usually listen to music on Spotify and sometimes I want to sort it in order of the number of views, but the number of views itself cannot be seen in the app.

Instead, Spotify's PC version site (https://www.spotify.com/jp/) You can download viewing history etc. as JSON format data.

So, I downloaded my data, counted it in Python, and displayed it.

** Download procedure ** Click the button from Profile> Privacy Settings> Download Your Data. You will receive a download link by email. It will take up to 30 days, so be patient.

I only use the standard library, so even if you don't know programming, you can use it by copying and executing it as long as you have Python on your PC.

I wrote it for myself, so I'm sorry if it doesn't work.

code

count.py


import json
import collections

#Read json data
# file_For path, specify your StreamingHistory file.
with open('file_path') as f:
    d = json.load(f)

list = []

print("Do you want to search the whole thing? y/n")
search_all = str(input())

print("How many times do you want to display it?")
count = int(input())

#Extraction of song title&Add to list
#In case of whole search
if search_all == "y":
    for i in d:
        list.append(i['trackName'])
#In case of specified search
elif search_all == "n":
    print("Please enter the artist")
    artist = str(input())
    for i in d:
        if(i['artistName'] == artist):
            list.append(i['trackName'])

#Get elements in order of appearance
c = collections.Counter(list)
c_list = c.most_common()

print("------------")
print("Song title,Views")

#Display the number of views above a certain level
for i in c_list:
    if i[1] >= count:
        print(i)

Display result

スクリーンショット 2020-06-24 18.24.25.png

Python is convenient because you can do various things quickly.

Recommended Posts

Arrange songs played on Spotify in order of number of views
Analyzing data on the number of corona patients in Japan
Count the number of characters in the text on the clipboard on mac
Get the number of readers of a treatise on Mendeley in Python
Get the number of views of Qiita
Change the order of PostgreSQL on Heroku
Project Euler # 17 "Number of Characters" in Python
Let's automatically display the lyrics of the song being played on iTunes in Python
Set an upper limit on the number of recursive function iterations in Python
Visualize the timeline of the number of issues on GitHub assigned to you in Python