petio-team / petio

Petio Request, Discover, Review
https://petio.tv
MIT License
251 stars 28 forks source link

Link to watch in Plex doesn't respect library access. #270

Open JackGameer opened 3 years ago

JackGameer commented 3 years ago

Describe the bug Having multiple libraries in Plex (such as 1080p and 4K) leads to duplicates of movies/shows. When using the "Watch Now" link to view a piece of content in Plex it takes me to the 4K library. However most of my users do not have access to this library, so it's a dead link.

Expected behavior Petio should only direct users to libraries they have access to, so in this instance to the 1080p library.

AshDyson commented 3 years ago

I don't think we'll be able to actually determine user access like this, but I do think we could force plex to link to the lower resolution item or atleast a dropdown selection of all versions etc

JackGameer commented 3 years ago

As a quick fix, a combination of those solutions mentioned would be fine. So like you said default to the lower resolution copy and have a dropdown where the higher resolution copy could be selected.

Regarding determining user access per library, if you're not opposed to making API calls to plex.tv you can try this endpoint, from my little research it seems to be the only one I can find that gives library share details.

https://plex.tv/api/servers/{serverMachineId}/shared_servers/ X-Plex-Token will need to be sent as well with a valid access token

It will list all users that have access to the server in the format below

<SharedServer id=“0000000” username=“User” email=“user@user.com" userID=“0000000” accessToken=“abc123” name="Plex Server" acceptedAt=“0000000” invitedAt=“0000000” allowSync="1" allowCameraUpload="0" allowChannels="0" allowTuners="0" allowSubtitleAdmin="0" owned="1" allLibraries="0" filterAll="" filterMovies="" filterMusic="" filterPhotos="" filterTelevision="">
    <Section id="0000000" key="4" title="Anime" type="show" shared="1"/>
    <Section id="0000000" key="1" title="Movies" type="movie" shared="1"/>
    <Section id="0000000" key="3" title="Movies UHD" type="movie" shared=“0”/>
    <Section id="0000000" key="2" title="TV Shows" type="show" shared="1"/>
    <Section id="0000000" key="5" title="TV Shows UHD" type="show" shared=“0”/>
  </SharedServer>

This is a user who has access to every library apart from the 4K(UHD) ones.

bakes82 commented 3 years ago

If using plex auth (every user needs a plex account), then just loop over each users "servers" then loop over each servers libraries and find if it exists and then display a link for each server. This way nothing is ever 1 server agnostic, and if you want to move/bold the "server" that the request system is for that would be fine too. But it would be nice to be able find a high quality version of the movie I want to watch across my available shared servers. IE: You have 4 plex shared server, you would see a drop down like: Server 1 - Movies 1080p Server 1 - Movies 720p Server 2 - Movies Server 2 - Movies 4k-Remux Server 3 - Movies Server 3 - Movies Low Quality Server 4 - Movie Doesn't Exist

JackGameer commented 3 years ago

In reference to my previous comment. I've made a proof of concept for determining per library access. https://gist.github.com/JackGameer/945f500b4f180caaf5882f3940441a6d Example output below with different users who have access to different libraries

{
  id: '00000000',
  title: 'user@user.com',
  username: 'user@user.com',
  email: 'suser@user.com',
  recommendationsPlaylistId: '',
  thumb: 'https://plex.tv/users/abc123/avatar?c=0000000',
  Server: {
    id: '00000000',
    serverId: '00000000',
    machineIdentifier: 'abc123',
    name: 'Plex Server',
    lastSeenAt: '00000000',
    numLibraries: '2',
    owned: '1'
  },
  quotaCount: 0,
  Libraries: [
    {
      id: '00000000',
      key: '1',
      title: 'Movies',
      type: 'movie',
      shared: '1'
    },
    {
      id: '00000000',
      key: '2',
      title: 'TV Shows',
      type: 'show',
      shared: '1'
    }
  ]
}
{
  id: '00000000',
  title: 'user2@user.com',
...
   Libraries: [
    {
      id: '00000000',
      key: '5',
      title: 'Anime',
      type: 'show',
      shared: '1'
    },
    {
      id: '00000000',
      key: '1',
      title: 'Movies',
      type: 'movie',
      shared: '1'
    },
    {
      id: '00000000',
      key: '3',
      title: 'Movies UHD',
      type: 'movie',
      shared: '1'
    },
    {
      id: '00000000',
      key: '2',
      title: 'TV Shows',
      type: 'show',
      shared: '1'
    },
    {
      id: '00000000',
      key: '4',
      title: 'TV Shows UHD',
      type: 'show',
      shared: '1'
    }
  ]
}

The keys of the user's libraries can be compared against the section id/keys (librarySectionID) in the metadata of the content, determining if the user has access to the library it's located in.

AshDyson commented 3 years ago

The added complexity of this style lookup will just lag the front end unfortunately. I think the best solution is to just list out all versions available

ADRFranklin commented 3 years ago

Yeah it makes more sense to have a dropdown, because as you said with users not having access to the 4k, you wouldn't want someone who has access to both, only being able to watch it in the lowest resolution if they use a 4k monitor or device.

So being able to choose from a dropdown, makes more sense without breaking UX for users with different criteria's.

AshDyson commented 3 years ago

Assigning this to a feature request as it's no longer regarded as a bug