I have 2 tasks, but can they be handled with Add-Ons?
#1
Hello everyone!

I don't have any python skills yet, but I know other programming languages and have CompSci degree. Smile So I hope I've got the basics of programming covered. I've looked over the various wiki pages concerning add on development. From what I've gathered I'm unsure whether it is actually possible to do, what I need to do. Here are the two tasks:

1) Send Wake-On-LAN-Message (possibly by executing etherwake) when ever an NFS-Share is accessed.
2) Rewrite certain URLs, when they are accessed.

Why I need to do that:

1) My NAS is in sleep most of the day to reduce power consumption. Right now both, my girlfriend and me, use an android app to wake the file server beforen playing a movie. However, sometimes she just forgets to start it xbmc can't access the files. From the logs I can tell that xbmc generates a log message when it initializes or shuts down NFS connections. I could write a shell script to monitor the log, but since some of my client computers use windows and some linux I'm afraid that a truly portable solution will be hard to come up with. Is there a way to monitor for NFS connection attempts from a python add on?

2) I'm using MediaElch as my Media Manager to scrape all metadata and write them to nfo-files. xbmc just scrapes these local files and stores everything into a shared mysql database. Links to movie trailers are actual links to the corresponding Youtube page. These links don't automatically trigger the Youtube plugin and xbmc fails to play the trailers. I'd like to have python script to rewrite the Youtube URLs when they are accessed into working plugin-urls (e.g. plugin://plugin.video.youtube/?action=play_video&videoid=sFXGrTng0gQ). Is it possible to rewrite URLs from a python add on?

Any pointers would be greatly appreciated. If someone could tell me that this is indeed possible and what functions/classes/keywords I should look up, I'd be happy to google for them myself. Smile
Reply
#2
For your first, take a look here
Reply
#3
(2013-05-17, 13:30)ConfusedTA Wrote: For your first, take a look here

Thank you very much. This would indeed solve my problem, but it seems it not available on xbmc 12.2. (quote from the linked thread: "The patch has been merged and should become available from XBMC 13 (Gotham) Alpha 4 (May 2013)")

I'd like to stay away from xbmc 13 until it has become the current and stable release.
Reply
#4
http://forum.xbmc.org/showthread.php?tid...pid1418659

Someone's compiled this in with 12.2 final
Reply
#5
For #1, I'm pretty much certain that their is an addon for sending magic packets already written here somewhere

For #2, I just had to do something similar in an addon. I had to change the format of some files I was writing periodically, so I had to go back and update all the files that had been written previously. This is what I used:
Code:
import os

def fix_existing_files(start_folder):
    start_folder = xbmc.translatePath(start_folder)
    for root, dirs, files in os.walk(start_folder):
        for current_file in files:
            if current_file.endswith('.strm'):
                print "processing file: %s" %current_file)
                full_path = os.path.join(root, current_file)
                with open(full_path, 'r+') as target:
                    content = target.read()
                    target.seek(0)
                    new_content = content.replace('old_text', 'new_text')
                    if not 'some_text' in new_content:
                        new_content += '&video_type=episode'
                    print 'Writing new content: %s' %new_content)
                    target.write(new_content)
Reply
#6
(2013-05-17, 13:48)ConfusedTA Wrote: http://forum.xbmc.org/showthread.php?tid...pid1418659

Someone's compiled this in with 12.2 final

Thanks again for helping me. Unfortunately I need several different builds (linux-amd64, win-x86, android and raspberry pi) and I'd like to keep the setup as simple as possible. So hunting down custom builds for all these platforms every time there's an update is not really an option for me (read: I'm waaaaay to lazy). That's why I wanted to write a small custom add on...


(2013-05-17, 16:58)Bstrdsmkr Wrote: For #1, I'm pretty much certain that their is an addon for sending magic packets already written here somewhere

For #2, I just had to do something similar in an addon. I had to change the format of some files I was writing periodically, so I had to go back and update all the files that had been written previously. This is what I used:
Code:
import os

def fix_existing_files(start_folder):
    start_folder = xbmc.translatePath(start_folder)
    for root, dirs, files in os.walk(start_folder):
        for current_file in files:
            if current_file.endswith('.strm'):
                print "processing file: %s" %current_file)
                full_path = os.path.join(root, current_file)
                with open(full_path, 'r+') as target:
                    content = target.read()
                    target.seek(0)
                    new_content = content.replace('old_text', 'new_text')
                    if not 'some_text' in new_content:
                        new_content += '&video_type=episode'
                    print 'Writing new content: %s' %new_content)
                    target.write(new_content)

Yes, I know there's an advanced WOL add on, but it doesn't really fit my requirements (i.e. my lazyness).
Also thanks for posting your code. From reading it (and I never used python before) it seems that you're iterating over existing files and replace their content. I'd rather not permanently change the youtube URLs, but rewrite them on the fly, when ever they are being accessed through xbmc. Otherwise I'd have written a cron job to periodically run UPDATEs on the mysql database.
Reply
#7
In that case, it's theoretically possible, but will trip the lazy trigger pretty early. You'd need to write a transparent proxy and reinvent the youtube-addon wheel.

You can use os.popen() to run shell commands (although it's just as easy to create and send the packet in python). You can't directly monitor for connection attempts, but you could use a service addon to monitor the log file from within python. Since the connection attempt has already begun by the time you catch it that way, you'll need to turn up the curl timeout in advancedsettings.xml though
Reply
#8
you could send the wol magic packet with this.

Code:
import socket
import struct
server_macaddress = "AA:BB:CC:DD:EE:FF"
addr_byte = server_macaddress.split(':')
hw_addr = struct.pack(
    'BBBBBB',
    int(addr_byte[0], 16),
    int(addr_byte[1], 16),
    int(addr_byte[2], 16),
    int(addr_byte[3], 16),
    int(addr_byte[4], 16),
    int(addr_byte[5], 16)
)

msg = '\xff' * 6 + hw_addr * 16
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
s.sendto(msg, ("255.255.255.255", 9))
Image
Reply

Logout Mark Read Team Forum Stats Members Help
I have 2 tasks, but can they be handled with Add-Ons?0