python-plexapi/plexapi/sync.py

43 lines
1.6 KiB
Python
Raw Normal View History

# -*- coding: utf-8 -*-
2014-12-29 03:21:58 +00:00
import requests
from plexapi import utils
2014-12-29 03:21:58 +00:00
from plexapi.exceptions import NotFound
class SyncItem(object):
2017-02-13 22:44:28 +00:00
""" Sync Item. This doesn't current work. """
2014-12-29 03:21:58 +00:00
def __init__(self, device, data, servers=None):
self._device = device
self._servers = servers
self._loadData(data)
2017-01-02 21:06:40 +00:00
def _loadData(self, data):
self._data = data
self.id = utils.cast(int, data.attrib.get('id'))
self.version = utils.cast(int, data.attrib.get('version'))
2014-12-29 03:21:58 +00:00
self.rootTitle = data.attrib.get('rootTitle')
self.title = data.attrib.get('title')
self.metadataType = data.attrib.get('metadataType')
self.machineIdentifier = data.find('Server').get('machineIdentifier')
self.status = data.find('Status').attrib.copy()
self.MediaSettings = data.find('MediaSettings').attrib.copy()
self.policy = data.find('Policy').attrib.copy()
self.location = data.find('Location').attrib.copy()
def server(self):
server = list(filter(lambda x: x.machineIdentifier == self.machineIdentifier, self._servers))
2014-12-29 03:21:58 +00:00
if 0 == len(server):
raise NotFound('Unable to find server with uuid %s' % self.machineIdentifier)
2014-12-29 03:21:58 +00:00
return server[0]
def getMedia(self):
server = self.server().connect()
key = '/sync/items/%s' % self.id
return server.fetchItems(key)
2014-12-29 03:21:58 +00:00
def markAsDone(self, sync_id):
server = self.server().connect()
2017-01-02 21:06:40 +00:00
url = '/sync/%s/%s/files/%s/downloaded' % (
self._device.clientIdentifier, server.machineIdentifier, sync_id)
server.query(url, method=requests.put)