0

I am a new learner to Python and am being asked to write a program that asks the user for a search term and then perform a search using the iTunes search service for the entity type album. The program should then print how many search results where returned. For each result print the artist name, the album name and track count. I am supposed to use the get() function and the json() method.

Can someone please start me on the right path? I feel lost with this program.

Linda
  • 1
  • 1
  • Please try something first, and then post your question with your codes, errors. – Sachith Muhandiram May 19 '22 at 01:53
  • I don't know where to start. Let me ask this... how would I perform a search using the iTunes search service? Is this a library I should have access to? – Linda May 19 '22 at 23:20

3 Answers3

2

Install the package iGetMusic by:

pip install iGetMusic

This allows you to search songs via:

import iGetMusic
song = iGetMusic.get(term="SEARCH TERM")

#And get the author via:

song[x].getArtistName()

For more infos to iGetMusic visit:
iGetMusic Github

Waradu
  • 154
  • 9
0

Linda, I think we're in the same OpenSAP class... this should get you going.

import json
import requests as r

x = input("Please enter a search term: ")
url = f'https://itunes.apple.com/search?term={x}&entity=album' 
r = r.get(url) 

print(f"The search returned {r.text.count(x)} results."
JAK
  • 1
0
import requests as r
Count = 0
artist = ""
album = ""
trackcount = 0
x = input("Please enter a search term: ")
url = f"https://itunes.apple.com/search?term={x}&entity=album"
f = r.get(url) 
d = f.json()
for x in d:
    if x == "resultCount":
        count = d["resultCount"]
        print(f"The search returned {str(count)} results.")
    elif x == "results":
        for lx in d["results"]:
            artist = lx["artistName"]
            album = lx["collectionName"]
            trackcount = lx["trackCount"]
            print(f"Artist: {artist} - Album: {album} - Track Count: {str(trackcount)}")