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

Collection and folder #275

wants to merge 2 commits into from

Conversation

gbooker
Copy link
Collaborator

@gbooker gbooker commented Mar 6, 2019

GHI (If applicable): None

Description:

Allow browsing movies by collection and by folder. Useful for a large movie library and a library where there is no metadata and items are arranged on the server by folder.

Checklist:

  • I have based this PR against the develop branch

@gbooker gbooker requested a review from ruuk March 6, 2019 16:16
@ruuk ruuk self-assigned this Oct 6, 2019
@pannal
Copy link
Contributor

pannal commented Oct 27, 2019

Hey, I've been testing this PR; it seems to fail reproducably.

When entering an empty folder (in my case a "subs" folder that doesn't return any children whatsoever) inside a valid folder, then going back up again until the main library view is hit, then opening any item results in an empty view.

pannal added a commit to pannal/plex-for-kodi that referenced this pull request Oct 27, 2019
@pannal
Copy link
Contributor

pannal commented Oct 27, 2019

OK, this is a pretty easy fix:

Index: lib/windows/library.py
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- lib/windows/library.py	(revision ea1b1bc138ce7f45803dc6bd08c7b0b06c34f4c5)
+++ lib/windows/library.py	(revision e1b05f65fd38c4b4399e2a0a928cc51d00157462)
@@ -1219,7 +1219,7 @@
                 self.librarySettings.setItemType(self.librarySettings.getItemType())
             else:
                 self.processCommand(opener.handleOpen(preplay.PrePlayWindow, video=datasource, parent_list=self.showPanelControl))
-            updateWatched = True
+                updateWatched = True
         elif self.section.TYPE == 'artist':
             if ITEM_TYPE == 'album':
                 self.openItem(mli.dataSource)
@@ -1652,7 +1652,7 @@
                             if not obj.isDirectory():
                                 mli.setLabel2(util.durationToText(obj.fixedDuration()))
                             mli.setProperty('art', obj.defaultArt.asTranscodedImageURL(*artDim))
-                            if not obj.isWatched:
+                            if not obj.isWatched and obj.TYPE != "Directory":
                                 if self.section.TYPE == 'show':
                                     mli.setProperty('unwatched.count', str(obj.unViewedLeafCount))
                                 else:

Copy link
Contributor

@ruuk ruuk left a comment

Choose a reason for hiding this comment

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

Looks and works great, just some minor comments, and it needs the below fix as reloading folders seems to break them (and is unnecessary in any case).

diff --git a/lib/_included_packages/plexnet/plexobjects.py b/lib/_included_packages/plexnet/plexobjects.py
index 12eeb76..1011037 100644
--- a/lib/_included_packages/plexnet/plexobjects.py
+++ b/lib/_included_packages/plexnet/plexobjects.py
@@ -123,6 +123,9 @@ class Checks:
     def isDirectory(self):
         return self.name == "Directory" or self.name == "Playlist"
 
+    def isFolder(self):
+        return '/folder?' in self.key
+
     def isPhotoOrDirectoryItem(self):
         return self.type == "photoalbum"  # or self.isPhotoItem()
 
@@ -215,6 +218,9 @@ class PlexObject(object, Checks):
         if _soft and self._reloaded:
             return self
 
+        if self.isFolder():
+            return self
+
         try:
             if self.get('ratingKey'):
                 data = self.server.query('/library/metadata/{0}'.format(self.ratingKey), params=kwargs)

@@ -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>

@@ -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>

@@ -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>

@@ -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>

@@ -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>

@@ -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>

@@ -669,6 +669,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>

@@ -685,6 +686,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>

@@ -732,6 +734,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>

Comment on lines +1195 to +1207
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())
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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants