def download(url, token, filename=None, savepath=None, session=None, chunksize=<NUM_LIT>,<EOL>unpack=False, mocked=False, showstatus=False):
from plexapi import log<EOL>session = session or requests.Session()<EOL>headers = {'<STR_LIT>': token}<EOL>response = session.get(url, headers=headers, stream=True)<EOL>savepath = savepath or os.getcwd()<EOL>compat.makedirs(savepath, exist_ok=True)<EOL>if not filename and response.headers.get('<STR_LIT>'):<EOL><INDENT>filename = re.findall(r'<STR_LIT>', response.headers.get('<STR_LIT>'))<EOL>filename = filename[<NUM_LIT:0>] if filename[<NUM_LIT:0>] else None<EOL><DEDENT>filename = os.path.basename(filename)<EOL>fullpath = os.path.join(savepath, filename)<EOL>extension = os.path.splitext(fullpath)[-<NUM_LIT:1>]<EOL>if not extension:<EOL><INDENT>contenttype = response.headers.get('<STR_LIT>')<EOL>if contenttype and '<STR_LIT:image>' in contenttype:<EOL><INDENT>fullpath += contenttype.split('<STR_LIT:/>')[<NUM_LIT:1>]<EOL><DEDENT><DEDENT>if mocked:<EOL><INDENT>log.debug('<STR_LIT>', fullpath)<EOL>return fullpath<EOL><DEDENT>log.info('<STR_LIT>', fullpath)<EOL>if showstatus:  <EOL><INDENT>total = int(response.headers.get('<STR_LIT>', <NUM_LIT:0>))<EOL>bar = tqdm(unit='<STR_LIT:B>', unit_scale=True, total=total, desc=filename)<EOL><DEDENT>with open(fullpath, '<STR_LIT:wb>') as handle:<EOL><INDENT>for chunk in response.iter_content(chunk_size=chunksize):<EOL><INDENT>handle.write(chunk)<EOL>if showstatus:<EOL><INDENT>bar.update(len(chunk))<EOL><DEDENT><DEDENT><DEDENT>if showstatus:  <EOL><INDENT>bar.close()<EOL><DEDENT>if fullpath.endswith('<STR_LIT>') and unpack:<EOL><INDENT>with zipfile.ZipFile(fullpath, '<STR_LIT:r>') as handle:<EOL><INDENT>handle.extractall(savepath)<EOL><DEDENT><DEDENT>return fullpath<EOL>
Helper to download a thumb, videofile or other media item. Returns the local
        path to the downloaded file.

       Parameters:
            url (str): URL where the content be reached.
            token (str): Plex auth token to include in headers.
            filename (str): Filename of the downloaded file, default None.
            savepath (str): Defaults to current working dir.
            chunksize (int): What chunksize read/write at the time.
            mocked (bool): Helper to do evertything except write the file.
            unpack (bool): Unpack the zip file.
            showstatus(bool): Display a progressbar.

        Example:
            >>> download(a_episode.getStreamURL(), a_episode.location)
            /path/to/file