daraus speichere ich gewisse einträge in einem file
js sieht wie folgt aus
Code: Alles auswählen
{"js":{"total_items":1,"max_page_items":14,"selected_item":0,"cur_page":0,"data":[{"id":"1693:1","owner":"","name":"Season 1","old_name":"","o_name":"Season 1","fname":"","description":"N\/A","pic":"","cost":0,"time":"N\/a","file":"","path":"Pi\u0119kni_i_bezrobotni","protocol":"","rtsp_url":"","censored":0,"series":[1,2,3,4,5,6],"volume_correction":0,"category_id":"367","genre_id":0,"genre_id_1":0,"genre_id_2":0,"genre_id_3":0,"hd":1,"genre_id_4":0,"cat_genre_id_1":"367","cat_genre_id_2":0,"cat_genre_id_3":0,"cat_genre_id_4":0,"director":"N\/A","actors":"Robert G\u00f3rski, Miko\u0142aj Cie\u015blak, Wojciech Kalarus, Anna Karczmarczyk","year":"2021-03-06","accessed":1,"status":1,"disable_for_hd_devices":0,"added":"2021-10-06 14:31:04","count":0,"count_first_0_5":0,"count_second_0_5":0,"vote_sound_good":0,"vote_sound_bad":0,"vote_video_good":0,"vote_video_bad":0,"rate":"","last_rate_update":"","last_played":"","for_sd_stb":0,"rating_imdb":"N\/A","rating_count_imdb":"","rating_last_update":"0000-00-00 00:00:00","age":"12+","high_quality":0,"rating_kinopoisk":"N\/A","comments":"","low_quality":0,"is_series":1,"year_end":0,"autocomplete_provider":"imdb","screenshots":"","is_movie":1,"lock":0,"fav":0,"for_rent":0,"screenshot_uri":"https:\/\/image.tmdb.org\/t\/p\/w600_and_h900_bestv2\/mI6P1Md9FUXZnm6hug81DQLl26p.jpg","genres_str":"Comedy","cmd":"eyJ0eXBlIjoic2VyaWVzIiwic2VyaWVzX2lkIjoxNjkzLCJzZWFzb25fbnVtIjoxfQ==","week_and_more":"October 2021","has_files":0}]}}
Code: Alles auswählen
def getSeasons(portal_mac, url, serial, path):
args = urllib.parse.parse_qs(sys.argv[2][1:])
cat = args['cat'][0];
category = args['category'][0];
now = time();
portalurl = "_".join(re.findall("[a-zA-Z0-9]+", url));
portalurl = path + '/' + portalurl + '-season'+cat;
setMac(portal_mac);
#setSerialNumber(serial);
if not os.path.exists(path):
os.makedirs(path)
if os.path.exists(portalurl):
#check last time
with open(portalurl, 'rb') as data_file: data = json.load(data_file);
if 'version' not in data or data['version'] != cache_version:
clearCache(url, path);
else:
time_init = float(data['time']);
# update 12h
if ((now - time_init) / 3600) < 12:
return data;
handshake(url);
data = '{ "version" : "' + cache_version + '", "time" : "' + str(now) + '", "season'+cat+'" : [ \n'
page = 1;
pages = 300;
total_items = 1.0;
max_page_items = 1.0;
while True:
info = retrieveData(url, values = {
'type' : 'series',
'action' : 'get_ordered_list',
'category' : category,
'movie_id' : cat,
'sortby' : 'added',
'season_id' : '0',
'episod_id' : '0',
'p' : page,
'JsHttpRequest' : '1-xml'})
total_items = float(info['js']['total_items']);
max_page_items = float(info['js']['max_page_items']);
pages = math.ceil(total_items/max_page_items);
results = info['js']['data']
for i in results:
cat = i["id"]
name = i["name"]
cmd = i['cmd']
logo = i["screenshot_uri"]
plot = i["description"]
plot = plot.replace('"',"-")
plot = plot.replace("\r","")
plot = plot.replace("\n", " ")
plot = plot.replace(" "," ")
genre = i['genres_str']
year = i["year"]
category = i['category_id']
data += '{'
data += '"category":"' + category + '", '
data += '"cat":"' + cat + '", '
data += '"name":"' + name + '", '
data += '"cmd":"' + cmd + '", '
data += '"logo":"' + logo + '", '
data += '"plot":"' + plot + '", '
data += '"genre":"' + genre + '", '
data += '"year":"' + year + '"}, \n'
page += 1;
if page > pages or page == 300:
break;
data = data[:-3] + '\n]}'
with open(portalurl, 'wb') as f: f.write(data.encode('utf-8'));
return json.loads(data.encode('utf-8'), strict=False);
jetzt möchte ih noch ein 2tes file abspeichern mit dem inhalt aus
results = info['js']['data']['series']
damit möchte ich zu diesem inhalt kommen : --- "series":[1,2,3,4,5,6] ---
da bekomme ich aber den fehler wie oben in der Beschreibung
"list indices must be integers or slices, not str"
wie komme ich an diesen eintrag und wie kann ich ihn am besten "umbenennen"
so würde ich es brauchen
"episode":"' +zahl+'" (1 nächstes 2 nächstes 3 usw)
so wie oben im script mit den anderen daten halt
das dann eine datei entsteht wo in jeder zeile/eintrag dann fortlaufend die zahl steht
das andere benötigte kann ich mir ja dann von der erstellten datei holen.
lg ronald und danke fürs helfen