Skip to content

Instantly share code, notes, and snippets.

@lad1337
Last active September 5, 2017 12:18
Show Gist options
  • Save lad1337/72880debc1dcc6922f5bf39eaad3072c to your computer and use it in GitHub Desktop.
Save lad1337/72880debc1dcc6922f5bf39eaad3072c to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
import sys
# run this: pip install git+https://github.com/lad1337/python-plexapi@feature/download-progress
USAGE = "usage: python pcp.py <username> [<password>]"
from plexapi.myplex import MyPlexAccount
from plexapi.video import Episode
from plexapi.video import Movie
from plexapi.video import Show
def choose(msg, items, attr_name):
for index, i in enumerate(items):
if callable(attr_name):
name = attr_name(i)
else:
name = getattr(i, attr_name)
print("{index}: {name}".format(index=index, name=name))
picked = map(int, (input("{}: ".format(msg))).split(','))
if len(picked) == 1:
return items[picked[0]]
else:
return [items[p] for p in picked]
def search(server):
query = input("What are you looking for?: ")
return choose("Choose result", server.search(query), lambda x: repr(x))
def download(item):
print("Loading...")
files = wanted_item.download('./')
print("Complete.")
for f in files:
print("- {}".format(f))
def main():
args = sys.argv[1:]
if len(args) == 2:
user, pw = args
elif len(args) == 1:
user = args[0]
import getpass
pw = getpass.getpass()
else:
print(USAGE)
exit(1)
account = MyPlexAccount(user, pw)
res = choose("Choose a server", account.resources(), 'name')
print("Connecting...")
server = res.connect()
print("Connected!")
found_item = search(server)
if isinstance(found_item, Show):
wanted_item = choose("Choose episode", found_item.episodes(), lambda x: x._prettyfilename())
elif isinstance(found_item, (Movie, Episode)):
wanted_item = found_item
else:
print("dont know what to to with {}".format(found_item))
exit(1)
if isinstance(wanted_item, list):
print("downloading {} items".format(len(wanted_item)))
for wanted_i in wanted_item:
download(wanted_i)
else:
download(wanted_item)
if __name__ == "__main__":
main()
@lad1337
Copy link
Author

lad1337 commented Aug 11, 2017

This is plex cp (pcp):

  • it works with shared servers
  • if you use the pip install git+https://github.com/lad1337/python-plexapi@feature/download-progress it has a download bar
  • it is / has a wizard
  • BUT it can only load one file at a time
  • AND its only a wizard, no pre defined arguments let you use it copy just in one command
  • it will always copy the target into the current directory, with plex's naming scheme

@pkkid
Copy link

pkkid commented Aug 11, 2017

Hey lad1337. This looks quite useful. Do you mind if I include this in the python-plexapi tools directory?

@lad1337
Copy link
Author

lad1337 commented Aug 11, 2017

no, sure go ahead, i would be honoured :)

@pkkid
Copy link

pkkid commented Aug 13, 2017

Thanks! -- I changed the formating slightly and added an option to download from a PlexWeb url. You can use that by calling plex-download.py --url=<URL> (just make sure to only copy everything after the ! in the url). I love your choose function, I'll be using that very often in the future.

https://github.com/pkkid/python-plexapi/blob/master/tools/plex-download.py

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment