2016-03-21 04:26:02 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
2014-12-29 03:21:58 +00:00
|
|
|
import requests
|
2016-03-17 05:14:31 +00:00
|
|
|
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):
|
2017-02-06 04:52:10 +00:00
|
|
|
self._device = device
|
|
|
|
self._servers = servers
|
|
|
|
self._loadData(data)
|
2017-01-02 21:06:40 +00:00
|
|
|
|
2017-02-06 04:52:10 +00:00
|
|
|
def _loadData(self, data):
|
|
|
|
self._data = data
|
2016-03-17 05:14:31 +00:00
|
|
|
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):
|
2017-02-06 04:52:10 +00:00
|
|
|
server = list(filter(lambda x: x.machineIdentifier == self.machineIdentifier, self._servers))
|
2014-12-29 03:21:58 +00:00
|
|
|
if 0 == len(server):
|
2017-02-06 04:52:10 +00:00
|
|
|
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()
|
2017-02-07 06:20:49 +00:00
|
|
|
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' % (
|
2017-02-06 04:52:10 +00:00
|
|
|
self._device.clientIdentifier, server.machineIdentifier, sync_id)
|
2017-02-09 04:29:17 +00:00
|
|
|
server.query(url, method=requests.put)
|