Menu

#105 Metadata pusher to IDJC

v1.0 (example)
closed
nobody
None
5
2023-09-22
2021-10-19
Guesst
No

Hello, I requested support to send metadata to the IDJC stream from an external source, in this case a text file, Thanks to the team that helped me with an example code:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#!/usr/bin/env python
import sys
import re

import dbus
from dbus.exceptions import DBusException

def main(profile):
        session = dbus.SessionBus()
        for metadata in sys.stdin:
            try:
                output = session.get_object('net.sf.idjc.' + profile, '/net/sf/idjc/output')
                output.set_metadata_control_string(0, metadata.strip(), dbus_interface='net.sf.idjc')
                output.metadata_update(0, dbus_interface='net.sf.idjc')
            except DBusException as e:
                print(e)
        # Optional: Handle scenario where idjc is not running here.
        # e.g. return 5

        return 0

if name == "main":
        try:
                PROFILE = sys.argv[1]
        except IndexError:
                PROFILE = "default"

sys.exit(main(PROFILE))

After some syntaxis adjustments with my limited python skills I ended up only with the error:

NameError: name 'name' is not defined

So for testing purposes i define it manually, and test it without errors but also didn't worked with the metadata change on the stream.

If someone could give me a tip to continue my search I would appreciate it.

Greetings

Discussion

  • Stephen Fairchild

    Here it is again this time in code tags.

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    #! /usr/bin/env python
    
    """dbusmeta.py: dbus example pushes metadata to idjc
    
    type stuff in console to see it appear as metadata
    """
    
    
    import sys
    import re
    
    import dbus
    from dbus.exceptions import DBusException
    
    
    def main(profile):
        session = dbus.SessionBus()
    
        for metadata in sys.stdin:
            try:
                output = session.get_object('net.sf.idjc.' + profile, '/net/sf/idjc/output')
                output.set_metadata_control_string(0, metadata.strip(), dbus_interface="net.sf.idjc")
                output.metadata_update(0, dbus_interface="net.sf.idjc")
            except DBusException as e:
                print(e)
                # Optional: Handle scenario where idjc is not running here.
                # e.g. return 5
    
        return 0
    
    
    if __name__ == "__main__":
        try:
            PROFILE = sys.argv[1]
        except IndexError:
            PROFILE = "default"
    
        sys.exit(main(PROFILE))
    
     
  • Stephen Fairchild

    This will only work if you are logged in on the same user account on the same machine. If you want it to work on a different profile than default you have to supply it on the command line.

    Example one off usage:

    $ echo "New Metadata" | python dbusmeta.py default
    
     
  • Guesst

    Guesst - 2021-10-21

    I tested on the user session in the same machine with the default profile, It didn't change the metadata, but also I didn't got any errors, I tested python with -v but got no error or warning messages. I'll try it in the console, thank you for the support.

     
  • Stephen Fairchild

    It dawned on me that the version of IDJC you are using could be too old for this to work. Reckon your version number is among the 0.8 series.

     
  • Guesst

    Guesst - 2021-10-23

    I've compiled V 0.9.1 because Debian hasn't include it in Bullseye, everything is working great, maybe there's something else I can check.

     
  • Guesst

    Guesst - 2022-04-20

    It worked! after checking I've found that the script works properly, my problem was that I had two outputs and the change only works in the first output stream.

    Thank you very much Stephen!

     
  • Stephen Fairchild

    See the line of code that goes: output.set_metadata_control_string(0, ...
    Replace the 0 with a 1 to affect metadata on the second stream and so on.
    The same applies for metadata_update.

     

    Last edit: Stephen Fairchild 2022-04-21
  • Stephen Fairchild

    • status: open --> closed
     

Log in to post a comment.