'Get the PlexPy history.
Required parameters:
None
Optional parameters:
grouping (int):                 0 or 1
user (str):                     "Jon Snow"
user_id (int):                  133788
rating_key (int):               4348
parent_rating_key (int):        544
grandparent_rating_key (int):   351
start_date (str):               "YYYY-MM-DD"
section_id (int):               2
media_type (str):               "movie", "episode", "track"
transcode_decision (str):       "direct play", "copy", "transcode",
order_column (str):             "date", "friendly_name", "ip_address", "platform", "player",
"full_title", "started", "paused_counter", "stopped", "duration"
order_dir (str):                "desc" or "asc"
start (int):                    Row to start from, 0
length (int):                   Number of items to return, 25
search (str):                   A string to search for, "Thrones"
Returns:
json:
{"draw": 1,
"recordsTotal": 1000,
"recordsFiltered": 250,
"total_duration": "42 days 5 hrs 18 mins",
"filter_duration": "10 hrs 12 mins",
"data":
[{"year": 2016,
"paused_counter": 0,
"player": "Plex Web (Chrome)",
"parent_rating_key": 544,
"parent_title": "",
"duration": 263,
"transcode_decision": "transcode",
"rating_key": 4348,
"user_id": 8008135,
"thumb": "/library/metadata/4348/thumb/1462414561",
"id": 1124,
"platform": "Chrome",
"media_type": "episode",
"grandparent_rating_key": 351,
"started": 1462688107,
"full_title": "Game of Thrones - The Red Woman",
"reference_id": 1123,
"date": 1462687607,
"percent_complete": 84,
"ip_address": "xxx.xxx.xxx.xxx",
"group_ids": "1124",
"media_index": 17,
"friendly_name": "Mother of Dragons",
"watched_status": 0,
"group_count": 1,
"stopped": 1462688370,
"parent_media_index": 7,
"user": "DanyKhaleesi69"'

@cherrypy.expose
@cherrypy.tools.json_out()
@requireAuth()
@addtoapi()
def get_history(self, user=None, user_id=None, grouping=None, **kwargs):

    if (not kwargs.get('json_data')):
        dt_columns = [('date', True, False), ('friendly_name', True, True), ('ip_address', True, True), ('platform', True, True), ('player', True, True), ('full_title', True, True), ('started', True, False), ('paused_counter', True, False), ('stopped', True, False), ('duration', True, False), ('watched_status', False, False)]
        kwargs['json_data'] = build_datatables_json(kwargs, dt_columns, 'date')
    if (grouping and str(grouping).isdigit()):
        grouping = int(grouping)
    elif (grouping == 'false'):
        grouping = 0
    custom_where = []
    if user_id:
        custom_where.append(['session_history.user_id', user_id])
    elif user:
        custom_where.append(['session_history.user', user])
    if ('rating_key' in kwargs):
        rating_key = kwargs.get('rating_key', '')
        custom_where.append(['session_history.rating_key', rating_key])
    if ('parent_rating_key' in kwargs):
        rating_key = kwargs.get('parent_rating_key', '')
        custom_where.append(['session_history.parent_rating_key', rating_key])
    if ('grandparent_rating_key' in kwargs):
        rating_key = kwargs.get('grandparent_rating_key', '')
        custom_where.append(['session_history.grandparent_rating_key', rating_key])
    if ('start_date' in kwargs):
        start_date = kwargs.get('start_date', '')
        custom_where.append(['strftime("%Y-%m-%d",    datetime(started,    "unixepoch",    "localtime"))', start_date])
    if ('reference_id' in kwargs):
        reference_id = kwargs.get('reference_id', '')
        custom_where.append(['session_history.reference_id', reference_id])
    if ('section_id' in kwargs):
        section_id = kwargs.get('section_id', '')
        custom_where.append(['session_history_metadata.section_id', section_id])
    if ('media_type' in kwargs):
        media_type = kwargs.get('media_type', '')
        if media_type:
            custom_where.append(['session_history.media_type', media_type])
    if ('transcode_decision' in kwargs):
        transcode_decision = kwargs.get('transcode_decision', '')
        if transcode_decision:
            custom_where.append(['session_history_media_info.transcode_decision', transcode_decision])
    data_factory = datafactory.DataFactory()
    history = data_factory.get_datatables_history(kwargs=kwargs, custom_where=custom_where, grouping=grouping)
    return history
