예제 #1
0
def get_plexhistory(key):
    """ Fetch plex recently added. """
    values = {'items': []}
    plex = PlexServer()
    config = _get_config()
    accounts = {a.accountID: a.name for a in plex.systemAccounts()}
    mindate = datetime.now() - timedelta(days=30)
    history = plex.history(150, mindate=mindate)
    for vdata in history:
        video = {}
        video['type'] = vdata.type
        video['viewed'] = _datetime_to_str(vdata.viewedAt)
        video['title'] = _video_title(vdata)[:15]
        video['account'] = accounts.get(vdata.accountID, 'Unknown')
        video['account'] = config.plexhistory_names.get(
            video['account'], video['account'])[:6]
        if not _ignored(video['account'], config.plexhistory_ignore):
            values['items'].append(video)
    values['total'] = len(values['items'])
    with open(join(CACHE, f'{key}.json'), 'w') as handle:
        json.dump(values, handle)