agentleFS
eddmanneddmann/jeeves/skills/plex/SKILL.md

plex

Skill2 starsChanged 9 months agoMITView on GitHub

Query Plex Media Server for movies, TV shows, music, and playback history. Use when the user asks about their Plex library, "what movies do I have", "recently added", "continue watching", "watch history", "search my Plex", or wants to explore media in their Plex server.

  • Reads credentials

1 other project uses a version of this.

Adopted by

Most recently taken up by

  • Other versions1 project uses a version of this.

    Word for word · 0

    None found.

    Edited · 0

    None found.

    Wrote their own version · 1

    1. hevangel/media-agent-skills★ 4same name

    How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.

  • In this repository13 other files it gives its agents.

The file

We split this skill into the rules it gives an agent

8 rules. About 0 are common, 3 are distinctive, and 5 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈3

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 5

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    If not set, ask the user for their Plex server URL (e.g.

    line 16
  2. Very specific:

    IMPORTANT: Do NOT call pinlogin.run() or pinlogin.waitForLogin() — these start a blocking polling thread that will timeout before the user …

    line 57
  3. Very specific:

    Use _getCode() to generate the PIN without starting the polling thread

    line 117
  4. Distinctive:

    Alternative: direct token auth: If the user already has a Plex token, skip OAuth and store it directly:

    line 122
  5. Distinctive:

    If a method call fails or you're unsure what's available, introspect:

    line 310
  6. Distinctive:

    "Not authenticated": Run the OAuth flow from the Setup section

    line 320
  7. Very specific:

    "Connection refused": Check PLEX_SERVER_URL, ensure server is running

    line 321
  8. Very specific:

    Section not found: Use exact section title (case-sensitive), check plex.library.sections()

    line 323

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Plex Skill

Query Plex Media Server by writing UV inline Python scripts using plexapi.

Setup

Credentials

Requires PLEX_SERVER_URL in workspace/.env.

If not set, ask the user for their Plex server URL (e.g. http://192.168.1.100:32400), then append to .env:

echo 'PLEX_SERVER_URL=http://their-server:32400' >> .env

Authentication

Plex uses OAuth with a PIN-based flow. This MUST be done in two separate steps because you need to show the user the link and wait for them to click it before polling.

Step 1: Generate auth URL and save state

set -a; source .env 2>/dev/null; set +a; uv run - <<'EOF'
# /// script
# requires-python = ">=3.11"
# dependencies = ["plexapi>=4.18"]
# ///
import json
from pathlib import Path
from plexapi.myplex import MyPlexPinLogin

pinlogin = MyPlexPinLogin(oauth=True)
code = pinlogin._getCode()
pin_id = pinlogin._id
client_id = pinlogin._headers()['X-Plex-Client-Identifier']

# Save state for step 2
Path("plex-oauth-state.json").write_text(json.dumps({
    "pin_id": pin_id,
    "code": code,
    "client_id": client_id,
}))

print(f"URL: {pinlogin.oauthUrl()}")
EOF

Send the URL to the user as a clickable markdown link. Tell them to sign in and let you know when done. The PIN is valid for ~15 minutes so there's no rush.

IMPORTANT: Do NOT call pinlogin.run() or pinlogin.waitForLogin() — these start a blocking polling thread that will timeout before the user can click the link. Instead, manually call _getCode() and save the state.

Step 2: Poll for token (run ONLY after user confirms they've signed in)

export PLEX_SERVER_URL=$(grep PLEX_SERVER_URL .env | cut -d= -f2); uv run - <<'EOF'
# /// script
# requires-python = ">=3.11"
# dependencies = ["plexapi>=4.18", "requests"]
# ///
import json, os, requests, time, xml.etree.ElementTree as ET
from pathlib import Path
from plexapi.server import PlexServer
from plexapi.myplex import MyPlexAccount

state = json.loads(Path("plex-oauth-state.json").read_text())

headers = {
    "Accept": "application/xml",
    "X-Plex-Client-Identifier": state["client_id"],
    "X-Plex-Product": "PlexAPI",
}

# Poll with backoff to avoid rate limiting (429)
for i in range(15):
    resp = requests.get(
        f"https://plex.tv/api/v2/pins/{state['pin_id']}",
        headers=headers, timeout=10
    )
    if resp.status_code == 429:
        time.sleep(5)
        continue
    if resp.status_code == 200:
        root = ET.fromstring(resp.text)
        token = root.attrib.get('authToken', '')
        if token:
            server_url = os.environ["PLEX_SERVER_URL"]
            plex = PlexServer(server_url, token)
            Path("plex-token.json").write_text(json.dumps({
                "token": token,
                "server_url": server_url
            }, indent=2))
            Path("plex-token.json").chmod(0o600)
            account = MyPlexAccount(token=token)
            print(f"SUCCESS: Connected as {account.username}")
            print(f"Server: {plex.friendlyName}")
            for section in plex.library.sections():
                print(f"  - {section.title} ({section.type})")
            exit(0)
    time.sleep(3)

print("ERROR: No token received. Ask user to try signing in again.")
exit(1)
EOF

Key details about the OAuth flow:

  • MyPlexPinLogin.run() generates a NEW pin and starts a blocking thread — don't use it for two-step auth
  • MyPlexPinLogin.pin raises BadRequest when oauth=True — don't access it
  • Use _getCode() to generate the PIN without starting the polling thread
  • Save _id (pin ID), _code, and the client identifier to a file between steps
  • In step 2, poll the Plex API directly with requests using the saved pin ID
  • Plex rate limits aggressively — poll every 3s, back off on 429s

Alternative: direct token auth. If the user already has a Plex token, skip OAuth and store it directly:

export PLEX_SERVER_URL=$(grep PLEX_SERVER_URL .env | cut -d= -f2); uv run - <<'EOF'
# /// script
# requires-python = ">=3.11"
# dependencies = ["plexapi>=4.18"]
# ///
import json, os
from pathlib import Path
from plexapi.server import PlexServer

server_url = os.environ["PLEX_SERVER_URL"]
token = os.environ["PLEX_TOKEN"]

plex = PlexServer(server_url, token)

Path("plex-token.json").write_text(json.dumps({
    "token": token,
    "server_url": server_url
}, indent=2))
Path("plex-token.json").chmod(0o600)

print(f"SUCCESS: Connected to {plex.friendlyName}")
for section in plex.library.sections():
    print(f"  - {section.title} ({section.type})")
EOF

For the direct token approach, the user can find their token by opening any media item in the Plex web UI → Get Info → View XML → copy X-Plex-Token from the URL.

Query Template

export PLEX_SERVER_URL=$(grep PLEX_SERVER_URL .env | cut -d= -f2); uv run - <<'EOF'
# /// script
# requires-python = ">=3.11"
# dependencies = ["plexapi>=4.18"]
# ///
import json
from pathlib import Path
from plexapi.server import PlexServer

TOKEN_FILE = Path("plex-token.json")
if not TOKEN_FILE.exists():
    print("ERROR: Not authenticated — run Plex setup first")
    exit(1)

config = json.loads(TOKEN_FILE.read_text())
plex = PlexServer(config["server_url"], config["token"])

# === YOUR QUERY CODE HERE ===
for section in plex.library.sections():
    print(f"{section.title} ({section.type}): {section.totalSize} items")
EOF

API Reference

Server Methods

MethodReturnsDescription
plex.library.sections()list[LibrarySection]All library sections
plex.library.section(name)LibrarySectionGet section by title
plex.library.sectionByID(id)LibrarySectionGet section by ID
plex.library.onDeck()list[Media]On deck items
plex.library.recentlyAdded()list[Media]Recently added across all sections
plex.continueWatching()list[Media]Continue watching hub
plex.history(maxresults=N)list[Media]Watch history

Section Methods

MethodReturnsDescription
section.all()list[Media]All items in section
section.search(title, **filters)list[Media]Search with filters
section.recentlyAdded()list[Media]Recently added to section
section.onDeck()list[Media]On deck for section

Media Fields (Movie)

FieldTypeDescription
titlestrMovie title
yearintRelease year
durationintDuration in milliseconds
ratingfloatCritic rating
audienceRatingfloatAudience rating (Rotten Tomatoes)
contentRatingstrContent rating (PG-13, R, etc.)
summarystrPlot summary
genreslist[Genre]Genre tags (access .tag)
directorslist[Director]Directors (access .tag)
roleslist[Role]Cast members (access .tag)
studiostrProduction studio
addedAtdatetimeWhen added to library
lastViewedAtdatetimeLast watched (None if unwatched)
viewCountintTimes watched

Media Fields (Show)

FieldTypeDescription
titlestrShow title
yearintFirst aired year
childCountintNumber of seasons
leafCountintTotal episodes
viewedLeafCountintWatched episodes
durationintTypical episode duration (ms)

Media Fields (Episode)

FieldTypeDescription
titlestrEpisode title
grandparentTitlestrShow name
parentTitlestrSeason name
parentIndexintSeason number
indexintEpisode number
durationintDuration in milliseconds

Navigation (Shows)

MethodReturnsDescription
show.seasons()list[Season]All seasons
show.episodes()list[Episode]All episodes
show.episode(season=N, episode=M)EpisodeSpecific episode
season.episodes()list[Episode]Episodes in season

Examples

These show non-obvious patterns. For straightforward methods, use the API reference above.

TV Show Navigation (unintuitive field names)

shows = plex.library.section("TV Shows")
show = shows.get("Breaking Bad")
print(f"{show.title}: {show.leafCount} episodes")

for season in show.seasons():
    print(f"  {season.title}: {len(season.episodes())} episodes")

# Episode fields use grandparent/parent for show/season
ep = show.episode(season=1, episode=1)
print(f"{ep.grandparentTitle} S{ep.parentIndex}E{ep.index}: {ep.title}")

Search with Filters

movies = plex.library.section("Movies")

# Filter by genre + year
action = movies.search(genre="Action", year=2023)
for m in action:
    # Tags are objects — access .tag for the string
    genres = [g.tag for g in m.genres]
    print(f"{m.title} ({m.year}) - {', '.join(genres)}")

Quick Reference

# Unit conversions
duration_min = media.duration / 60000
duration_hrs = media.duration / 3600000

# Library section types
# "movie", "show", "artist" (music), "photo"

# Access tag names from lists
genres = [g.tag for g in movie.genres]
actors = [r.tag for r in movie.roles]
directors = [d.tag for d in movie.directors]

# Check if watched
is_watched = media.viewCount > 0
is_unwatched = media.lastViewedAt is None

Re-authentication

Plex tokens are long-lived but can be revoked. If queries fail with "Unauthorized", re-run the OAuth flow from the Setup section.

Debugging

If a method call fails or you're unsure what's available, introspect:

uv run -c "from plexapi.server import PlexServer; print([m for m in dir(PlexServer) if not m.startswith('_')])"

For full library docs: webfetch https://github.com/pkkid/python-plexapi

Troubleshooting

  • "Not authenticated": Run the OAuth flow from the Setup section
  • "Connection refused": Check PLEX_SERVER_URL, ensure server is running
  • "Unauthorized": Token revoked, re-run OAuth
  • Section not found: Use exact section title (case-sensitive), check plex.library.sections()
  • Empty results: Some methods return generators; convert with list() if needed
  • Rate limited (429): Plex API rate limits aggressively. Back off and retry. Avoid rapid repeated OAuth attempts.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.