Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

Replacing the JavaScript Engin with Python

alex sayle
2011-09-17
2013-05-30
1 2 3 > >> (Page 1 of 3)
  • alex sayle
    alex sayle
    2011-09-17

    How much interest would there be in a patch to replace the JavaScript engin with Python?

    I'm asking as I've written most of it. I've currently got a python interpreter running inside mediatomb and I can pass it files, by tomorrow eve ( UK time ) I'm hoping to of wired the basic functionality for manipulating mediatomb objects.

    I'm personally only interested in Video and I have no need for JS so I was going to rip it out .. I could keep the JS around, and wire up non-video media if there's an interest.

    either-way I'll post back with a link to my github branch and some results.

     
  • Lyall Pearce
    Lyall Pearce
    2011-09-18

    Personally I have no preference either way, so long as the end user experience does not change.

    Now, if the change involved the ability to have on-line, off-line or near-line media storage where MT would recognise that a USB drive was off-line and not delete all the content stored on that drive but serve up a 'Media offline' message. Of course, individual media content that goes missing whilst other still exists would be deleted as it is now.

    This, imho, would be awesome.

     
  • Aaron Bronow
    Aaron Bronow
    2011-09-18

    I for one use the music streaming feature on my PS3. I haven't been successful at getting YouTube to work but I'm interested in using that non-video media as well.

     
  • Lyall Pearce
    Lyall Pearce
    2011-09-18

    FYI: video and photos work just fine on the PS3, from MT.

     
  • alex sayle
    alex sayle
    2011-09-18

    groovy, once I've done video, I'll look at music as well then. Don't expect much in the way of default scripts tho :D

    In regards to the off line mode, I'm personally not interested in messing with too much of the MT internals as it makes a patch less likely to be accepted … but it doesn't harm to think/talk about it.

    what kind of experience are you after ? to be able to mark  a section of the physical drives as "offline-able" and not delete items on scan ? at what point do you delete them ? if the mount point changes ?  what would the Upnp client see ? what would the behaviour of playing a media file that is "offline" mean ? ( apart from RickRolling )

     
  • alex sayle
    alex sayle
    2011-09-18

    oh bugger I thought I'd side stepped the whole thing by asking questions. EPIC FAIL on my part. I'll eat my own dog food and take a look.

    I'll do the python stuff first and then take a look at whole "do-able" off-line mode is.

     
  • chowjok
    chowjok
    2011-09-19

    This has been suggested before (See: https://sourceforge.net/projects/mediatomb/forums/forum/440750/topic/4049112?message=8997614), so there're many people who're interested.

    I'm mainly interested in using external APIs which isn't currently possible with the current JS implementation. I'm very interested to try out what've you done. I think Python will be suitable to accomplish what I need my import scripts to do. I don't have much of a use for images and music either.

     
  • alex sayle
    alex sayle
    2011-09-19

    I've posted onto the other thread as well.

    Ok so there's enough interest to roll it up into something distributable then.

    The Current status is that I have python up and running, I've done m4 macros so that ./configure will look for Python and generate appropriate lines in the header files. The compiler has been informed of python and the linking will happen automagically. I haven't touched the config side so you have to place python in place of the JS but it works to an extent where you can get a mediatomb module / object loaded inside python inside MediaTomb. (although the properties mostly have "42" in them as place holders and no real data )

    I'll clean it up a tad and put it up on git hub ..

    What distro's do people  use ? I'm a Debian man myself and thus have debs being built, I can exntend this a version of two ubuntu if that's a populer use case.

     
  • alex sayle
    alex sayle
    2011-09-19

    And FYI, the py code would then look like the following.

    def do_magic_with_video(media):
       # do cool stuff here.
    import mediatomb
    mediatomb.log("Starting Import Script")
    
    media = mediatomb.MediaTomb()
    if  media.mime = "video":
        do_magic_with_video(media)
    mediatomb.log("end import script")
    

    The mediatomb module would only be availble inside the MediaTomb Runtime as its defined in C(++) with in the runtime context.

    I'm happy to take suggestions on what the Python API should look like.

    I'll be clear that I'm doing this for my own needs and my dislike for ECMA Script.  I'm not going to promise changes that I haven't looked into, nor will I do too much support on stuff that I don't use.

    This thread will be the one that I'll post on aas things progress.

    Now, time for coffee and my day job …

     
  • chowjok
    chowjok
    2011-09-19

    I'm using Fedora. A diff file will do for me as I'll be compiling it myself.

     
  • alex sayle
    alex sayle
    2011-09-19

    would github do ? :D

     
  • chowjok
    chowjok
    2011-09-19

    Sure :P

     
  • alex sayle
    alex sayle
    2011-09-19

    Initial code. Please note, its feature incomplete.

    https://github.com/crankcube/mediatomb

    As present you can compile it giggle to self that python is linked,  set up config.xml up as if it you would to run JS and replace the import.js file with python. There is not enough API to fiddle the media objects or any state within MediaTomb.

    I build it on Debian Squeeze and haven't tested it on anything else, so issue reports or even "hey it builds on X!" would be supereb.

    I've pressed buttons on the github page so it has an issue tracker and what not .. so if those interested could use it, that'd be awesome.

     
  • chowjok
    chowjok
    2011-09-19

    Ran the configure script successfully and it says libpython is enabled. But it also says libjs is enabled. Is this still needed?

    During compile I get the following error:

    g++ -DHAVE_CONFIG_H -I. -I.. -I../tombupnp/upnp/inc   -I/usr/include/ffmpeg -I../src -I../tombupnp/ixml/inc -I../tombupnp/threadutil/inc -I../tombupnp/upnp/inc -I..  -I/usr/include/mysql -g -pipe -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m32 -fasynchronous-unwind-tables -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -fno-strict-aliasing -fwrapv -fPIC  -fPIC -g -static-libgcc -fno-omit-frame-pointer -fno-strict-aliasing -DMY_PTHREAD_FASTMUTEX=1 -I/usr/include/js -I/usr/include/taglib       -pthread  -I/usr/include/ffmpeg        -g -O2 -I/usr/include/python2.7 -I/usr/include/python2.7 -fno-strict-aliasing -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m32 -march=i686 -mtune=atom -fasynchronous-unwind-tables -D_GNU_SOURCE -fPIC -fwrapv -DNDEBUG -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m32 -march=i686 -mtune=atom -fasynchronous-unwind-tables -D_GNU_SOURCE -fPIC -fwrapv  -MT libmediatomb_a-atrailers_service.o -MD -MP -MF .deps/libmediatomb_a-atrailers_service.Tpo -c -o libmediatomb_a-atrailers_service.o `test -f '../src/atrailers_service.cc' || echo './'`../src/atrailers_service.cc
    In file included from /usr/include/python2.7/pyconfig.h:4:0,
                     from /usr/include/python2.7/Python.h:8,
                     from ../src/scripting/script.h:37,
                     from ../src/scripting/playlist_parser_script.h:36,
                     from ../src/content_manager.h:46,
                     from ../src/atrailers_service.cc:41:
    /usr/include/python2.7/pyconfig-32.h:1164:0: warning: "_POSIX_C_SOURCE" redefined [enabled by default]
    /usr/include/features.h:164:0: note: this is the location of the previous definition
    /usr/include/python2.7/pyconfig-32.h:1186:0: warning: "_XOPEN_SOURCE" redefined [enabled by default]
    /usr/include/features.h:166:0: note: this is the location of the previous definition
    In file included from ../src/scripting/playlist_parser_script.h:36:0,
                     from ../src/content_manager.h:46,
                     from ../src/atrailers_service.cc:41:
    ../src/scripting/script.h:75:5: error: JSScript does not name a type
    ../src/scripting/script.h:76:5: error: JSScript does not name a type
    In file included from ../src/scripting/playlist_parser_script.h:36:0,
                     from ../src/content_manager.h:46,
                     from ../src/atrailers_service.cc:41:
    ../src/scripting/script.h:157:5: error: JSScript does not name a type
    ../src/scripting/script.h:158:19: error: JSScript has not been declared
    make[2]: *** [libmediatomb_a-atrailers_service.o] Error 1
    make[2]: Leaving directory `/home/chowjok/Desktop/crankcube-mediatomb-d46b4fc/build'
    make[1]: *** [all-recursive] Error 1
    make[1]: Leaving directory `/home/chowjok/Desktop/crankcube-mediatomb-d46b4fc'
    make: *** [all] Error 2
    
     
  • chowjok
    chowjok
    2011-09-19

    Issue raised on github

     
  • alex sayle
    alex sayle
    2011-09-19

    yes, JS support is still needed as I haven't ripped it out yet.

    Ok, I see the error and I see why its yapping at you… will fix it up when I'm not at my day job :)
    if you want to touch it up quickly you can edit src/scripting/script.h and comment out  line 72 - 76. that should shut that error up.

    the warnings are another story.. but they'e not harmful.

     
  • alex sayle
    alex sayle
    2011-09-19

    Thank you :)

     
  • chowjok
    chowjok
    2011-09-19

    I ran configure again with -enable-js=no but this time it says jsapi.h is not found.

     
  • chowjok
    chowjok
    2011-09-19

    Okay, thanks. I'll try that.

     
  • chowjok
    chowjok
    2011-09-19

    Alright, commented out lines 72-76 and got another JSSscript error, so commented out lines 157 and 158 as well and those errors were fixed.

    I then got another error:

    ../src/scripting/script.cc: In constructor ‘Script::Script(zmm::Ref<Runtime>)’:
    ../src/scripting/script.cc:1333:9: error: ‘rt’ was not declared in this scope
    ../src/scripting/script.cc: In member function ‘zmm::Ref<CdsObject> Script::pyObject2cdsObject(PyObject*, zmm::Ref<CdsObject>)’:
    ../src/scripting/script.cc:1375:1: warning: no return statement in function returning non-void [-Wreturn-type]
    ../src/scripting/script.cc: In member function ‘PyObject* Script::getObjectProperty(PyObject*, zmm::String)’:
    ../src/scripting/script.cc:1385:1: warning: no return statement in function returning non-void [-Wreturn-type]
    make[2]: *** [libmediatomb_a-script.o] Error 1
    make[2]: Leaving directory `/home/chowjok/Desktop/crankcube-mediatomb-d46b4fc/build'
    make[1]: *** [all-recursive] Error 1
    make[1]: Leaving directory `/home/chowjok/Desktop/crankcube-mediatomb-d46b4fc'
    make: *** [all] Error 2
    
     
  • alex sayle
    alex sayle
    2011-09-19

    Oh lovely.  Maybe I missed a commit somewhere … ? I'll clean it  up.

    Okm so here's the question de-jour.

    should ,
    1) JS be completely ripped out of the code base, configuration and all
    2) JS and Python be made murually exclusive
    3) JS and Python can live side by side

    the amount of effort involved is in that order and I personally prefer 1) or 2).

     
  • chowjok
    chowjok
    2011-09-19

    Assuming your modifications are going to be merged with mediatomb, in my opinion 2) is better because some people might wanna stick with their existing configuration. Personally I don't mind anything.

     
  • alex sayle
    alex sayle
    2011-09-19

    2) JS and Python be made mutually exclusive, does feel like the SANE solution, more #ifdefs for me!

    I'll add a configuration flag -script-engine=(js|javascript|py|python|none) to select which ( or any ) engine will be embeded.

     
  • alex sayle
    alex sayle
    2011-09-20

    As said earlier,
    I've made PY runtime and JS runtime mutually exclusive from each other.

    there's a new -enable-scripting= flag which defaults to python and turns off JS support. JS support is still available via
    -enable-scripting=javascript.

    ./configure will now also show what scripting engine is being used

    CONFIGURATION SUMMARY ----
    ...
    scripting : yes (python)
    libpython : yes
    

    a new virtual-layout type is also available and must be used for python import scripts.

         <virtual-layout type="py">
            <import-script>/opt/mediatomb/etc/mediatomb/py/import.py</import-script>
          </virtual-layout>
    

    Error messages and config stuff is there as well but to be clear, I'm building with

    % autoreconf
    % ./configure --enable-scripting=python
    

    on a Debian/Ubuntu hosts witch I've installed the build dependency packages and python-dev.

    if people can get it building, I'll move on to the runtime API.

     
1 2 3 > >> (Page 1 of 3)