Skip to content

Commit

Permalink
Merge pull request #1 from danielhoherd/refactor-and-fix
Browse files Browse the repository at this point in the history
Refactor and fix.
  • Loading branch information
danielhoherd committed Jan 3, 2019
2 parents 707d89a + 1e47d29 commit 1ddde79
Show file tree
Hide file tree
Showing 12 changed files with 114 additions and 273 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ build/
dist/
env/
venv/
Pipfile.lock
1 change: 1 addition & 0 deletions LICENSE
6 changes: 0 additions & 6 deletions Pipfile
Original file line number Diff line number Diff line change
@@ -1,21 +1,15 @@
[[source]]

url = "https://pypi.python.org/simple"
verify_ssl = true
name = "pypi"


[dev-packages]



[packages]

blessings = "==1.6"
bpython = "*"
certifi = "==2017.7.27.1"
chardet = "==3.0.4"
click = "==6.7"
curtsies = "==0.2.11"
greenlet = "==0.4.12"
idna = "==2.6"
Expand Down
162 changes: 0 additions & 162 deletions Pipfile.lock

This file was deleted.

24 changes: 24 additions & 0 deletions UNLICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
This is free and unencumbered software released into the public domain.

Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a compiled
binary, for any purpose, commercial or non-commercial, and by any
means.

In jurisdictions that recognize copyright laws, the author or authors
of this software dedicate any and all copyright interest in the
software to the public domain. We make this dedication for the benefit
of the public at large and to the detriment of our heirs and
successors. We intend this dedication to be an overt act of
relinquishment in perpetuity of all present and future rights to this
software under copyright law.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.

For more information, please refer to <http://unlicense.org/>
63 changes: 63 additions & 0 deletions plexdl/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# -*- coding: utf-8 -*-
import logging

import requests
from plexapi.myplex import MyPlexAccount
from plexapi.server import PlexServer

logging.basicConfig(
format='%(asctime)s %(levelname)s: %(message)s',
datefmt='%FT%T%z',
level='WARN',
)


class Client:
"""A client interface to plex for finding direct download URLs"""

@staticmethod
def print_item_info(item, access_token):
if hasattr(item, 'iterParts'):
locations = [i for i in item.iterParts() if i]
media_info = ' {}'.format(item.title)
for location in locations:
download_url = item._server.url('{}?download=1&X-Plex-Token={}'.format(location.key, access_token))
if item.media[0].width is not None:
media_info += ' {}x{}'.format(item.media[0].width, item.media[0].height)
if item.media[0].videoCodec is not None:
media_info += ' {}'.format(item.media[0].videoCodec)
if item.media[0].audioCodec is not None:
media_info += ' {}'.format(item.media[0].audioCodec)
if item.media[0].bitrate is not None:
media_info += ' {}kbps'.format(item.media[0].bitrate)
print(media_info)
print(' curl -o "{}.{}" "{}"'
.format(item.title,
location.container,
download_url))

def main(self, username, password, title):
account = MyPlexAccount(username, password)
available_resources = list()

for r in account.resources():
if r.product == 'Plex Media Server':
available_resources.append(r)

for this_resource in available_resources:
if not this_resource.presence:
continue
try:
this_server = PlexServer(this_resource.connections[-1:][0].uri, this_resource.accessToken)
print('\nSearching server: "{}"\n Plex version: {}\n OS: {} {}'
.format(this_server.friendlyName,
this_server.version,
this_server.platform,
this_server.platformVersion))
for item in this_server.search(title, mediatype='movie'):
self.print_item_info(item, this_resource.accessToken)

except requests.exceptions.ConnectionError as e:
print(' ERROR: something went wrong with "{}"'.format(this_resource.name))
print(e)
pass
24 changes: 14 additions & 10 deletions plexdl/cli.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
# -*- coding: utf-8 -*-
import click
import argparse

import plexdl


@click.command()
@click.option('--username', envvar='PLEXDL_USER',
required=True, help='Your plex username')
@click.option('--password', envvar='PLEXDL_PASS',
required=True, help='Your plex password')
@click.argument('title')
def main(username, password, title):
def parse_args():
parser = argparse.ArgumentParser(description='Search your Plex libraries and show download URLs')
parser.add_argument('--debug', action='store_true', help='Enable debug output')
parser.add_argument('--username', required=True, help='Your plex username')
parser.add_argument('--password', required=True, help='Your plex password')
parser.add_argument('title', help='Title to search for')
return parser.parse_args()


def main():
"""Searches your plex account for media matching the given string, then prints out download commands."""
p = plexdl.client()
p.main(username, password, title)
args = parse_args()
p = plexdl.Client()
p.main(args.username, args.password, args.title)


if __name__ == '__main__':
Expand Down
56 changes: 0 additions & 56 deletions plexdl/plexdl.py

This file was deleted.

15 changes: 0 additions & 15 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,19 +1,4 @@
blessings==1.6
bpython==0.16
certifi==2017.7.27.1
chardet==3.0.4
click==6.7
coverage
curtsies==0.2.11
greenlet==0.4.12
idna==2.6
pkg-release
PlexAPI==3.0.3
pre-commit>=0.15.0
Pygments==2.2.0
pytest
requests==2.18.4
six==1.11.0
urllib3==1.22
wcwidth==0.1.7
websocket-client==0.44.0

0 comments on commit 1ddde79

Please sign in to comment.