How do I build a Python program with the iTune ssearch service

710 views Asked by At

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.

3

There are 3 answers

0
Waradu On

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

0
JAK On

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."
0
Udayakumar M On
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)}")