0

forgive me, if if come straight out with it but python drives me nuts at something what seemed to be quite simple.

In a nutshell I'm writing an extension for a musicvideo scraper which is responsible for getting the fanart backdrop. Here is the URL: github.com/MViDLibraryToolKit/.../APICaller

So I was able to call the Fanart.tv API and receiving the right json response. My problem is that i'm to dumb to collect the URLs under the Element "artistbackground"

I search the internet and found a very similar post here at stackoverflow but unluckily this was concerning python2,API V2 and a different category at fanart.tv so I was not able to take use out of it. Here it was

Anyway, here is my poor Try to collect URLs to list

# --------------------- Response Verarbeitung

# Ausgabe zwecks Debug
# print(fanartTVresp)
# http://webservice.fanart.tv/v3/music/albums/ba853904-ae25-4ebb-89d6-c44cfbd71bd2?api_key=fdadba00cfaaf3621eaa748669256a9e&client_key=dce01d75553d7e3fbc2ad742aaf5d371

# zu befüllende Liste
url_list = []

# lade Web-Response
json_response = json.loads(fanartTVresp)

# durch Element artistbackground loopen

for artistbackground in json_response:
    url = urllib.parse.quote(['url'], ':/')
    if url:
        url_list.append(url)
print(url_list)

The libs I loaded...

import musicbrainzngs
import urllib
import json
import socket
from pprint import pprint
from urllib.parse import quote

The rest from the code you can find at my github link. Please help me, it drives me crazy ^^

Kind regards

p.s. Please excuse my english, I came from germany :)

Nils
  • 3
  • 4

1 Answers1

0

I think I finally got it.

# URL List for background images
url_list = []

# set only for debug / value came from  powershell runtime later
location = os.path.abspath('C:/temp')


# decode json
json_response = json.loads(fanartTVresp.decode())

# set string objects

bgitem = json_response["artistbackground"]

bgcoverurl = json_response["artistbackground"][0]["url"]

# iterating items and collect
for bgcoverurl in bgitem:
    url_list.append(bgcoverurl)
    print(url_list)

After taking some hourse of sleep I reallized that "json.loads" deserialized the response to regular python objects. Correct me if I'm wrong. Anyway, it finally works!

Nils
  • 3
  • 4