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

Provide User Interface to the MythTV's Services #198

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

rcrdnalor
Copy link
Contributor

See https://www.mythtv.org/wiki/Services_API .

The class 'MythTVService' can be used in two ways:

Either to be called directly with all parameters to perform an
operation:
Each operation consists of a call to - and a reception of - the
selected MythTVService.
A direct call uses at least the following parameters:

  • service: the service category one is asking for (e.g.: 'Dvr')
    optype = 'POST' # or 'GET'
  • opdata: a dictionary describing the data needed to perform the
    operation.

Or 'MythTVService' is used sequentially by calling:

  • getoperation
  • strip_operation_defaults
  • encode_operation
  • perform_operation

An instance of the 'MythTVService' class can be reused to perform
multiple operations of the same service type.

Example:
ms = MythTVService('Channel', host)
op = ms.getoperation('GetChannelInfoList')
op['opdata']['SourceID'] = 1
op['opdata']['Details'] = True
op_stripped = ms.strip_operation_defaults('GetChannelInfoList', op)
op_encoded = ms.encode_operation(op_stripped)
if ms.perform_operation(op_encoded):
# 'ms' is now an object of type 'GetChannelInfoList'
print(ms.channelinfos[0].chanid)

Notes about naming convention:
The MythTV Python Bindings use lower-case names for their attributes.
The MythTV-Services API use 'CamelCase' notation for the data needed
by 'POST' and returned by 'GET' operations.
During processing of these data, they are converted to lower-case:
Please note, that Python's PEP-08 dislikes 'CamelCase' notation for
naming attributes of a class.

Since every call to 'MythTVService' returns an instance derived from
the base-class 'DictData', one can access these data by either using
av'dictionary-like notation', or using the 'key as attribute'.

TL;DR: Attributes are lower-case names and the following notations
belong to the same object:
- ms.channelinfo.chanid
- ms.channelinfo['chanid']
- ms['channelinfo']['chanid']

A list of operations of the selcted service can be retrieved by
calling 'ms.list_operations()'.
A list of available attributes of an already performed operation
is returned by calling 'ms.list_attributes()'.

Notes about logging:
This module uses the internal logging mechanism from 'logging.py'.
To enable all debug logging to console, start the python script with
$ python3 your_script.py --loglevel debug --verbose all .
For the interactive python shell, replace the scriptname with a
dash ("-").

See 'MythTV/services_api/send.py' for logging of the services_api.

Thank you for contributing to MythTV.

As many of our developers do not visit GitHub it is important to track
all contributions at our central ticket tracker over at code.mythtv.org

To prevent your contributions being overlooked please create a new ticket
there and refer to this pull request. (Bonus points for linking to the
ticket in the pull request, too. It helps us noticed potentially overlooked
pull requests due to missing tickets.)

https://code.mythtv.org/trac/wiki/TicketHowTo
https://code.mythtv.org/trac/newticket

@rcrdnalor
Copy link
Contributor Author

See ticket #13620 for the basic information and for a simple tutorial.

@stuarta stuarta added component:bindings:python Python Bindings component:mythtv:api Services API issues labels Sep 1, 2020
See https://www.mythtv.org/wiki/Services_API .

The class 'MythTVService' can be used in two ways:

Either to be called directly with all parameters to perform an
operation:
Each operation consists of a call to - and a reception of - the
selected MythTVService.
A direct call uses at least the following parameters:
  - service: the service category one is asking for (e.g.: 'Dvr')
    optype = 'POST' # or 'GET'
  - opdata: a dictionary describing the data needed to perform the
            operation.

Or 'MythTVService' is used sequentially by calling:
  - getoperation
  - strip_operation_defaults
  - encode_operation
  - perform_operation

An instance of the 'MythTVService' class can be reused to perform
multiple operations of the same service type.

Example:
  ms = MythTVService('Channel', host)
  op = ms.getoperation('GetChannelInfoList')
  op['opdata']['SourceID'] = 1
  op['opdata']['Details'] = True
  op_stripped = ms.strip_operation_defaults('GetChannelInfoList', op)
  op_encoded = ms.encode_operation(op_stripped)
  if ms.perform_operation(op_encoded):
        # 'ms' is now an object of type 'GetChannelInfoList'
        print(ms.channelinfos[0].chanid)

Notes about naming convention:
The MythTV Python Bindings use lower-case names for their attributes.
The MythTV-Services API use 'CamelCase' notation for the data needed
by 'POST' and returned by 'GET' operations.
During processing of these data, they are converted to lower-case:
Please note, that Python's PEP-08 dislikes 'CamelCase' notation for
naming attributes of a class.

Since every call to 'MythTVService' returns an instance derived from
the base-class 'DictData', one can access these data by either using
av'dictionary-like notation', or using the 'key as attribute'.

TL;DR: Attributes are lower-case names and the following notations
belong to the same object:
    - ms.channelinfo.chanid
    - ms.channelinfo['chanid']
    - ms['channelinfo']['chanid']

A list of operations of the selcted service can be retrieved by
calling 'ms.list_operations()'.
A list of available attributes of an already performed operation
is returned by calling 'ms.list_attributes()'.

Notes about logging:
This module uses the internal logging mechanism from 'logging.py'.
To enable all debug logging to console, start the python script with
$ python3 your_script.py --loglevel debug --verbose all .
For the interactive python shell, replace the scriptname with a
dash ("-").

See 'MythTV/services_api/send.py' for logging of the services_api.
The xml data retrieved from the host by the Services-API are
of different types:

- a simple response containing only values or list of values,
  like the response to 'GetHostName' or 'GetHosts'.
  Simple responses get evaluated and are returned directly,
  because their element-tags are not defined in the wsdl.

- a complex response containing a xml namespace and a version,
  like the response to 'ChannelInfo' or 'ChannelInfoList'.
  Complex responses will be objectified within the class itself.

The result of an operation is now stored in
'MythTVService.operation_result', too.
Elements of type 'ArrayOf' occur in two flowers:

 - Either defined with types of the "xs" namespace like
   "ArrayOfString"
 - Or defined with types of the the "tns" namespace like
   "ArrayOfProgram".

This fixes parsing of list-elements of the basic namespace 'xs'.
Timeout can now be set globally for a 'MythTVService' session or
can be set for each operation.
Especially uUseful when retrieving metadata.
@rcrdnalor rcrdnalor force-pushed the devel/mythservices branch from ca2db07 to c7e7847 Compare March 2, 2022 20:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component:bindings:python Python Bindings component:mythtv:api Services API issues
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants