Skip to content

Commit

Permalink
Switch to using python black
Browse files Browse the repository at this point in the history
  • Loading branch information
danielhoherd committed Jan 29, 2019
1 parent 089aa74 commit 9a3e4ae
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 56 deletions.
5 changes: 5 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[flake8]
ignore = E203, E266, E501, W503, F403, F401
max-line-length = 120
max-complexity = 18
select = B,C,E,F,W,T4,B9
18 changes: 7 additions & 11 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
repos:
- repo: git@github.com:pre-commit/pre-commit-hooks.git
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.1.0
hooks:
- id: check-byte-order-marker
Expand All @@ -10,7 +10,6 @@ repos:
- id: check-xml
- id: check-yaml
- id: debug-statements
- id: double-quote-string-fixer
- id: end-of-file-fixer
- id: fix-encoding-pragma
- id: flake8
Expand All @@ -19,23 +18,20 @@ repos:
- id: requirements-txt-fixer
- id: sort-simple-yaml
- id: trailing-whitespace
- repo: git@github.com:detailyang/pre-commit-shell.git
- repo: https://github.com/detailyang/pre-commit-shell
rev: 1.0.4
hooks:
- id: shell-lint
- repo: git@github.com:asottile/pyupgrade.git
rev: v1.11.0
- repo: https://github.com/ambv/black
rev: 18.9b0
hooks:
- id: pyupgrade
- repo: [email protected]:Lucas-C/pre-commit-hooks.git
- id: black
args: ['-l', '132']
- repo: https://github.com/Lucas-C/pre-commit-hooks
rev: v1.1.6
hooks:
- id: remove-tabs
exclude_types: [makefile]
- repo: [email protected]:asottile/reorder_python_imports.git
rev: v1.3.4
hooks:
- id: reorder-python-imports
- repo: https://github.com/adrienverge/yamllint.git
rev: v1.14.0
hooks:
Expand Down
30 changes: 14 additions & 16 deletions plexdl/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,40 +5,36 @@
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',
)
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'):
if hasattr(item, "iterParts"):
locations = [i for i in item.iterParts() if i]
for location in locations:
media_info = list()
if item.media[0].width is not None:
media_info.append(f'{item.media[0].width}x{item.media[0].height}')
media_info.append(f"{item.media[0].width}x{item.media[0].height}")
if item.media[0].videoCodec is not None:
media_info.append(item.media[0].videoCodec)
if item.media[0].audioCodec is not None:
media_info.append(item.media[0].audioCodec)
if item.media[0].bitrate is not None:
media_info.append(f'{item.media[0].bitrate}kbps')
media_info.append(f"{item.media[0].bitrate}kbps")
print(f' {item.title} ({", ".join(media_info)})')
download_url = item._server.url(f'{location.key}?download=1&X-Plex-Token={access_token}')
download_url = item._server.url(f"{location.key}?download=1&X-Plex-Token={access_token}")
print(f' curl -o "{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':
if r.product == "Plex Media Server":
available_resources.append(r)

for this_resource in available_resources:
Expand All @@ -49,13 +45,15 @@ def main(self, username, password, title):
if connection.local:
continue
this_server = PlexServer(connection.uri, this_resource.accessToken)
relay_status = ''
relay_status = ""
if connection.relay:
relay_status = ' (relay)'
print(f'\nServer: "{this_server.friendlyName}"{relay_status}\n'
f'Plex version: {this_server.version}\n"'
f'OS: {this_server.platform} {this_server.platformVersion}')
for item in this_server.search(title, mediatype='movie'):
relay_status = " (relay)"
print(
f'\nServer: "{this_server.friendlyName}"{relay_status}\n'
f'Plex version: {this_server.version}\n"'
f"OS: {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(f'ERROR: connection to "{this_resource.name}" failed.')
Expand Down
16 changes: 7 additions & 9 deletions plexdl/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,11 @@


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', default=os.environ.get('PLEXDL_USER', None),
help='Your plex username (env PLEXDL_USER)')
parser.add_argument('--password', default=os.environ.get('PLEXDL_PASS', None),
help='Your plex password (env PLEXDL_PASS)')
parser.add_argument('title', help='Title to search for')
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", default=os.environ.get("PLEXDL_USER", None), help="Your plex username (env PLEXDL_USER)")
parser.add_argument("--password", default=os.environ.get("PLEXDL_PASS", None), help="Your plex password (env PLEXDL_PASS)")
parser.add_argument("title", help="Title to search for")
arg_parser = parser.parse_args()
arg_parser.print_help = parser.print_help
return arg_parser
Expand All @@ -23,7 +21,7 @@ def main():
"""Searches your plex account for media matching the given string, then prints out download commands."""
args = parse_args()
if args.password is None or args.username is None:
print('Error: must provide username and password\n')
print("Error: must provide username and password\n")
args.print_help()
sys.exit(1)
p = plexdl.Client()
Expand All @@ -33,5 +31,5 @@ def main():
sys.exit(1)


if __name__ == '__main__':
if __name__ == "__main__":
main()
34 changes: 15 additions & 19 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,25 @@
from setuptools import find_packages
from setuptools import setup

dependencies = ['plexapi']
dependencies = ["plexapi"]

setup(
author='Daniel Hoherd',
author_email='[email protected]',
author="Daniel Hoherd",
author_email="[email protected]",
include_package_data=True,
install_requires=dependencies,
long_description=open('README.md').read(),
name='plexdl',
platforms='any',
version='0.1.0',
entry_points={
'console_scripts': [
'plexdl = plexdl.cli:main',
],
},
long_description=open("README.md").read(),
name="plexdl",
platforms="any",
version="0.1.0",
entry_points={"console_scripts": ["plexdl = plexdl.cli:main"]},
classifiers=[
'Development Status :: 3 - Alpha',
'Environment :: Console',
'License :: OSI Approved :: UNLICENSE License',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.6',
'Topic :: Utilities',
"Development Status :: 3 - Alpha",
"Environment :: Console",
"License :: OSI Approved :: UNLICENSE License",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.6",
"Topic :: Utilities",
],
packages=find_packages(exclude=('tests*', 'testing*')),
packages=find_packages(exclude=("tests*", "testing*")),
)
2 changes: 1 addition & 1 deletion tests/example_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@


def test_hello():
assert Client.hello() == 'world'
assert Client.hello() == "world"

0 comments on commit 9a3e4ae

Please sign in to comment.