Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Collection and folder #275

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions lib/_included_packages/plexnet/plexlibrary.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,21 @@ def all(self, start=None, size=None, filter_=None, sort=None, unwatched=False, t
path = '{0}/all'.format(self.key)
else:
path = '/library/sections/{0}/all'.format(self.key)

return self.items(path, start, size, filter_, sort, unwatched, type_, False)

def folder(self, start=None, size=None, subDir=False):
if self.key.startswith('/'):
path = self.key
else:
path = '/library/sections/{0}'.format(self.key)

if not subDir:
path = '{0}/folder'.format(path)

return self.items(path, start, size, None, None, False, None, True)

def items(self, path, start, size, filter_, sort, unwatched, type_, tag_fallback):

args = {}

Expand All @@ -152,9 +167,9 @@ def all(self, start=None, size=None, filter_=None, sort=None, unwatched=False, t
args[self.TYPE == 'movie' and 'unwatched' or 'unwatchedLeaves'] = 1

if args:
path += util.joinArgs(args)
path += util.joinArgs(args, '?' not in path)

return plexobjects.listItems(self.server, path)
return plexobjects.listItems(self.server, path, tag_fallback=tag_fallback)

def jumpList(self, filter_=None, sort=None, unwatched=False, type_=None):
if self.key.startswith('/'):
Expand Down Expand Up @@ -369,6 +384,9 @@ def __repr__(self):
title = self.title.replace(' ', '.')[0:20]
return '<{0}:{1}:{2}>'.format(self.__class__.__name__, self.key, title)

@plexobjects.registerLibType
class Collection(Generic):
TYPE = 'collection'

@plexobjects.registerLibType
class Playlist(playlist.BasePlaylist, signalsmixin.SignalsMixin):
Expand Down
5 changes: 3 additions & 2 deletions lib/_included_packages/plexnet/plexobjects.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ def __init__(self, data, initpath=None, server=None, container=None):
self.titleSort = PlexValue('')
self.deleted = False
self._reloaded = False
self.data = data

if data is None:
return
Expand Down Expand Up @@ -512,7 +513,7 @@ def init(self, container):
return self


def listItems(server, path, libtype=None, watched=None, bytag=False, data=None, container=None):
def listItems(server, path, libtype=None, watched=None, bytag=False, data=None, container=None, tag_fallback=False):
data = data if data is not None else server.query(path)
container = container or PlexContainer(data, path, server, path)
items = ItemContainer().init(container)
Expand All @@ -525,7 +526,7 @@ def listItems(server, path, libtype=None, watched=None, bytag=False, data=None,
if watched is False and elem.attrib.get('viewCount', 0) >= 1:
continue
try:
items.append(buildItem(server, elem, path, bytag, container))
items.append(buildItem(server, elem, path, bytag, container, tag_fallback))
except exceptions.UnknownType:
pass

Expand Down
4 changes: 2 additions & 2 deletions lib/_included_packages/plexnet/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def now(local=False):
return time.mktime(time.gmtime())


def joinArgs(args):
def joinArgs(args, includeQuestion=True):
if not args:
return ''

Expand All @@ -124,7 +124,7 @@ def joinArgs(args):
value = str(args[key])
arglist.append('{0}={1}'.format(key, compat.quote(value)))

return '?{0}'.format('&'.join(arglist))
return '{0}{1}'.format(includeQuestion and '?' or '&', '&'.join(arglist))


def addPlexHeaders(transferObj, token=None):
Expand Down
60 changes: 49 additions & 11 deletions lib/windows/library.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,12 @@
TYPE_PLURAL = {
'artist': T(32347, 'artists'),
'album': T(32461, 'albums'),
'movie': T(32348, 'movies'),
'movie': T(32348, 'Movies'),
'photo': T(32349, 'photos'),
'show': T(32350, 'Shows'),
'episode': T(32458, 'Episodes')
'episode': T(32458, 'Episodes'),
'collection': T(32490, 'Collections'),
'folder': T(32491, 'Folders'),
}

SORT_KEYS = {
Expand Down Expand Up @@ -140,14 +142,15 @@ def setItemType(type_=None):


class ChunkRequestTask(backgroundthread.Task):
def setup(self, section, start, size, callback, filter_=None, sort=None, unwatched=False):
def setup(self, section, start, size, callback, filter_=None, sort=None, unwatched=False, subDir=False):
self.section = section
self.start = start
self.size = size
self.callback = callback
self.filter = filter_
self.sort = sort
self.unwatched = unwatched
self.subDir = subDir
return self

def contains(self, pos):
Expand All @@ -163,7 +166,14 @@ def run(self):
type_ = 4
elif ITEM_TYPE == 'album':
type_ = 9
items = self.section.all(self.start, self.size, self.filter, self.sort, self.unwatched, type_=type_)
elif ITEM_TYPE == 'collection':
type_ = 18

if ITEM_TYPE == 'folder':
items = self.section.folder(self.start, self.size, self.subDir)
else:
items = self.section.all(self.start, self.size, self.filter, self.sort, self.unwatched, type_=type_)

if self.isCanceled():
return
self.callback(items, self.start)
Expand Down Expand Up @@ -393,6 +403,7 @@ def __init__(self, *args, **kwargs):
windowutils.UtilMixin.__init__(self)
self.section = kwargs.get('section')
self.filter = kwargs.get('filter_')
self.subDir = kwargs.get('subDir')
self.keyItems = {}
self.firstOfKeyItems = {}
self.tasks = backgroundthread.Tasks()
Expand Down Expand Up @@ -470,11 +481,13 @@ def onFirstInit(self):
else:
self.showPanelControl = kodigui.ManagedControlList(self, self.POSTERS_PANEL_ID, 5)
self.keyListControl = kodigui.ManagedControlList(self, self.KEY_LIST_ID, 27)
self.setProperty('subDir', self.subDir and '1' or '')
self.setProperty('no.options', self.section.TYPE != 'photodirectory' and '1' or '')
self.setProperty('unwatched.hascount', self.section.TYPE == 'show' and '1' or '')
util.setGlobalProperty('sort', self.sort)
self.setProperty('filter1.display', self.filterUnwatched and T(32368, 'UNPLAYED') or T(32345, 'All'))
self.setProperty('sort.display', SORT_KEYS[self.section.TYPE].get(self.sort, SORT_KEYS['movie'].get(self.sort))['title'])
self.setProperty('media.itemType', ITEM_TYPE or self.section.TYPE)
self.setProperty('media.type', TYPE_PLURAL.get(ITEM_TYPE or self.section.TYPE, self.section.TYPE))
self.setProperty('media', self.section.TYPE)
self.setProperty('hide.filteroptions', self.section.TYPE == 'photodirectory' and '1' or '')
Expand Down Expand Up @@ -731,7 +744,7 @@ def shiftChunks(self, mod=1):
else:
self.chunkCallback([False] * CHUNK_SIZE, start)
task = ChunkRequestTask().setup(
self.section, start, CHUNK_SIZE, self.chunkCallback, filter_=self.getFilterOpts(), sort=self.getSortOpts(), unwatched=self.filterUnwatched
self.section, start, CHUNK_SIZE, self.chunkCallback, filter_=self.getFilterOpts(), sort=self.getSortOpts(), unwatched=self.filterUnwatched, subDir=self.subDir
)

self.tasks.add(task)
Expand Down Expand Up @@ -793,7 +806,8 @@ def chunkedPosJump(self, pos, start=None):
self.chunkCallback,
filter_=self.getFilterOpts(),
sort=self.getSortOpts(),
unwatched=self.filterUnwatched
unwatched=self.filterUnwatched,
subDir=self.subDir
)

self.tasks.add(task)
Expand Down Expand Up @@ -887,6 +901,9 @@ def itemTypeButtonClicked(self):
if self.section.TYPE == 'show':
for t in ('show', 'episode'):
options.append({'type': t, 'display': TYPE_PLURAL.get(t, t)})
elif self.section.TYPE == 'movie':
for t in ('movie', 'collection', 'folder'):
options.append({'type': t, 'display': TYPE_PLURAL.get(t, t)})
elif self.section.TYPE == 'artist':
for t in ('artist', 'album'):
options.append({'type': t, 'display': TYPE_PLURAL.get(t, t)})
Expand Down Expand Up @@ -1174,7 +1191,22 @@ def showPanelClicked(self):
self.processCommand(opener.handleOpen(subitems.ShowWindow, media_item=mli.dataSource, parent_list=self.showPanelControl))
updateWatched = True
elif self.section.TYPE == 'movie':
self.processCommand(opener.handleOpen(preplay.PrePlayWindow, video=mli.dataSource, parent_list=self.showPanelControl))
datasource = mli.dataSource
if datasource.isDirectory():
cls = self.section.__class__
section = cls(self.section.data, self.section.initpath, self.section.server, self.section.container)
sectionId = section.key
if not sectionId.isdigit():
sectionId = section.getLibrarySectionId()

section.set('librarySectionID', sectionId)
section.key = datasource.key
section.title = datasource.title

self.processCommand(opener.handleOpen(LibraryWindow, windows=self._windows, default_window=self._next, section=section, filter_=self.filter, subDir=True))
self.librarySettings.setItemType(self.librarySettings.getItemType())
Comment on lines +1195 to +1207
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this can be simplified as below - it seemed to work fine with the change:

Suggested change
if datasource.isDirectory():
cls = self.section.__class__
section = cls(self.section.data, self.section.initpath, self.section.server, self.section.container)
sectionId = section.key
if not sectionId.isdigit():
sectionId = section.getLibrarySectionId()
section.set('librarySectionID', sectionId)
section.key = datasource.key
section.title = datasource.title
self.processCommand(opener.handleOpen(LibraryWindow, windows=self._windows, default_window=self._next, section=section, filter_=self.filter, subDir=True))
self.librarySettings.setItemType(self.librarySettings.getItemType())
if datasource.isDirectory():
cls = self.section.__class__
section = cls(datasource.data, datasource.key, self.section.server, datasource.container)
sectionId = section.key if section.key.isdigit() else section.getLibrarySectionId()
section.set('librarySectionID', sectionId)
self.processCommand(opener.handleOpen(LibraryWindow, windows=self._windows, default_window=self._next, section=section, subDir=True))
self.librarySettings.setItemType(self.librarySettings.getItemType())

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the above, the section's key and title are no longer set. It's been a long time since I've looked at this code but I think this had to do with entering a directory that was contained within a directory.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure what you mean. When you pass datasource.data to the LibrarySection constructor, the key and title are set to the key and title of the datasource.data (which is the raw data that initialized datasource). I tested it with a directory within a directory and it seemed to work fine (once the other folder reloading fix was added).

else:
self.processCommand(opener.handleOpen(preplay.PrePlayWindow, video=datasource, parent_list=self.showPanelControl))
updateWatched = True
elif self.section.TYPE == 'artist':
if ITEM_TYPE == 'album':
Expand Down Expand Up @@ -1280,12 +1312,17 @@ def fillShows(self):
type_ = 4
elif ITEM_TYPE == 'album':
type_ = 9
elif ITEM_TYPE == 'collection':
type_ = 18

idx = 0
fallback = 'script.plex/thumb_fallbacks/{0}.png'.format(TYPE_KEYS.get(self.section.type, TYPE_KEYS['movie'])['fallback'])

if self.sort != 'titleSort':
sectionAll = self.section.all(0, 0, filter_=self.getFilterOpts(), sort=self.getSortOpts(), unwatched=self.filterUnwatched, type_=type_)
if self.sort != 'titleSort' or ITEM_TYPE == 'folder' or self.subDir:
if ITEM_TYPE == 'folder':
sectionAll = self.section.folder(0, 0, self.subDir)
else:
sectionAll = self.section.all(0, 0, filter_=self.getFilterOpts(), sort=self.getSortOpts(), unwatched=self.filterUnwatched, type_=type_)
totalSize = sectionAll.totalSize.asInt()
if not self.chunkMode:
for x in range(totalSize):
Expand Down Expand Up @@ -1358,7 +1395,7 @@ def fillShows(self):
for start in range(0, totalSize, CHUNK_SIZE):
tasks.append(
ChunkRequestTask().setup(
self.section, start, CHUNK_SIZE, self.chunkCallback, filter_=self.getFilterOpts(), sort=self.getSortOpts(), unwatched=self.filterUnwatched
self.section, start, CHUNK_SIZE, self.chunkCallback, filter_=self.getFilterOpts(), sort=self.getSortOpts(), unwatched=self.filterUnwatched, subDir=self.subDir
)
)
ct += 1
Expand Down Expand Up @@ -1591,7 +1628,8 @@ def _chunkCallback(self, items, start):
mli.setProperty('key', self.chunkMode.getKey(pos))

if showUnwatched:
mli.setLabel2(util.durationToText(obj.fixedDuration()))
if not obj.isDirectory():
mli.setLabel2(util.durationToText(obj.fixedDuration()))
mli.setProperty('art', obj.defaultArt.asTranscodedImageURL(*artDim))
if not obj.isWatched:
if self.section.TYPE == 'show':
Expand Down
9 changes: 8 additions & 1 deletion resources/language/English/strings.po
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@ msgid "Artists"
msgstr ""

msgctxt "#32348"
msgid "movies"
msgid "Movies"
msgstr ""

msgctxt "#32349"
Expand Down Expand Up @@ -975,6 +975,13 @@ msgctxt "#32485"
msgid "Go back instantly with the previous menu action in scrolled views"
msgstr ""

msgctxt "#32490"
msgid "Collections"
msgstr ""

msgctxt "#32491"
msgid "Folders"
msgstr ""
msgctxt "#32492"
msgid "Kodi Subtitle Settings"
msgstr ""
11 changes: 7 additions & 4 deletions resources/skins/Main/1080i/script-plex-listview-16x9-chunked.xml
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@
<posx>60</posx>
<posy>248</posy>
<control type="image">
<visible>!String.IsEqual(Window.Property(media),show)</visible>
<visible>!String.IsEqual(Window.Property(media),show) + !String.IsEqual(Window.Property(media),movie)</visible>
<posx>0</posx>
<posy>0</posy>
<width>630</width>
Expand All @@ -416,7 +416,7 @@
<aspectratio>scale</aspectratio>
</control>
<control type="image">
<visible>String.IsEqual(Window.Property(media),show)</visible>
<visible>String.IsEqual(Window.Property(media),show) | String.IsEqual(Window.Property(media),movie)</visible>
<posx>0</posx>
<posy>0</posy>
<width>630</width>
Expand Down Expand Up @@ -763,6 +763,7 @@
<onright>210</onright>
<ondown>50</ondown>
<control type="button" id="311">
<visible>!String.IsEqual(Window.Property(media.itemType),folder)</visible>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<visible>!String.IsEqual(Window.Property(media.itemType),folder)</visible>
<visible>!String.IsEqual(Window.Property(media.itemType),folder)</visible>

<enable>false</enable>
<width max="300">auto</width>
<height>65</height>
Expand All @@ -779,6 +780,7 @@
<label>[UPPERCASE]$INFO[Window.Property(filter2.display)][/UPPERCASE]</label>
</control>
<control type="button" id="211">
<visible>!String.IsEqual(Window.Property(media.itemType),folder)</visible>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<visible>!String.IsEqual(Window.Property(media.itemType),folder)</visible>
<visible>!String.IsEqual(Window.Property(media.itemType),folder)</visible>

<width max="500">auto</width>
<height>65</height>
<font>font12</font>
Expand All @@ -793,7 +795,7 @@
<label>[UPPERCASE]$INFO[Window.Property(filter1.display)][/UPPERCASE]</label>
</control>
<control type="button" id="310">
<visible>!String.IsEqual(Window.Property(media),show)</visible>
<visible>!String.IsEqual(Window.Property(media),show) + !String.IsEqual(Window.Property(media),movie)</visible>
<enable>false</enable>
<width max="300">auto</width>
<height>65</height>
Expand All @@ -810,7 +812,7 @@
<label>[UPPERCASE]$INFO[Window.Property(media.type)][/UPPERCASE]</label>
</control>
<control type="button" id="312">
<visible>String.IsEqual(Window.Property(media),show)</visible>
<visible>String.IsEqual(Window.Property(media),show) | String.IsEqual(Window.Property(media),movie)</visible>
<width max="300">auto</width>
<height>65</height>
<font>font12</font>
Expand All @@ -826,6 +828,7 @@
<label>[UPPERCASE]$INFO[Window.Property(media.type)][/UPPERCASE]</label>
</control>
<control type="button" id="210">
<visible>!String.IsEqual(Window.Property(media.itemType),folder)</visible>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<visible>!String.IsEqual(Window.Property(media.itemType),folder)</visible>
<visible>!String.IsEqual(Window.Property(media.itemType),folder)</visible>

<width max="300">auto</width>
<height>65</height>
<font>font12</font>
Expand Down
11 changes: 7 additions & 4 deletions resources/skins/Main/1080i/script-plex-listview-16x9.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
<posx>60</posx>
<posy>248</posy>
<control type="image">
<visible>!String.IsEqual(Window.Property(media),show)</visible>
<visible>!String.IsEqual(Window.Property(media),show) + !String.IsEqual(Window.Property(media),movie)</visible>
<posx>0</posx>
<posy>0</posy>
<width>630</width>
Expand All @@ -40,7 +40,7 @@
<aspectratio>scale</aspectratio>
</control>
<control type="image">
<visible>String.IsEqual(Window.Property(media),show)</visible>
<visible>String.IsEqual(Window.Property(media),show) | String.IsEqual(Window.Property(media),movie)</visible>
<posx>0</posx>
<posy>0</posy>
<width>630</width>
Expand Down Expand Up @@ -715,6 +715,7 @@
<onright>210</onright>
<ondown>50</ondown>
<control type="button" id="311">
<visible>!String.IsEqual(Window.Property(media.itemType),folder)</visible>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<visible>!String.IsEqual(Window.Property(media.itemType),folder)</visible>
<visible>!String.IsEqual(Window.Property(media.itemType),folder)</visible>

<enable>false</enable>
<width max="300">auto</width>
<height>65</height>
Expand All @@ -731,6 +732,7 @@
<label>[UPPERCASE]$INFO[Window.Property(filter2.display)][/UPPERCASE]</label>
</control>
<control type="button" id="211">
<visible>!String.IsEqual(Window.Property(media.itemType),folder)</visible>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<visible>!String.IsEqual(Window.Property(media.itemType),folder)</visible>
<visible>!String.IsEqual(Window.Property(media.itemType),folder)</visible>

<width max="500">auto</width>
<height>65</height>
<font>font12</font>
Expand All @@ -745,7 +747,7 @@
<label>[UPPERCASE]$INFO[Window.Property(filter1.display)][/UPPERCASE]</label>
</control>
<control type="button" id="310">
<visible>!String.IsEqual(Window.Property(media),show)</visible>
<visible>!String.IsEqual(Window.Property(media),show) + !String.IsEqual(Window.Property(media),movie)</visible>
<enable>false</enable>
<width max="300">auto</width>
<height>65</height>
Expand All @@ -762,7 +764,7 @@
<label>[UPPERCASE]$INFO[Window.Property(media.type)][/UPPERCASE]</label>
</control>
<control type="button" id="312">
<visible>String.IsEqual(Window.Property(media),show)</visible>
<visible>String.IsEqual(Window.Property(media),show) | String.IsEqual(Window.Property(media),movie)</visible>
<width max="300">auto</width>
<height>65</height>
<font>font12</font>
Expand All @@ -778,6 +780,7 @@
<label>[UPPERCASE]$INFO[Window.Property(media.type)][/UPPERCASE]</label>
</control>
<control type="button" id="210">
<visible>!String.IsEqual(Window.Property(media.itemType),folder)</visible>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<visible>!String.IsEqual(Window.Property(media.itemType),folder)</visible>
<visible>!String.IsEqual(Window.Property(media.itemType),folder)</visible>

<width max="300">auto</width>
<height>65</height>
<font>font12</font>
Expand Down
Loading