python Plex随机预卷

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python Plex随机预卷相关的知识,希望对你有一定的参考价值。

#!/usr/bin/env python

import random
import sys
import urllib

import requests
from lxml import etree


PLEX_URL = 'http://...:32400'
PLEX_SERVER_ID = '...'
PLEX_PREROLLS_SECTION_ID = '...'

BASE_URL = 'https://app.plex.tv/web/app#!/server/{server_id}/details?key={key}'

try:
    media_type = sys.argv[1]
except:
    exit("USAGE: random_preroll.py <media_type>")

if media_type != 'movie':
    exit()

prerolls = etree.fromstring(requests.get('{}/library/sections/{}/all'.format(PLEX_URL, PLEX_PREROLLS_SECTION_ID)).content)
preroll_key = random.choice(prerolls.xpath('//Video')).attrib['key']
preroll_url = BASE_URL.format(**dict(server_id=PLEX_SERVER_ID, key=preroll_key))
requests.put('{}/:/prefs?{}'.format(PLEX_URL, urllib.urlencode({'CinemaTrailersPrerollID': preroll_url})))

以上是关于python Plex随机预卷的主要内容,如果未能解决你的问题,请参考以下文章

python 这是我试图让Alexa返回Plex的On Deck和Recent Downloaded列表。它不是最漂亮的,但Plex的API不是最佳选择

如何在Ubuntu 20.04 LTS Focal Fossa上安装Plex Media Server

sh [Plex CLI]一个简单的bash脚本来控制您的Plex客户端#plex #cli #shell

Plex

将 Plex 与 Chromecast 与 RasPlex 结合使用?

sh Patch Plex