2016-03-31 18:13:26 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
#################################################################################################
|
|
|
|
|
2016-07-24 08:59:48 +00:00
|
|
|
import logging
|
2016-09-04 10:18:31 +00:00
|
|
|
import hashlib
|
2016-12-03 09:11:38 +00:00
|
|
|
import threading
|
|
|
|
import Queue
|
2016-07-24 08:59:48 +00:00
|
|
|
|
2016-03-31 18:13:26 +00:00
|
|
|
import xbmc
|
|
|
|
|
|
|
|
import downloadutils
|
2016-11-05 21:15:07 +00:00
|
|
|
import database
|
2016-11-05 03:18:39 +00:00
|
|
|
from utils import window, settings
|
2016-11-04 23:20:09 +00:00
|
|
|
from contextlib import closing
|
2016-07-24 08:59:48 +00:00
|
|
|
|
|
|
|
#################################################################################################
|
|
|
|
|
|
|
|
log = logging.getLogger("EMBY."+__name__)
|
2016-03-31 18:13:26 +00:00
|
|
|
|
|
|
|
#################################################################################################
|
|
|
|
|
|
|
|
|
2016-12-03 09:11:38 +00:00
|
|
|
class DownloadThreader(threading.Thread):
|
|
|
|
|
|
|
|
is_finished = False
|
|
|
|
|
|
|
|
def __init__(self, queue, output):
|
|
|
|
|
|
|
|
self.queue = queue
|
|
|
|
self.output = output
|
|
|
|
threading.Thread.__init__(self)
|
|
|
|
|
|
|
|
def run(self):
|
|
|
|
|
|
|
|
try:
|
|
|
|
query = self.queue.get()
|
|
|
|
except Queue.Empty:
|
|
|
|
self.is_finished = True
|
|
|
|
return
|
2016-03-31 18:13:26 +00:00
|
|
|
|
2016-12-03 09:11:38 +00:00
|
|
|
try:
|
|
|
|
result = downloadutils.DownloadUtils().downloadUrl(query['url'],
|
|
|
|
parameters=query.get('params'))
|
|
|
|
if result:
|
|
|
|
self.output.extend(result['Items'])
|
|
|
|
except Exception as error:
|
|
|
|
log.error(error)
|
|
|
|
|
|
|
|
self.queue.task_done()
|
|
|
|
self.is_finished = True
|
|
|
|
|
|
|
|
|
|
|
|
class Read_EmbyServer():
|
2016-03-31 18:13:26 +00:00
|
|
|
|
2016-12-03 09:11:38 +00:00
|
|
|
limitIndex = min(int(settings('limitIndex')), 50)
|
|
|
|
download_limit = int(settings('downloadThreads'))
|
|
|
|
download_threads = list()
|
2016-03-31 18:13:26 +00:00
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
|
2016-12-03 09:11:38 +00:00
|
|
|
self.doUtils = downloadutils.DownloadUtils()
|
2016-03-31 18:13:26 +00:00
|
|
|
self.userId = window('emby_currUser')
|
|
|
|
self.server = window('emby_server%s' % self.userId)
|
|
|
|
|
2016-11-05 18:36:46 +00:00
|
|
|
def get_emby_url(self, handler):
|
|
|
|
return "{server}/emby/%s" % handler
|
|
|
|
|
2016-12-03 09:11:38 +00:00
|
|
|
def _add_worker_thread(self, queue, output):
|
|
|
|
|
|
|
|
while True:
|
|
|
|
for thread in self.download_threads:
|
|
|
|
if thread.is_finished:
|
|
|
|
self.download_threads.remove(thread)
|
|
|
|
|
|
|
|
if window('emby_online') != "true":
|
|
|
|
# Something happened
|
|
|
|
log.error("Server is not online, don't start new download thread")
|
|
|
|
queue.task_done()
|
|
|
|
return False
|
|
|
|
|
|
|
|
if len(self.download_threads) < self.download_limit:
|
|
|
|
# Start new "daemon thread" - actual daemon thread is not supported in Kodi
|
|
|
|
new_thread = DownloadThreader(queue, output)
|
2017-01-07 08:19:39 +00:00
|
|
|
|
|
|
|
counter = 0
|
|
|
|
worked = False
|
|
|
|
while counter < 10:
|
|
|
|
try:
|
|
|
|
new_thread.start()
|
|
|
|
worked = True
|
|
|
|
break
|
|
|
|
except:
|
|
|
|
counter = counter + 1
|
|
|
|
xbmc.sleep(1000)
|
|
|
|
|
|
|
|
if worked:
|
|
|
|
self.download_threads.append(new_thread)
|
|
|
|
return True
|
|
|
|
else:
|
|
|
|
return False
|
2016-12-03 09:11:38 +00:00
|
|
|
else:
|
|
|
|
log.info("Waiting for empty download spot: %s", len(self.download_threads))
|
|
|
|
xbmc.sleep(100)
|
|
|
|
|
2016-03-31 18:13:26 +00:00
|
|
|
|
|
|
|
def split_list(self, itemlist, size):
|
|
|
|
# Split up list in pieces of size. Will generate a list of lists
|
|
|
|
return [itemlist[i:i+size] for i in range(0, len(itemlist), size)]
|
|
|
|
|
|
|
|
def getItem(self, itemid):
|
|
|
|
# This will return the full item
|
2017-01-24 23:14:48 +00:00
|
|
|
item = self.doUtils.downloadUrl("{server}/emby/Users/{UserId}/Items/%s?format=json" % itemid)
|
2016-03-31 18:13:26 +00:00
|
|
|
return item
|
|
|
|
|
2016-12-03 09:11:38 +00:00
|
|
|
def getItems(self, item_list):
|
2016-03-31 18:13:26 +00:00
|
|
|
|
|
|
|
items = []
|
2016-12-03 09:11:38 +00:00
|
|
|
queue = Queue.Queue()
|
2016-03-31 18:13:26 +00:00
|
|
|
|
2016-12-03 09:11:38 +00:00
|
|
|
url = "{server}/emby/Users/{UserId}/Items?&format=json"
|
|
|
|
for item_ids in self.split_list(item_list, self.limitIndex):
|
2016-03-31 18:13:26 +00:00
|
|
|
# Will return basic information
|
|
|
|
params = {
|
|
|
|
|
2016-12-03 09:11:38 +00:00
|
|
|
'Ids': ",".join(item_ids),
|
2016-03-31 18:13:26 +00:00
|
|
|
'Fields': "Etag"
|
|
|
|
}
|
2016-12-03 09:11:38 +00:00
|
|
|
queue.put({'url': url, 'params': params})
|
|
|
|
if not self._add_worker_thread(queue, items):
|
|
|
|
break
|
2016-11-30 22:21:36 +00:00
|
|
|
|
2016-12-03 09:11:38 +00:00
|
|
|
queue.join()
|
2016-03-31 18:13:26 +00:00
|
|
|
|
|
|
|
return items
|
|
|
|
|
2016-12-03 09:11:38 +00:00
|
|
|
def getFullItems(self, item_list):
|
|
|
|
|
2016-03-31 18:13:26 +00:00
|
|
|
items = []
|
2016-12-03 09:11:38 +00:00
|
|
|
queue = Queue.Queue()
|
2016-03-31 18:13:26 +00:00
|
|
|
|
2016-12-03 09:11:38 +00:00
|
|
|
url = "{server}/emby/Users/{UserId}/Items?format=json"
|
|
|
|
for item_ids in self.split_list(item_list, self.limitIndex):
|
2016-03-31 18:13:26 +00:00
|
|
|
params = {
|
|
|
|
|
2016-12-03 09:11:38 +00:00
|
|
|
"Ids": ",".join(item_ids),
|
2016-03-31 18:13:26 +00:00
|
|
|
"Fields": (
|
|
|
|
|
|
|
|
"Path,Genres,SortName,Studios,Writer,ProductionYear,Taglines,"
|
|
|
|
"CommunityRating,OfficialRating,CumulativeRunTimeTicks,"
|
|
|
|
"Metascore,AirTime,DateCreated,MediaStreams,People,Overview,"
|
|
|
|
"CriticRating,CriticRatingSummary,Etag,ShortOverview,ProductionLocations,"
|
|
|
|
"Tags,ProviderIds,ParentId,RemoteTrailers,SpecialEpisodeNumbers,"
|
2016-04-24 00:14:21 +00:00
|
|
|
"MediaSources,VoteCount"
|
2016-03-31 18:13:26 +00:00
|
|
|
)
|
|
|
|
}
|
2016-12-03 09:11:38 +00:00
|
|
|
queue.put({'url': url, 'params': params})
|
|
|
|
if not self._add_worker_thread(queue, items):
|
|
|
|
break
|
2016-11-30 22:21:36 +00:00
|
|
|
|
2016-12-03 09:11:38 +00:00
|
|
|
queue.join()
|
2016-03-31 18:13:26 +00:00
|
|
|
|
|
|
|
return items
|
|
|
|
|
2016-06-16 05:43:36 +00:00
|
|
|
def getFilteredSection(self, parentid, itemtype=None, sortby="SortName", recursive=True,
|
2016-08-18 06:41:18 +00:00
|
|
|
limit=None, sortorder="Ascending", filter_type=""):
|
2016-03-31 18:13:26 +00:00
|
|
|
params = {
|
|
|
|
|
|
|
|
'ParentId': parentid,
|
|
|
|
'IncludeItemTypes': itemtype,
|
|
|
|
'CollapseBoxSetItems': False,
|
|
|
|
'IsVirtualUnaired': False,
|
|
|
|
'IsMissing': False,
|
|
|
|
'Recursive': recursive,
|
|
|
|
'Limit': limit,
|
|
|
|
'SortBy': sortby,
|
|
|
|
'SortOrder': sortorder,
|
2016-09-05 01:19:51 +00:00
|
|
|
'Filters': filter_type,
|
2016-06-16 05:43:36 +00:00
|
|
|
'Fields': (
|
|
|
|
|
|
|
|
"Path,Genres,SortName,Studios,Writer,ProductionYear,Taglines,"
|
|
|
|
"CommunityRating,OfficialRating,CumulativeRunTimeTicks,"
|
|
|
|
"Metascore,AirTime,DateCreated,MediaStreams,People,Overview,"
|
|
|
|
"CriticRating,CriticRatingSummary,Etag,ShortOverview,ProductionLocations,"
|
|
|
|
"Tags,ProviderIds,ParentId,RemoteTrailers,SpecialEpisodeNumbers"
|
|
|
|
)
|
2016-03-31 18:13:26 +00:00
|
|
|
}
|
2016-12-03 09:11:38 +00:00
|
|
|
return self.doUtils.downloadUrl("{server}/emby/Users/{UserId}/Items?format=json", parameters=params)
|
2016-03-31 18:13:26 +00:00
|
|
|
|
|
|
|
def getTvChannels(self):
|
2016-06-16 05:43:36 +00:00
|
|
|
|
2016-03-31 18:13:26 +00:00
|
|
|
params = {
|
|
|
|
|
|
|
|
'EnableImages': True,
|
2016-06-16 05:43:36 +00:00
|
|
|
'Fields': (
|
|
|
|
|
|
|
|
"Path,Genres,SortName,Studios,Writer,ProductionYear,Taglines,"
|
|
|
|
"CommunityRating,OfficialRating,CumulativeRunTimeTicks,"
|
|
|
|
"Metascore,AirTime,DateCreated,MediaStreams,People,Overview,"
|
|
|
|
"CriticRating,CriticRatingSummary,Etag,ShortOverview,ProductionLocations,"
|
|
|
|
"Tags,ProviderIds,ParentId,RemoteTrailers,SpecialEpisodeNumbers"
|
|
|
|
)
|
2016-03-31 18:13:26 +00:00
|
|
|
}
|
2016-06-16 05:43:36 +00:00
|
|
|
url = "{server}/emby/LiveTv/Channels/?userid={UserId}&format=json"
|
2016-12-03 09:11:38 +00:00
|
|
|
return self.doUtils.downloadUrl(url, parameters=params)
|
2016-03-31 18:13:26 +00:00
|
|
|
|
|
|
|
def getTvRecordings(self, groupid):
|
2016-06-16 05:43:36 +00:00
|
|
|
|
|
|
|
if groupid == "root":
|
|
|
|
groupid = ""
|
|
|
|
|
2016-03-31 18:13:26 +00:00
|
|
|
params = {
|
|
|
|
|
|
|
|
'GroupId': groupid,
|
|
|
|
'EnableImages': True,
|
2016-06-16 05:43:36 +00:00
|
|
|
'Fields': (
|
|
|
|
|
|
|
|
"Path,Genres,SortName,Studios,Writer,ProductionYear,Taglines,"
|
|
|
|
"CommunityRating,OfficialRating,CumulativeRunTimeTicks,"
|
|
|
|
"Metascore,AirTime,DateCreated,MediaStreams,People,Overview,"
|
|
|
|
"CriticRating,CriticRatingSummary,Etag,ShortOverview,ProductionLocations,"
|
|
|
|
"Tags,ProviderIds,ParentId,RemoteTrailers,SpecialEpisodeNumbers"
|
|
|
|
)
|
2016-03-31 18:13:26 +00:00
|
|
|
}
|
2016-06-16 05:43:36 +00:00
|
|
|
url = "{server}/emby/LiveTv/Recordings/?userid={UserId}&format=json"
|
2016-12-03 09:11:38 +00:00
|
|
|
return self.doUtils.downloadUrl(url, parameters=params)
|
2016-03-31 18:13:26 +00:00
|
|
|
|
2016-10-10 08:19:00 +00:00
|
|
|
def getSection(self, parentid, itemtype=None, sortby="SortName", artist_id=None, basic=False, dialog=None):
|
2016-03-31 18:13:26 +00:00
|
|
|
|
|
|
|
items = {
|
|
|
|
|
|
|
|
'Items': [],
|
|
|
|
'TotalRecordCount': 0
|
|
|
|
}
|
|
|
|
# Get total number of items
|
|
|
|
url = "{server}/emby/Users/{UserId}/Items?format=json"
|
|
|
|
params = {
|
|
|
|
|
|
|
|
'ParentId': parentid,
|
2016-10-10 08:19:00 +00:00
|
|
|
'ArtistIds': artist_id,
|
2016-03-31 18:13:26 +00:00
|
|
|
'IncludeItemTypes': itemtype,
|
2016-11-11 02:33:06 +00:00
|
|
|
'LocationTypes': "FileSystem,Remote,Offline",
|
2016-03-31 18:13:26 +00:00
|
|
|
'CollapseBoxSetItems': False,
|
|
|
|
'IsVirtualUnaired': False,
|
2016-11-10 20:36:04 +00:00
|
|
|
'IsMissing': False,
|
2016-03-31 18:13:26 +00:00
|
|
|
'Recursive': True,
|
|
|
|
'Limit': 1
|
|
|
|
}
|
|
|
|
try:
|
2016-12-03 09:11:38 +00:00
|
|
|
result = self.doUtils.downloadUrl(url, parameters=params)
|
2016-03-31 18:13:26 +00:00
|
|
|
total = result['TotalRecordCount']
|
|
|
|
items['TotalRecordCount'] = total
|
2016-11-30 22:21:36 +00:00
|
|
|
except Exception as error: # Failed to retrieve
|
2016-12-03 09:11:38 +00:00
|
|
|
log.debug("%s:%s Failed to retrieve the server response: %s", url, params, error)
|
2016-03-31 18:13:26 +00:00
|
|
|
else:
|
|
|
|
index = 0
|
|
|
|
jump = self.limitIndex
|
2016-12-03 09:11:38 +00:00
|
|
|
queue = Queue.Queue()
|
2016-03-31 18:13:26 +00:00
|
|
|
|
|
|
|
while index < total:
|
|
|
|
# Get items by chunk to increase retrieval speed at scale
|
|
|
|
params = {
|
|
|
|
|
|
|
|
'ParentId': parentid,
|
2016-10-10 08:19:00 +00:00
|
|
|
'ArtistIds': artist_id,
|
2016-03-31 18:13:26 +00:00
|
|
|
'IncludeItemTypes': itemtype,
|
|
|
|
'CollapseBoxSetItems': False,
|
|
|
|
'IsVirtualUnaired': False,
|
2016-12-03 09:11:38 +00:00
|
|
|
'EnableTotalRecordCount': False,
|
2016-11-11 02:33:06 +00:00
|
|
|
'LocationTypes': "FileSystem,Remote,Offline",
|
2016-11-10 20:36:04 +00:00
|
|
|
'IsMissing': False,
|
2016-03-31 18:13:26 +00:00
|
|
|
'Recursive': True,
|
|
|
|
'StartIndex': index,
|
|
|
|
'Limit': jump,
|
|
|
|
'SortBy': sortby,
|
|
|
|
'SortOrder': "Ascending",
|
|
|
|
}
|
|
|
|
if basic:
|
|
|
|
params['Fields'] = "Etag"
|
|
|
|
else:
|
2016-10-04 06:18:32 +00:00
|
|
|
params['Fields'] = (
|
2016-03-31 18:13:26 +00:00
|
|
|
|
|
|
|
"Path,Genres,SortName,Studios,Writer,ProductionYear,Taglines,"
|
|
|
|
"CommunityRating,OfficialRating,CumulativeRunTimeTicks,"
|
|
|
|
"Metascore,AirTime,DateCreated,MediaStreams,People,Overview,"
|
|
|
|
"CriticRating,CriticRatingSummary,Etag,ShortOverview,ProductionLocations,"
|
|
|
|
"Tags,ProviderIds,ParentId,RemoteTrailers,SpecialEpisodeNumbers,"
|
2016-04-24 00:11:29 +00:00
|
|
|
"MediaSources,VoteCount"
|
2016-03-31 18:13:26 +00:00
|
|
|
)
|
2016-12-03 09:11:38 +00:00
|
|
|
queue.put({'url': url, 'params': params})
|
|
|
|
if not self._add_worker_thread(queue, items['Items']):
|
|
|
|
break
|
|
|
|
|
|
|
|
index += jump
|
|
|
|
|
|
|
|
if dialog:
|
|
|
|
percentage = int((float(index) / float(total))*100)
|
|
|
|
dialog.update(percentage)
|
|
|
|
|
|
|
|
queue.join()
|
|
|
|
if dialog:
|
|
|
|
dialog.update(100)
|
|
|
|
|
2016-03-31 18:13:26 +00:00
|
|
|
return items
|
|
|
|
|
2016-11-05 07:16:59 +00:00
|
|
|
def get_views(self, root=False):
|
2016-03-31 18:13:26 +00:00
|
|
|
|
|
|
|
if not root:
|
|
|
|
url = "{server}/emby/Users/{UserId}/Views?format=json"
|
|
|
|
else: # Views ungrouped
|
|
|
|
url = "{server}/emby/Users/{UserId}/Items?Sortby=SortName&format=json"
|
|
|
|
|
2016-12-03 09:11:38 +00:00
|
|
|
return self.doUtils.downloadUrl(url)
|
2016-11-05 07:16:59 +00:00
|
|
|
|
|
|
|
def getViews(self, mediatype="", root=False, sortedlist=False):
|
|
|
|
# Build a list of user views
|
|
|
|
views = []
|
|
|
|
mediatype = mediatype.lower()
|
|
|
|
|
2016-03-31 18:13:26 +00:00
|
|
|
try:
|
2016-11-05 07:16:59 +00:00
|
|
|
items = self.get_views(root)['Items']
|
2016-11-30 22:21:36 +00:00
|
|
|
except Exception as error:
|
|
|
|
log.debug("Error retrieving views for type: %s error:%s" % (mediatype, error))
|
2016-03-31 18:13:26 +00:00
|
|
|
else:
|
|
|
|
for item in items:
|
|
|
|
|
2016-10-07 04:31:41 +00:00
|
|
|
if item['Type'] in ("Channel", "PlaylistsFolder"):
|
2016-03-31 18:13:26 +00:00
|
|
|
# Filter view types
|
|
|
|
continue
|
|
|
|
|
|
|
|
# 3/4/2016 OriginalCollectionType is added
|
|
|
|
itemtype = item.get('OriginalCollectionType', item.get('CollectionType', "mixed"))
|
|
|
|
|
2016-10-07 04:31:41 +00:00
|
|
|
if item['Name'] not in ('Collections', 'Trailers', 'Playlists'):
|
2016-03-31 18:13:26 +00:00
|
|
|
|
|
|
|
if sortedlist:
|
|
|
|
views.append({
|
|
|
|
|
2016-03-31 18:35:23 +00:00
|
|
|
'name': item['Name'],
|
2016-03-31 18:13:26 +00:00
|
|
|
'type': itemtype,
|
2016-03-31 18:35:23 +00:00
|
|
|
'id': item['Id']
|
2016-03-31 18:13:26 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
elif (itemtype == mediatype or
|
|
|
|
(itemtype == "mixed" and mediatype in ("movies", "tvshows"))):
|
|
|
|
|
|
|
|
views.append({
|
|
|
|
|
2016-03-31 18:35:23 +00:00
|
|
|
'name': item['Name'],
|
2016-03-31 18:13:26 +00:00
|
|
|
'type': itemtype,
|
2016-03-31 18:35:23 +00:00
|
|
|
'id': item['Id']
|
2016-03-31 18:13:26 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
return views
|
|
|
|
|
|
|
|
def verifyView(self, parentid, itemid):
|
|
|
|
|
|
|
|
params = {
|
|
|
|
|
|
|
|
'ParentId': parentid,
|
|
|
|
'CollapseBoxSetItems': False,
|
|
|
|
'IsVirtualUnaired': False,
|
2016-11-11 02:33:06 +00:00
|
|
|
'LocationTypes': "FileSystem,Remote,Offline",
|
2016-11-10 20:36:04 +00:00
|
|
|
'IsMissing': False,
|
2016-03-31 18:13:26 +00:00
|
|
|
'Recursive': True,
|
|
|
|
'Ids': itemid
|
|
|
|
}
|
|
|
|
try:
|
2016-12-03 09:11:38 +00:00
|
|
|
result = self.doUtils.downloadUrl("{server}/emby/Users/{UserId}/Items?format=json", parameters=params)
|
2016-03-31 18:13:26 +00:00
|
|
|
total = result['TotalRecordCount']
|
2016-11-30 22:21:36 +00:00
|
|
|
except Exception as error:
|
2016-03-31 18:13:26 +00:00
|
|
|
# Something happened to the connection
|
2016-11-30 22:21:36 +00:00
|
|
|
log.info("Error getting item count: " + str(error))
|
2016-12-03 09:11:38 +00:00
|
|
|
return False
|
2016-03-31 18:13:26 +00:00
|
|
|
|
2016-12-03 09:11:38 +00:00
|
|
|
return True if total else False
|
2016-03-31 18:13:26 +00:00
|
|
|
|
|
|
|
def getMovies(self, parentId, basic=False, dialog=None):
|
2016-03-31 18:35:23 +00:00
|
|
|
return self.getSection(parentId, "Movie", basic=basic, dialog=dialog)
|
2016-03-31 18:13:26 +00:00
|
|
|
|
|
|
|
def getBoxset(self, dialog=None):
|
2016-03-31 18:35:23 +00:00
|
|
|
return self.getSection(None, "BoxSet", dialog=dialog)
|
2016-03-31 18:13:26 +00:00
|
|
|
|
|
|
|
def getMovies_byBoxset(self, boxsetid):
|
2016-03-31 18:35:23 +00:00
|
|
|
return self.getSection(boxsetid, "Movie")
|
2016-03-31 18:13:26 +00:00
|
|
|
|
|
|
|
def getMusicVideos(self, parentId, basic=False, dialog=None):
|
2016-03-31 18:35:23 +00:00
|
|
|
return self.getSection(parentId, "MusicVideo", basic=basic, dialog=dialog)
|
2016-03-31 18:13:26 +00:00
|
|
|
|
|
|
|
def getHomeVideos(self, parentId):
|
2016-03-31 18:35:23 +00:00
|
|
|
return self.getSection(parentId, "Video")
|
2016-03-31 18:13:26 +00:00
|
|
|
|
|
|
|
def getShows(self, parentId, basic=False, dialog=None):
|
2016-03-31 18:35:23 +00:00
|
|
|
return self.getSection(parentId, "Series", basic=basic, dialog=dialog)
|
2016-03-31 18:13:26 +00:00
|
|
|
|
|
|
|
def getSeasons(self, showId):
|
|
|
|
|
|
|
|
items = {
|
|
|
|
|
|
|
|
'Items': [],
|
|
|
|
'TotalRecordCount': 0
|
|
|
|
}
|
|
|
|
|
|
|
|
params = {
|
|
|
|
|
|
|
|
'IsVirtualUnaired': False,
|
|
|
|
'Fields': "Etag"
|
|
|
|
}
|
2016-06-16 05:43:36 +00:00
|
|
|
url = "{server}/emby/Shows/%s/Seasons?UserId={UserId}&format=json" % showId
|
2016-11-30 22:21:36 +00:00
|
|
|
|
|
|
|
try:
|
2016-12-03 09:11:38 +00:00
|
|
|
result = self.doUtils.downloadUrl(url, parameters=params)
|
2016-11-30 22:21:36 +00:00
|
|
|
except Exception as error:
|
|
|
|
log.info("Error getting Seasons form server: " + str(error))
|
|
|
|
result = None
|
|
|
|
|
|
|
|
if result is not None:
|
2016-03-31 18:13:26 +00:00
|
|
|
items = result
|
|
|
|
|
|
|
|
return items
|
|
|
|
|
|
|
|
def getEpisodes(self, parentId, basic=False, dialog=None):
|
2016-03-31 18:35:23 +00:00
|
|
|
return self.getSection(parentId, "Episode", basic=basic, dialog=dialog)
|
2016-03-31 18:13:26 +00:00
|
|
|
|
|
|
|
def getEpisodesbyShow(self, showId):
|
2016-03-31 18:35:23 +00:00
|
|
|
return self.getSection(showId, "Episode")
|
2016-03-31 18:13:26 +00:00
|
|
|
|
|
|
|
def getEpisodesbySeason(self, seasonId):
|
2016-03-31 18:35:23 +00:00
|
|
|
return self.getSection(seasonId, "Episode")
|
2016-03-31 18:13:26 +00:00
|
|
|
|
2016-10-10 08:19:00 +00:00
|
|
|
def getArtists(self, parent_id=None, dialog=None):
|
2016-03-31 18:13:26 +00:00
|
|
|
|
|
|
|
items = {
|
|
|
|
|
|
|
|
'Items': [],
|
|
|
|
'TotalRecordCount': 0
|
|
|
|
}
|
|
|
|
# Get total number of items
|
|
|
|
url = "{server}/emby/Artists?UserId={UserId}&format=json"
|
|
|
|
params = {
|
|
|
|
|
2016-10-18 11:43:40 +00:00
|
|
|
'ParentId': parent_id,
|
2016-03-31 18:13:26 +00:00
|
|
|
'Recursive': True,
|
|
|
|
'Limit': 1
|
|
|
|
}
|
|
|
|
try:
|
2016-12-03 09:11:38 +00:00
|
|
|
result = self.doUtils.downloadUrl(url, parameters=params)
|
2016-03-31 18:13:26 +00:00
|
|
|
total = result['TotalRecordCount']
|
|
|
|
items['TotalRecordCount'] = total
|
2016-11-30 22:21:36 +00:00
|
|
|
except Exception as error: # Failed to retrieve
|
2016-12-03 09:11:38 +00:00
|
|
|
log.debug("%s:%s Failed to retrieve the server response: %s", url, params, error)
|
2016-03-31 18:13:26 +00:00
|
|
|
else:
|
2016-10-10 08:19:00 +00:00
|
|
|
index = 0
|
2016-03-31 18:13:26 +00:00
|
|
|
jump = self.limitIndex
|
2016-12-03 09:11:38 +00:00
|
|
|
queue = Queue.Queue()
|
2016-03-31 18:13:26 +00:00
|
|
|
|
|
|
|
while index < total:
|
|
|
|
# Get items by chunk to increase retrieval speed at scale
|
|
|
|
params = {
|
|
|
|
|
2016-10-10 08:19:00 +00:00
|
|
|
'ParentId': parent_id,
|
2016-03-31 18:13:26 +00:00
|
|
|
'Recursive': True,
|
|
|
|
'IsVirtualUnaired': False,
|
2016-12-03 09:11:38 +00:00
|
|
|
'EnableTotalRecordCount': False,
|
2016-11-11 02:33:06 +00:00
|
|
|
'LocationTypes': "FileSystem,Remote,Offline",
|
|
|
|
'IsMissing': False,
|
2016-03-31 18:13:26 +00:00
|
|
|
'StartIndex': index,
|
|
|
|
'Limit': jump,
|
|
|
|
'SortBy': "SortName",
|
|
|
|
'SortOrder': "Ascending",
|
|
|
|
'Fields': (
|
|
|
|
|
|
|
|
"Etag,Genres,SortName,Studios,Writer,ProductionYear,"
|
|
|
|
"CommunityRating,OfficialRating,CumulativeRunTimeTicks,Metascore,"
|
|
|
|
"AirTime,DateCreated,MediaStreams,People,ProviderIds,Overview"
|
|
|
|
)
|
|
|
|
}
|
2016-12-03 09:11:38 +00:00
|
|
|
queue.put({'url': url, 'params': params})
|
|
|
|
if not self._add_worker_thread(queue, items['Items']):
|
|
|
|
break
|
2016-03-31 18:13:26 +00:00
|
|
|
|
2016-12-03 09:11:38 +00:00
|
|
|
index += jump
|
2016-11-30 22:21:36 +00:00
|
|
|
|
2016-03-31 18:13:26 +00:00
|
|
|
if dialog:
|
|
|
|
percentage = int((float(index) / float(total))*100)
|
|
|
|
dialog.update(percentage)
|
2016-12-03 09:11:38 +00:00
|
|
|
|
|
|
|
queue.join()
|
|
|
|
if dialog:
|
|
|
|
dialog.update(100)
|
|
|
|
|
2016-03-31 18:13:26 +00:00
|
|
|
return items
|
|
|
|
|
|
|
|
def getAlbums(self, basic=False, dialog=None):
|
2016-03-31 18:35:23 +00:00
|
|
|
return self.getSection(None, "MusicAlbum", sortby="DateCreated", basic=basic, dialog=dialog)
|
2016-03-31 18:13:26 +00:00
|
|
|
|
|
|
|
def getAlbumsbyArtist(self, artistId):
|
2016-10-10 08:19:00 +00:00
|
|
|
return self.getSection(None, "MusicAlbum", sortby="DateCreated", artist_id=artistId)
|
2016-03-31 18:13:26 +00:00
|
|
|
|
|
|
|
def getSongs(self, basic=False, dialog=None):
|
2016-03-31 18:35:23 +00:00
|
|
|
return self.getSection(None, "Audio", basic=basic, dialog=dialog)
|
2016-03-31 18:13:26 +00:00
|
|
|
|
|
|
|
def getSongsbyAlbum(self, albumId):
|
2016-06-16 05:43:36 +00:00
|
|
|
return self.getSection(albumId, "Audio")
|
2016-03-31 18:13:26 +00:00
|
|
|
|
|
|
|
def getAdditionalParts(self, itemId):
|
|
|
|
|
|
|
|
items = {
|
|
|
|
|
|
|
|
'Items': [],
|
|
|
|
'TotalRecordCount': 0
|
|
|
|
}
|
2016-06-16 05:43:36 +00:00
|
|
|
url = "{server}/emby/Videos/%s/AdditionalParts?UserId={UserId}&format=json" % itemId
|
2016-11-30 22:21:36 +00:00
|
|
|
|
|
|
|
try:
|
2016-12-03 09:11:38 +00:00
|
|
|
result = self.doUtils.downloadUrl(url)
|
2016-11-30 22:21:36 +00:00
|
|
|
except Exception as error:
|
|
|
|
log.info("Error getting additional parts form server: " + str(error))
|
|
|
|
result = None
|
|
|
|
|
|
|
|
if result is not None:
|
2016-03-31 18:13:26 +00:00
|
|
|
items = result
|
|
|
|
|
|
|
|
return items
|
|
|
|
|
|
|
|
def sortby_mediatype(self, itemids):
|
|
|
|
|
|
|
|
sorted_items = {}
|
|
|
|
|
|
|
|
# Sort items
|
|
|
|
items = self.getFullItems(itemids)
|
|
|
|
for item in items:
|
|
|
|
|
|
|
|
mediatype = item.get('Type')
|
|
|
|
if mediatype:
|
|
|
|
sorted_items.setdefault(mediatype, []).append(item)
|
|
|
|
|
|
|
|
return sorted_items
|
|
|
|
|
2016-06-20 01:32:09 +00:00
|
|
|
def updateUserRating(self, itemid, favourite=None):
|
2016-03-31 18:13:26 +00:00
|
|
|
# Updates the user rating to Emby
|
2016-12-03 09:11:38 +00:00
|
|
|
doUtils = self.doUtils.downloadUrl
|
2016-06-16 05:43:36 +00:00
|
|
|
|
2016-03-31 18:13:26 +00:00
|
|
|
if favourite:
|
2016-06-16 05:43:36 +00:00
|
|
|
url = "{server}/emby/Users/{UserId}/FavoriteItems/%s?format=json" % itemid
|
|
|
|
doUtils(url, action_type="POST")
|
2016-06-20 01:32:09 +00:00
|
|
|
elif not favourite:
|
2016-06-16 05:43:36 +00:00
|
|
|
url = "{server}/emby/Users/{UserId}/FavoriteItems/%s?format=json" % itemid
|
|
|
|
doUtils(url, action_type="DELETE")
|
2016-04-24 00:11:29 +00:00
|
|
|
else:
|
2016-07-24 08:59:48 +00:00
|
|
|
log.info("Error processing user rating.")
|
2016-03-31 18:13:26 +00:00
|
|
|
|
2016-07-24 08:59:48 +00:00
|
|
|
log.info("Update user rating to emby for itemid: %s | favourite: %s" % (itemid, favourite))
|
2016-06-20 00:24:42 +00:00
|
|
|
|
|
|
|
def refreshItem(self, itemid):
|
|
|
|
|
|
|
|
url = "{server}/emby/Items/%s/Refresh?format=json" % itemid
|
|
|
|
params = {
|
|
|
|
|
|
|
|
'Recursive': True,
|
|
|
|
'ImageRefreshMode': "FullRefresh",
|
|
|
|
'MetadataRefreshMode': "FullRefresh",
|
|
|
|
'ReplaceAllImages': False,
|
|
|
|
'ReplaceAllMetadata': True
|
|
|
|
|
|
|
|
}
|
2016-12-03 09:11:38 +00:00
|
|
|
self.doUtils.downloadUrl(url, postBody=params, action_type="POST")
|
2016-06-20 01:32:09 +00:00
|
|
|
|
|
|
|
def deleteItem(self, itemid):
|
|
|
|
|
2016-06-21 20:26:42 +00:00
|
|
|
url = "{server}/emby/Items/%s?format=json" % itemid
|
2016-12-03 09:11:38 +00:00
|
|
|
self.doUtils.downloadUrl(url, action_type="DELETE")
|
2016-09-04 10:18:31 +00:00
|
|
|
|
|
|
|
def getUsers(self, server):
|
|
|
|
|
|
|
|
url = "%s/emby/Users/Public?format=json" % server
|
2016-11-30 22:21:36 +00:00
|
|
|
try:
|
2016-12-03 09:11:38 +00:00
|
|
|
users = self.doUtils.downloadUrl(url, authenticate=False)
|
2016-11-30 22:21:36 +00:00
|
|
|
except Exception as error:
|
|
|
|
log.info("Error getting users from server: " + str(error))
|
|
|
|
users = []
|
2016-09-04 10:18:31 +00:00
|
|
|
|
2016-11-30 22:21:36 +00:00
|
|
|
return users
|
2016-09-04 10:18:31 +00:00
|
|
|
|
|
|
|
def loginUser(self, server, username, password=None):
|
|
|
|
|
|
|
|
password = password or ""
|
|
|
|
url = "%s/emby/Users/AuthenticateByName?format=json" % server
|
|
|
|
data = {'username': username, 'password': hashlib.sha1(password).hexdigest()}
|
2016-12-03 09:11:38 +00:00
|
|
|
user = self.doUtils.downloadUrl(url, postBody=data, action_type="POST", authenticate=False)
|
2016-09-04 10:18:31 +00:00
|
|
|
|
2016-11-05 18:36:46 +00:00
|
|
|
return user
|
|
|
|
|
|
|
|
def get_single_item(self, media_type, parent_id):
|
|
|
|
|
|
|
|
params = {
|
|
|
|
'ParentId': parent_id,
|
|
|
|
'Recursive': True,
|
|
|
|
'Limit': 1,
|
|
|
|
'IncludeItemTypes': media_type
|
|
|
|
}
|
|
|
|
url = self.get_emby_url('Users/{UserId}/Items?format=json')
|
2017-09-03 19:10:04 +00:00
|
|
|
return self.doUtils.downloadUrl(url, parameters=params)
|
|
|
|
|
|
|
|
# NEW CODE ----------------------------------------------------
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def _get_full_details(cls, params):
|
|
|
|
params.update({
|
|
|
|
'Fields': (
|
|
|
|
|
|
|
|
"Path,Genres,SortName,Studios,Writer,ProductionYear,Taglines,"
|
|
|
|
"CommunityRating,OfficialRating,CumulativeRunTimeTicks,"
|
|
|
|
"Metascore,AirTime,DateCreated,MediaStreams,People,Overview,"
|
|
|
|
"CriticRating,CriticRatingSummary,Etag,ShortOverview,ProductionLocations,"
|
|
|
|
"Tags,ProviderIds,ParentId,RemoteTrailers,SpecialEpisodeNumbers,"
|
|
|
|
"MediaSources,VoteCount"
|
|
|
|
)
|
|
|
|
})
|
|
|
|
return params
|
|
|
|
|
|
|
|
def get_parent_child(self, parent_id, media_format=None):
|
|
|
|
|
|
|
|
url = self.get_emby_url('Users/{UserId}/Items')
|
|
|
|
params = {
|
|
|
|
'SortBy': "SortName",
|
|
|
|
'SortOrder': "Ascending",
|
|
|
|
'IncludeItemTypes': media_format,
|
|
|
|
'Recursive': True,
|
|
|
|
'Limit': 1,
|
|
|
|
'ParentId': parent_id
|
|
|
|
}
|
|
|
|
result = self.doUtils.downloadUrl(url, parameters=params)
|
|
|
|
params['Limit'] = self.limitIndex
|
|
|
|
params = self._get_full_details(params)
|
|
|
|
|
|
|
|
index = 0
|
|
|
|
while index < result['TotalRecordCount']:
|
|
|
|
params['StartIndex'] = index
|
|
|
|
yield self.doUtils.downloadUrl(url, parameters=params)
|
|
|
|
|
|
|
|
index += self.limitIndex
|
|
|
|
|
|
|
|
def get_view_options(self, view_id):
|
|
|
|
|
|
|
|
url = self.get_emby_url('Library/VirtualFolders')
|
|
|
|
for library in self.doUtils.downloadUrl(url):
|
|
|
|
if library['ItemId'] == view_id:
|
|
|
|
return library['LibraryOptions']
|
2017-10-04 22:35:40 +00:00
|
|
|
|
|
|
|
def get_server_transcoding_settings(self):
|
|
|
|
|
|
|
|
url = self.get_emby_url('/System/Configuration/encoding')
|
|
|
|
return self.doUtils.downloadUrl(url)
|