Skip to content

Commit

Permalink
gracefully handle clipboard issue
Browse files Browse the repository at this point in the history
  • Loading branch information
BalliAsghar committed Sep 24, 2023
1 parent cc033f9 commit 49f4b9d
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions plex
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,12 @@ def ask_for_credentials():
def copy_to_clipboard(url):
try:
pyperclip.copy(url)
except ImportError:
click.echo('pyperclip not installed, link not copied to clipboard')
except AttributeError:
raise click.ClickException(
'Clipboard not available, please copy the link manually')
except Exception:
raise click.ClickException(
'Could not copy link to clipboard, please copy the link manually')


# Save User Credentials
Expand Down Expand Up @@ -195,9 +199,12 @@ def authenticate_cli(username, password, pin):
@click.command(name='download')
@click.argument('query')
def download_media_cli(query):
url = get_download_url(query)
copy_to_clipboard(url)
click.echo(url)
try:
url = get_download_url(query)
click.echo(url)
copy_to_clipboard(url)
except Exception as e:
click.echo('Error: {}'.format(e))


@click.command(name='signout')
Expand Down

0 comments on commit 49f4b9d

Please sign in to comment.