Merge pull request #23 from trtd/master

Python3 fixes / urllib, printing, dict access.  Sorry for the delay.
This commit is contained in:
Michael Shepanski 2015-10-02 09:09:10 -04:00
commit f4ce527a11
6 changed files with 26 additions and 11 deletions

View file

@ -59,7 +59,7 @@ class Library(object):
args = {}
if title: args['title'] = title
if vtype: args['type'] = video.search_type(vtype)
for tag, obj in tags.iteritems():
for tag, obj in tags.items():
args[tag] = obj.id
query = '/library/%s%s' % (filter, utils.joinArgs(args))
return video.list_items(self.server, query)
@ -99,7 +99,7 @@ class LibrarySection(object):
def _secondary_list(self, key, input=None):
choices = list_choices(self.server, '/library/sections/%s/%s' % (self.key, key))
if not input:
return choices.keys()
return list(choices.keys())
return video.list_items(self.server, '/library/sections/%s/%s/%s' % (self.key, key, choices[input]))
def all(self):
@ -146,7 +146,7 @@ class LibrarySection(object):
args = {}
if title: args['title'] = title
if vtype: args['type'] = video.search_type(vtype)
for tag, obj in tags.iteritems():
for tag, obj in tags.items():
args[tag] = obj.id
query = '/library/sections/%s/%s%s' % (self.key, filter, utils.joinArgs(args))
return video.list_items(self.server, query)

View file

@ -55,7 +55,7 @@ class MediaPart(object):
def selected_stream(self, stream_type):
streams = filter(lambda x: stream_type == x.type, self.streams)
selected = filter(lambda x: x.selected is True, streams)
selected = list(filter(lambda x: x.selected is True, streams))
if len(selected) == 0:
return None

View file

@ -1,7 +1,7 @@
"""
PlexServer
"""
import requests, urllib
import requests
from requests.status_codes import _codes as codes
from plexapi import BASE_HEADERS, TIMEOUT
from plexapi import log, video
@ -12,6 +12,12 @@ from plexapi.myplex import MyPlexAccount
from plexapi.playqueue import PlayQueue
from xml.etree import ElementTree
try:
from urllib import quote # Python2
except ImportError:
from urllib.parse import quote # Python3
TOTAL_QUERIES = 0
DEFAULT_BASEURI = 'http://localhost:32400'
@ -87,7 +93,7 @@ class PlexServer(object):
return ElementTree.fromstring(data) if data else None
def search(self, query, videotype=None):
query = urllib.quote(query)
query = quote(query)
items = video.list_items(self, '/search?query=%s' % query)
if videotype:
return [item for item in items if item.type == videotype]

View file

@ -26,7 +26,7 @@ class SyncItem(object):
return '<{0}:{1}>'.format(self.__class__.__name__, self.id)
def server(self):
server = filter(lambda x: x.machineIdentifier == self.machineIdentifier, self.servers)
server = list(filter(lambda x: x.machineIdentifier == self.machineIdentifier, self.servers))
if 0 == len(server):
raise NotFound('Unable to find server with uuid %s' % self.machineIdentifier)

View file

@ -1,9 +1,13 @@
"""
PlexAPI Utils
"""
import urllib
from datetime import datetime
try:
from urllib import quote # Python2
except ImportError:
from urllib.parse import quote # Python3
NA = '__NA__' # Value not available
@ -56,7 +60,7 @@ def joinArgs(args):
arglist = []
for key in sorted(args, key=lambda x:x.lower()):
value = str(args[key])
arglist.append('%s=%s' % (key, urllib.quote(value)))
arglist.append('%s=%s' % (key, quote(value)))
return '?%s' % '&'.join(arglist)

View file

@ -1,7 +1,7 @@
"""
PlexVideo
"""
import re, urllib
import re
from plexapi.client import Client
from plexapi.media import Media, Country, Director, Genre, Producer, Actor, Writer
from plexapi.myplex import MyPlexUser
@ -9,6 +9,11 @@ from plexapi.exceptions import NotFound, UnknownType, Unsupported
from plexapi.utils import PlexPartialObject, NA
from plexapi.utils import cast, toDatetime
try:
from urllib import urlencode # Python2
except ImportError:
from urllib.parse import urlencode # Python3
class Video(PlexPartialObject):
TYPE = None
@ -88,7 +93,7 @@ class Video(PlexPartialObject):
params['maxVideoBitrate'] = max(maxVideoBitrate, 64)
if videoResolution and re.match('^\d+x\d+$', videoResolution):
params['videoResolution'] = videoResolution
return self.server.url('/video/:/transcode/universal/start?%s' % urllib.urlencode(params))
return self.server.url('/video/:/transcode/universal/start?%s' % urlencode(params))
def markWatched(self):
path = '/:/scrobble?key=%s&identifier=com.plexapp.plugins.library' % self.ratingKey