Coder Social home page Coder Social logo

benjaminoddou / alfred-plex Goto Github PK

View Code? Open in Web Editor NEW
23.0 3.0 0.0 7.7 MB

๐Ÿ“บ Browse and perform actions on your plex media servers

Home Page: https://alfred.app/workflows/benjaminoddou/plex/

License: MIT License

Python 99.52% Shell 0.28% JavaScript 0.20%
alfred alfred-workflow plex plex-api plex-media-server python python-plexapi api

alfred-plex's Introduction

logo-dark

logo-light

made with heart by Benjamin Oddou saythanks Python 3.8+

โœจ Welcome to the Alfred Plex repository: An Alfred Workflow โœจ

vlc

โœ… Prerequisites

  • MacOS.
  • Alfred 5. Note that the Alfred Powerpack is required to use workflows.
  • An access to a plex media server.
  • Requires python 3.8 or above.

โฌ‡๏ธ Installation

  1. Download the workflow.
  2. Double click the .alfredworkflow file to install.

๐ŸŽ๏ธ Plex API

This workflow uses the Python-PlexAPI but doesn't cover all capabilities of this tool. If you see a good feature from the Python-PlexAPI that can be incorporated in this workflow, please let me know by opening an issue or sending a pull request.

๐Ÿงฐ Setup the workflow

Install Python 3.8 or above. Check your version with:

python --version

๐Ÿง™โ€โ™‚๏ธ Invoke the workflow

Launch the menu with plex. You can edit this trigger in the Workflow Configuration panel.

The workflow is divided in 6 parts :

  1. Search medias throughout your servers.
  2. Search medias using discover.
  3. Manage your plex accounts.
  4. Manage servers and perform actions.
  5. Manage presets to rapidly search medias.
  6. Workflow configuration + filter & sort options.

menu

To use this workflow, you need to add server(s).In order to do so, you must connect to an account that have access to a plex media server with your credentials. If you're not the owner of the server, you won't have access to the server settings.

Go to the Plex Account section to know more on how to manage your accounts.

๐Ÿค– Usage of the workflow

Plex Search : Search medias throughout your servers

1. Simple search

In this mode, you search medias on your servers directly by typing your request. You can optionally add a / followed by one of the following media types: track, album, artist, collection, actor, director, genre, movie, photo, photoalbum, playlist, show, episode, clip.

Link to the Python-PlexAPI documentation.

simple_search

2. Advance search

In this mode, you search medias on your library sections. To enter this mode, you can use filters and/or advanced filters.

To know how to use them, go to the section : Plex Help.

Link to the Python-PlexAPI documentation.

The following example libtype=movie/decade=1980/country=france returns movies released between 1980 and 1990 in the country France.

filters_full_1

3. Actions on medias

The following actions can be configured in the user configuration panel

  1. Nested search. Press โŽ on one of the following media types: actor, director, collection, artist, album, genre, show, season, to trigger a nested search.
  2. Open the media on the web. Simply press โŒ˜โŽ to open the media on plex. Not available for genre media type.
  3. Stream the media with VLC / IINA. This is only available for the following media types: movie, episode, clip, track, album. Press โŒฅโŽ to open the media in VLC / IINA. It requires VLC 3.0+ or IINA 1.0.0+ and the corresponding cli. See below to know how to install the cli. If you have multiple versions of the same movie, episode, clip, you'll be asked to choose the file you want to play.
  4. Get infos of movies and tv shows using the Movie and TV Show Search Alfred workflow by Tom McKnight. Press โŒƒโŽ to trigger the workflow. It requires Movie and TV Show Search Alfred workflow 2.16.0 or above. Only available for movie, show media types.

4. VLC and IINA integration

If you don't have VLC / IINA on your mac, run the following command to install it via homebrew:

brew install --cask vlc
brew install --cask iina

If you already have VLC / IINA installed check the presence of the cli with:

which vlc
which iina

If it is not found, uninstall VLC / IINA and reinstall it using homebrew.

Link to the VLC homebrew formulae. Link to the IINA homebrew formulae.

Plex Discover : Search medias using discover

Search medias and people on Plex Discover. You can perform the same actions ** listed above.

** Except streaming with VLC / IINA. Note that nested search allows you to search media title within your servers.

discover

Plex Accounts : Manage your plex accounts

Connect one or more accounts to add plex media servers. Use one of the following methods to connect to your plex account :

auth

In this section you can :

  • See the list of your servers. Servers that aren't added to the workflow are greyed out.
  • Manage connected users.
  • Manage connected devices.
  • Manage your watchlist.

plex_account

Removing a plex account will remove all the servers connected. You can also remove a server directly in the Plex Media Servers section.

When connected to the workflow, you'll be able to see the device under the Authorized Devices section. Follow this documentation to know more. Note that when using an authentication token, you'll use the web session from which you obtained the token.

device

Plex Media Servers : Manage servers and perform actions

Select the server to view its informations and perform actions.

  • Download last version of plex media server from the web.
  • Backup logs and databases.
  • Display connected account.
  • Manage running sessions.
  • Perform actions on library sections:
    • Scan library sections (search for new medias).
    • Refresh library sections (download fresh media info from the internet).
    • Display history.
    • Display library sections sizes.
  • Display and modify settings of the server.
  • Display real time server statistics.

New values for settings must match the setting type and must be valid python. For example, boolean must be True or False with capital letter and string must be quoted.

server_actions

Plex Presets : Manage presets to rapidly search medias

1. Create a preset

Create easily preset by pressing โŽ on Add a new Preset. Input a value for the preset WITH FULL FILTERS NAMES. Then input a title and a subtitle separated by a /.

2. Modify a preset

Simply press โŒ˜โŽ to enter in the modified mode. Press โŽ to edit the title/subtitle or the value.

preset_modify

3. Apply a preset

Simply press โŽ on a preset to apply its value to the search workflow.

preset_entry

Plex Help : Workflow configuration + filter & sort options

You can manage workflow cache, data and edit filter alias.

plex_help

Filters, fields and sorts options are generated based on your libraries metadata. This will vary regarding your medias and agents used to gather information.

1. Filters

Filters can be aliased, see section 4. Alias below

Plex filters can be applied by typing filterName=value. Use / to separate them. Find the list of filters under each library sections of your servers.

Example: libtype=movie/actor=adam driver. It returns movies with Adam Driver.

filters_full_2

2. Fields (advanced filters)

Plex fields (or advanced filters) can be applied by typing advancedFilters={<FILTER>} (or af={<FILTER>} in alias mode). There is certain conditions you have to respect to make advance filters working:

  • Use / to separate advanced filter from other filters.
  • You must use them along with a libtype.
  • You must provide a valid Python dict or valid JSON syntax. Double quotes " and single quotes ' are valid.

To know more on how to use these filters, check the Python-PlexAPI documentation.

Find the list of fields under each library sections of your servers.

Example: libtype=episode/advancedFilters={'show.title': 'one piece', 'episode.index': '1074'}. It returns episodes where episode number is 1074 and the title of the show contains one piece.

advanced_filters

3. Sorts

You can sort results by typing sort=sortName:dir (or so=sortName:dir in alias mode). Direction can be :asc for ascending or :desc for descending.

Example: libtype=movie/sort=originallyAvailableAt:desc. This will display movies from the most recent to the older one.

sorts

4. Alias

Alias are enabled by default, and allows you, when activated, to write filters more easily. libtype becomes lt, studio becomes st...

You can disable this behavior in the user control panel by unticking the ๐Ÿ“œ Use alias parameter.

Alias file can be edited, but be careful about double values. It is the alias.json file located under the ๐Ÿ“ Data folder (~/Library/Application Support/Alfred/Workflow Data/com.benjamino.plex by default).

Example: af={'addedAt>>': '30d'}/lt=show. It returns shows added or shows containing new elements (seasons, epidodes) in plex during the last 30 days.

alias

โš–๏ธ License

MIT License ยฉ Benjamin Oddou

alfred-plex's People

Contributors

benjaminoddou avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

alfred-plex's Issues

Plex Discover search not working

Hi,
I get the following notification when performing a search in Discover - "Failed to connect to Plex Discover. Check the token".

When I first installed the workflow, Discover was disabled in my Plex account. Later I enabled it but still won't work in the workflow.

I've tried reinstalling the workflow (also deleted the database folder for the workflow). I tried restarting Plex and getting the XML link again. Still won't work.

Running v1.5 of the workflow with PMS v4.108.

charset_normaliser module contains Intel Mach O shared libraries

This workflow wouldn't run on my M2 Mini. Debugging showed that the problem appears to be that the included charset_normaliser package includes Intel versions of the md.cpython-311-darwin.so and md__mypyc.cpython-311-darwin.so Mach-O bundles.

Error message:

Traceback (most recent call last):
  File "<Alfred folder>/Alfred.alfredpreferences/workflows/user.workflow.<UUID>/search_entry.py", line 4, in <module>
    from lib.plexapi.server import PlexServer
  File "<Alfred folder>/Alfred.alfredpreferences/workflows/user.workflow.<UUID>/lib/plexapi/__init__.py", line 8, in <module>
    from plexapi.config import PlexConfig, reset_base_headers
  File "<Alfred folder>/Alfred.alfredpreferences/workflows/user.workflow.<UUID>/./lib/plexapi/__init__.py", line 10, in <module>
    from plexapi.utils import SecretsFilter
  File "<Alfred folder>/Alfred.alfredpreferences/workflows/user.workflow.<UUID>/./lib/plexapi/utils.py", line 19, in <module>
    import requests
  File "<Alfred folder>/Alfred.alfredpreferences/workflows/user.workflow.<UUID>/./lib/requests/__init__.py", line 45, in <module>
    from .exceptions import RequestsDependencyWarning
  File "<Alfred folder>/Alfred.alfredpreferences/workflows/user.workflow.<UUID>/./lib/requests/exceptions.py", line 9, in <module>
    from .compat import JSONDecodeError as CompatJSONDecodeError
  File "<Alfred folder>/Alfred.alfredpreferences/workflows/user.workflow.<UUID>/./lib/requests/compat.py", line 13, in <module>
    import charset_normalizer as chardet
  File "<Alfred folder>/Alfred.alfredpreferences/workflows/user.workflow.<UUID>/./lib/charset_normalizer/__init__.py", line 24, in <module>
    from .api import from_bytes, from_fp, from_path
  File "<Alfred folder>/Alfred.alfredpreferences/workflows/user.workflow.<UUID>/./lib/charset_normalizer/api.py", line 5, in <module>
    from .cd import (
  File "<Alfred folder>/Alfred.alfredpreferences/workflows/user.workflow.<UUID>/./lib/charset_normalizer/cd.py", line 9, in <module>
    from .md import is_suspiciously_successive_range
ImportError: dlopen(<Alfred folder>/Alfred.alfredpreferences/workflows/user.workflow.<UUID>/./lib/charset_normalizer/md.cpython-311-darwin.so, 0x0002): tried: '<Alfred folder>/Alfred.alfredpreferences/workflows/user.workflow.<UUID>/./lib/charset_normalizer/md.cpython-311-darwin.so' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64')), '/System/Volumes/Preboot/Cryptexes/OS<Alfred folder>/Alfred.alfredpreferences/workflows/user.workflow.<UUID>/./lib/charset_normalizer/md.cpython-311-darwin.so' (no such file), '<Alfred folder>/Alfred.alfredpreferences/workflows/user.workflow.<UUID>/./lib/charset_normalizer/md.cpython-311-darwin.so' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64')), '<Alfred folder>/Alfred.alfredpreferences/workflows/user.workflow.<UUID>/lib/charset_normalizer/md.cpython-311-darwin.so' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64')), '/System/Volumes/Preboot/Cryptexes/OS<Alfred folder>/Alfred.alfredpreferences/workflows/user.workflow.<UUID>/lib/charset_normalizer/md.cpython-311-darwin.so' (no such file), '<Alfred folder>/Alfred.alfredpreferences/workflows/user.workflow.<UUID>/lib/charset_normalizer/md.cpython-311-darwin.so' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64'))

My workaround was to manually install charset_normaliser over the existing one by executing:

 pip install charset-normalizer -t ./lib --upgrade

from the folder where the Alfred Plex workflow is installed.

I don't know enough about Python packaging to propose a proper fix.

KeyError: 'friendlyName'

I unable to search for anything on v2.2.1

[19:05:03.870] ERROR: Plex[Script Filter] Code 1: Traceback (most recent call last):
  File "~/Alfred/Alfred.alfredpreferences/workflows/user.workflow.EEDAF0E3-34B2-416E-B0E6-CC10ABF3F241/search_entry.py", line 221, in <module>
    friendlyName = obj['friendlyName']
                   ~~~^^^^^^^^^^^^^^^^
KeyError: 'friendlyName'

Unable to add Plex Account

I receive the following error message when trying to add my Plex account.

[08:09:16.154] ERROR: Plex[Run Script] Traceback (most recent call last):
  File "$PATH/Alfred/Alfred.alfredpreferences/workflows/user.workflow.C65CE066-1457-41AF-8621-2EE9ED12669A/servers_add_delete.py", line 8, in <module>
    _type, _origin, _input = sys.argv[1].split(';')
    ^^^^^^^^^^^^^^^^^^^^^^
ValueError: not enough values to unpack (expected 3, got 1)

Can't add server

First of all I'd like to thank you for sharing this workflow - it looks really promising!

I tried it out just now and was able to get it running after first manually running pip3 install chardet (it was missing from my mac environment).

I tried adding my plex server by pasting the following XML URL:

https://10-1-1-2.{REDACTED}.plex.direct:32400/library/metadata/16348?checkFiles=1&includeAllConcerts=1&includeBandwidths=1&includeChapters=1&includeChildren=1&includeConcerts=1&includeExtras=1&includeFields=1&includeGeolocation=1&includeLoudnessRamps=1&includeMarkers=1&includeOnDeck=1&includePopularLeaves=1&includePreferences=1&includeRelated=1&includeRelatedCount=1&includeReviews=1&includeStations=1&X-Plex-Token={REDACTED}

Which resulted in a native notification popping up confirming that the server had been added (including the correct server name).

Unfortunately subsequent usage doesn't seem to pick up on the newly added server, instead claiming that

No plex media server detected

If I try to add the server again I get the same confirmation notification, but with no apparent changes.

The alfred debugger logs the following:

[10:37:31.700] ERROR: Plex[Run Script] Traceback (most recent call last):
  File "{REDACTED}/Alfred.alfredpreferences/workflows/user.workflow.25E2B625-8870-4DF2-A76A-38DC604CD9AD/config_add_delete.py", line 46, in <module>
    with open(servers_file_path, 'w') as file:
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
FileNotFoundError: [Errno 2] No such file or directory: '{REDACTED}/Library/Application Support/Alfred/Workflow Data/com.benjamino.plex/servers.json'

~/Library/Application Support/Alfred/Workflow Data/com.benjamino.plex/ doesn't exist on my machine, so I'm guessing the script needs to create the directory first.

Constantly getting new device notification from Plex

Hey,

since I installed the workflow I've been getting "New device accessed your server from Chrome (Chrome)" on my iPhone (through the Plex app) almost everyday at random times.

I tried deleting the workflow but the notifications still continue. Any idea why this is happening?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.