mirror of
https://github.com/pkkid/python-plexapi
synced 2024-11-22 11:43:13 +00:00
init
This commit is contained in:
parent
0a6655fddd
commit
4f56b1ad6c
2 changed files with 54 additions and 19 deletions
|
@ -242,7 +242,7 @@ def download(url, filename=None, savepath=None, session=None, chunksize=4024,
|
|||
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 progressbar.
|
||||
Example:
|
||||
>>> download(a_episode.getStreamURL(), a_episode.location)
|
||||
/path/to/file
|
||||
|
@ -274,11 +274,16 @@ def download(url, filename=None, savepath=None, session=None, chunksize=4024,
|
|||
log.info('Downloading: %s', fullpath)
|
||||
if showstatus:
|
||||
bar = tqdm(unit='B', unit_scale=True)
|
||||
print(bar)
|
||||
with open(fullpath, 'wb') as handle:
|
||||
for chunk in response.iter_content(chunk_size=chunksize):
|
||||
handle.write(chunk)
|
||||
if showstatus:
|
||||
print(len(chunk))
|
||||
bar.update(len(chunk))
|
||||
|
||||
if showstatus:
|
||||
bar.close()
|
||||
# check we want to unzip the contents
|
||||
if fullpath.endswith('zip') and unpack:
|
||||
with zipfile.ZipFile(fullpath, 'r') as handle:
|
||||
|
@ -346,7 +351,12 @@ def choose(msg, items, attr):
|
|||
# Request choice from the user
|
||||
while True:
|
||||
try:
|
||||
number = int(input('%s: ' % msg))
|
||||
return items[number]
|
||||
inp = input('%s: ' % msg)
|
||||
if any(s in inp for s in (':', '::', '-')):
|
||||
idx = slice(*map(lambda x: int(x.strip()) if x.strip() else None, inp.split(':')))
|
||||
return items[idx]
|
||||
else:
|
||||
return items[int(inp)]
|
||||
|
||||
except (ValueError, IndexError):
|
||||
pass
|
||||
|
|
|
@ -7,7 +7,11 @@ manually searching the items from the command line wizard.
|
|||
|
||||
Original contribution by lad1337.
|
||||
"""
|
||||
import argparse, re
|
||||
import argparse
|
||||
import os
|
||||
import re
|
||||
import shutil
|
||||
|
||||
from plexapi import utils
|
||||
from plexapi.compat import unquote
|
||||
from plexapi.video import Episode, Movie, Show
|
||||
|
@ -17,15 +21,24 @@ VALID_TYPES = (Movie, Episode, Show)
|
|||
|
||||
def search_for_item(url=None):
|
||||
if url: return get_item_from_url(opts.url)
|
||||
server = utils.choose('Choose a Server', account.resources(), 'name').connect()
|
||||
servers = [s for s in account.resources() if 'server' in s.provides]
|
||||
server = utils.choose('Choose a Server', servers, 'name').connect()
|
||||
query = input('What are you looking for?: ')
|
||||
item = []
|
||||
items = [i for i in server.search(query) if i.__class__ in VALID_TYPES]
|
||||
item = utils.choose('Choose result', items, lambda x: '(%s) %s' % (x.type.title(), x.title[0:60]))
|
||||
if isinstance(item, Show):
|
||||
display = lambda i: '%s %s %s' % (i.grandparentTitle, i.seasonEpisode, i.title)
|
||||
item = utils.choose('Choose episode', item.episodes(), display)
|
||||
if not isinstance(item, (Movie, Episode)):
|
||||
raise SystemExit('Unable to download %s' % item.__class__.__name__)
|
||||
items = utils.choose('Choose result', items, lambda x: '(%s) %s' % (x.type.title(), x.title[0:60]))
|
||||
|
||||
if not isinstance(items, list):
|
||||
items = [items]
|
||||
|
||||
for i in items:
|
||||
if isinstance(i, Show):
|
||||
display = lambda i: '%s %s %s' % (i.grandparentTitle, i.seasonEpisode, i.title)
|
||||
item = utils.choose('Choose episode', i.episodes(), display)
|
||||
|
||||
if not isinstance(item, list):
|
||||
item = [item]
|
||||
|
||||
return item
|
||||
|
||||
|
||||
|
@ -48,15 +61,27 @@ def get_item_from_url(url):
|
|||
if __name__ == '__main__':
|
||||
# Command line parser
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument('--username', help='Your Plex username')
|
||||
parser.add_argument('--password', help='Your Plex password')
|
||||
parser.add_argument('-u', '--username', help='Your Plex username')
|
||||
parser.add_argument('-p', '--password', help='Your Plex password')
|
||||
parser.add_argument('--url', default=None, help='Download from URL (only paste after !)')
|
||||
opts = parser.parse_args()
|
||||
# Search item to download
|
||||
account = utils.getMyPlexAccount(opts)
|
||||
item = search_for_item(opts.url)
|
||||
# Download the item
|
||||
print("Downloading '%s' from %s.." % (item._prettyfilename(), item._server.friendlyName))
|
||||
filepaths = item.download('./', showstatus=True)
|
||||
for filepath in filepaths:
|
||||
print(' %s' % filepath)
|
||||
items = search_for_item(opts.url)
|
||||
for i in items:
|
||||
for z in i.media:
|
||||
for f in z.parts:
|
||||
try:
|
||||
# lets see if we can get the file without using pms.
|
||||
shutil.copyfile(f.file, os.getcwd())
|
||||
except IOError as e:
|
||||
print('no shutil', e)
|
||||
for filepath in i.download('./', showstatus=True):
|
||||
print(' %s' % filepath)
|
||||
|
||||
|
||||
#print(help(i))
|
||||
# Download the item
|
||||
#print("Downloading '%s' from %s.." % (i._prettyfilename(), i._server.friendlyName))
|
||||
#for filepath in i.download('./', showstatus=True):
|
||||
# print(' %s' % filepath)
|
||||
|
|
Loading…
Reference in a new issue