Coder Social home page Coder Social logo

Comments (5)

mezz64 avatar mezz64 commented on July 30, 2024 1

@mcarlton00 I'd prefer the remove None valued keys approach. Seems much more elegant than checking everywhere.

from pyemby.

rynr avatar rynr commented on July 30, 2024

I asked for help at reddit, will hopefully get some response.

from pyemby.

iwalton3 avatar iwalton3 commented on July 30, 2024

This would be because the Jellyfin serializer started returning null values instead of not including the key in the response. It caused some problems for me too in jellyfin-mpv-shim.

This code would have to be updated to deal with a null value for device['NowPlayingItem'] in addition to the key not being present.

It was changed all over, so more changes for where keys historically weren't present now need to also deal with null values. I've gotten really defensive about null values coming back from Jellyfin accordingly.

from pyemby.

mcarlton00 avatar mcarlton00 commented on July 30, 2024

iwalton's correct. What's happening is that some of the responses from the server are coming back as None. As an example, here's the device profile I'm getting from Home Assistant.

{'AdditionalUsers': [],
 'ApplicationVersion': '1.6',
 'Capabilities': {'AppStoreUrl': None,
                  'DeviceProfile': None,
                  'IconUrl': None,
                  'MessageCallbackUrl': None,
                  'PlayableMediaTypes': [],
                  'SupportedCommands': [],
                  'SupportsContentUploading': False,
                  'SupportsMediaControl': False,
                  'SupportsPersistentIdentifier': True,
                  'SupportsSync': False},
 'Client': 'Home-Assistant',
 'DeviceId': '229044588395818',
 'DeviceName': 'HomeAssistant',
 'DeviceType': None,
 'FullNowPlayingItem': None,
 'HasCustomDeviceName': False,
 'Id': 'b8a8f09816c76aa04e04dbd3151f4cff',
 'IsActive': True,
 'LastActivityDate': '2020-09-20T16:04:15.3467043Z',
 'LastPlaybackCheckIn': '0001-01-01T00:00:00',
 'NowPlayingItem': None,
 'NowPlayingQueue': None,
 'NowViewingItem': None,
 'PlayState': {'AudioStreamIndex': None,
               'CanSeek': False,
               'IsMuted': False,
               'IsPaused': False,
               'MediaSourceId': None,
               'PlayMethod': None,
               'PositionTicks': None,
               'RepeatMode': 'RepeatNone',
               'SubtitleStreamIndex': None,
               'VolumeLevel': None},
 'PlayableMediaTypes': [],
 'PlaylistItemId': None,
 'RemoteEndPoint': '::ffff:192.168.0.148',
 'ServerId': '0e23a5ed08c84a159ea7d7aea7ff5e67',
 'SupportedCommands': [],
 'SupportsMediaControl': False,
 'SupportsRemoteControl': False,
 'TranscodingInfo': None,
 'UserId': '00000000-0000-0000-0000-000000000000',
 'UserName': None,
 'UserPrimaryImageTag': None}

Relatively easy fix, but then there's several other places in the codebase that are doing similar things where it assumes if the key exists, it will be a dict. For example:

new_theme = new['NowPlayingItem']['IsThemeMedia']
and

pyEmby/pyemby/device.py

Lines 124 to 125 in 6bb621e

artists = self.session['NowPlayingItem']['Artists']
if len(artists) > 1:

I'm working through and trying to find each of them right now, should have a PR up in a bit.

from pyemby.

mcarlton00 avatar mcarlton00 commented on July 30, 2024

Further update: In it's current state basically every function in device.py that involves the NowPlayingItem needs refactored. eg:

@property
def media_id(self):
    """ Return title currently playing."""
    try:
        return self.session['NowPlayingItem']['Id']
    except KeyError:
        return None

would need to become something along the lines of

@property
def media_id(self):
    """ Return title currently playing."""
    if self.session['NowPlayingItem']:
        return self.session['NowPlayingItem']['Id']
    else:
        return None

Obviously this would be a lot of changes in that file that may not be entirely wanted. An alternative method would be something that we implemented in our Kodi addon that solves the problem by simply removing all keys with values of None. https://github.com/jellyfin/jellyfin-kodi/blob/master/jellyfin_kodi/jellyfin/utils.py

@mezz64 let me know which direction you'd rather go with it.

from pyemby.

Related Issues (4)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.