How to convert Py2 to Py3 ( enigma2 Plugins)

There are 16 replies in this Thread which was already clicked 1,629 times. The last Post () by frankviana.

  • We need your help

    We can`t edit other peoples plugins without their consent.

    Contact the author and ask them to help.

    Some designers and programmers have not been active for a long time and someone should update these plugins.

    I have to agree with this said Because I see many Plugins from old python2 are not working as a plugin in python3,

    The One Plugin which was really nice to use was the MovieJukebox Plugin creator AliAbdul.

    He was on the Ihad forum & Lt forum many years ago and I have not see him since 2010-2012 so that is a fair point to say if there a very Clever Guy that can update this Plugin > Moviejukebox by AliAbdul then it would be really nice to see it is working in Python3 guys..


    I can give the rar file of the Moviejukebox rar file if any one that know the way to convert it would be nice to see.


    regards Talks.


    Rar File > MovieJukebox.rar

    Edited once, last by Talks ().

  • Talks other than a print statement not in brackets I dont think there is much wrong with that plugin.

    I think its still an old hd skin though.


    here is a cleaned version of plugin.py from that .rar file you have attached

    I haven't tested this on my box, I just run it through my linting software. So its as clean as it can be.


    A base for someone else to get working if its still not working probably. I am too busy to test properly

    Well it runs now anyway. Don't know what its meant to do or what its meant to look like. But the plugin opens :)
    I don't have any recordings. So I just quickly recorded bbc 1

    pasted-from-clipboard.png

  • ** A person who feels appreciated will always do more than what is expected **

  • basically I use a software called Geany as my python editor.
    I have python 3 installed on my computer

    I have a linting package installed in Geany.
    I fix all the linting errors. Which will fix a lot of python 3 errors.

    Then I will load the plugin onto box, try everything and see what crashes. Then google for the answers. Which will normally direct you to a similar question on stackoverflow.

    The rest just comes through experience of what works in python 2 and python 3. I code to work in both though. So I use conditionals.
    Its always the same errors over and over again.
    Usually different library or module calls that might have changed between versions.

    But generally all print statements need to be in brackets. print("BLAHBLAH"). This is often the major culprit. All old plugins would have wrote print "BLAHBLAH"

    python 3 handles strings differently. So might need wrapping in a str() or sometimes a .decode() or .encode() is required.
    This is the most confusing aspect. python 3 is bytes for everything. python 2 classes everything as a string. It doesn't care.

    here are some conditionals I have in my various plugins. Which highlights some changes needed to run in both.


    Code
    import sys
    
    pythonVer = 2
    if sys.version_info.major == 3:
        pythonVer = 3
    Python
    if pythonVer == 2:
        from urllib2 import urlopen, Request
    else:
        from urllib.request import urlopen, Request
    
    
    if pythonVer == 2:
        from urllib import quote
    else:
        from urllib.parse import quote


    from a file load

    Code
                        for line in lines:
                            if pythonVer == 3:
                                line = line.decode()


    from a url response

    Code
        for line in response:
            if pythonVer == 3:
                try:
                    line = line.decode("utf-8")
                except:
                    pass


    timestamp example

    Code
                if pythonVer == 2:
                    glob.pintime = int(time.mktime(datetime.now().timetuple()))
                else:
                    glob.pintime = int(datetime.timestamp(datetime.now()))


    simple byte to string conversion

    Code
            if pythonVer == 3:
                data = str(data)


    Basically all the above will pretty much get most plugins working
    Make sure the library calls are correct
    Make sure all print statements are in brackets.
    Make sure strings are specifically converted to strings. If a string is required.

    It is not always that simple. But most plugins are not really over complicated. They might read a file. They might download from a url. Display a few results.

    ** A person who feels appreciated will always do more than what is expected **

  • A few more things to look out for


    Code
    try:
     
        trying_to_check_error
     
    except NameError, err:
     
        print err, 'Error Caused'   # Would not work in Python 3.x


    is wrong as it now needs an "as"

    Code
    try:
     
        trying_to_check_error
     
    except NameError as err:
     
        print(err, 'Error Caused')  


    Division calculations.

    either use


    Python
    from __future__ import division
    print(7 / 5)

    or use double slash for all division calculations. Otherwise you will get a rounded integer result rather than a float (decimal).



    Code
    print(7 // 5)

    ** A person who feels appreciated will always do more than what is expected **

  • First Thing is Thank You very much KiddaC,


    I have downloaded your Plugin PY above and if i have got your message right then all i need to do is replace the one in the rar file and then run it Moviejukebox,


    Kind regards Talks.

  • Update for KiddaC.


    I have installed the Moviejukebox with the new python py that you have kindly given & it is now working 100% with all my Movies which I have in the Hard Drive of my VU+ 4K HD uno.


    Thank You KiddaC.


    Regards Talks.

  • I'm looking for a way to convert this plugin.


    If someone can help, I will be very grateful.


    The result of the plugin is this (canais.xml attach)


    Thx

    Files

    Dream Two, h9sSE/h9s/h9 twin, sf8008/sx88/sx88+, Osmini4k, Gt-Media v8UHD/GTC/v9prime/v8xs/m7x/finder2, Amiko SHD 8900, Vu Zero/Zero 4K, Mecool K1/K2/K3, Azamerica s2015, Nazabox Xgame, Koqit K1 mini, TBS 5520se/5925/6922se/6903x, Openbox X5/S9, AZBOX TITAN twin/Premium+/Elite, Rasp Pi/pi3/pi4, t95 max+, Freesky Triplo X, Orange Pi PC, Coolsat 5000, Dm528s, DM800se, Satlink 6933/6960/6932, Mygica S270, Pixelview PlayTV . Motorized 5m - C band(20ºE - 116.8ºW), Motorized 1,80m - KU band

    Edited 3 times, last by frankviana ().

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!