Python and MythTV (a MythTV Front-End)

  Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Post Reply
madtw Offline
Senior Member
Posts: 174
Joined: Mar 2004
Reputation: 0
Post: #1
i recently setup mythtv and am waiting for my pvr-250 tv tuner card to arrive. while i wait, i have setup the xbox version of mythtv that runs linux but was a bit disappointed. it takes a long time to boot up and a lot of the features are already handled by xbmc (e.g. weather, games, music, videos, dvd). the only additional feature that i currently want to use is the ability to view recorded tv shows, program recordings, delete recordings, look at tv schedule. as a result, i started playing with the python interpreter in xbmc.

after writing some scripts, i have a few questions. i'm new to python (just learned it on the weekend) so if the language supports something natively, i might not have discovered this yet so go easy on me.

1. does the xbmc version of python provide hooks to access smb shares natively? i found a pure python implementation of the smb client side protocol and have been able to get that working nicely but i was just wondering if there already exists a way to do this? i know that xbmc.player() can access files over smb shares if the "url" is constructed properly but i haven't found a way to do this using, for example, nt.listdir(dir).

2. xbmc obviously parses xml. is this exposed anywhere in the python interpreter? in order to bootstrap to the mysql database, i need a place to store the hostname, database name, user, and password. i was thinking of adding this to my xboxmediacenter.xml file. if there was a way for python scripts to get access to the parsed config file or to call the xml parser on a file, that would be handy.

3. does anyone know of a pure python mysql client interface module? in order to learn python, i wrote a python module that supports connecting and authenticating to mysql over a socket, select, insert, update, and deleting of rows in the database, creating and dropping databases. it does what i need it to do and i'm willing to contribute this to the project... but i'd like to add some more documentation to it and use it in a useful script so that i can make sure i'm happy with the api. if there already exists such a beast, then there's no point in me working any further on it.

4. i ran into a weird problem with the following code:

Quote:import xbmc

filename = "smb://banshee/videos/foobar.avi"
xbmc.player().play(filename)

the avi starts to play as expected but when i hit stop on the xbox remote, the screen goes black and the xbmc interface never comes back. i haven't waited to see what happens when the entire avi finishes. i am using the march 9, 2004 build... is this a known problem? if you replace the avi file with a mp3 file, it seems to work fine. any ideas?

5. someone mentioned in the forum about having buttons bound to python scripts... it would be fantastic if a user could add a button to the main xbmc menu (e.g. mythtv) that launches a python script. at the moment, the only way i could launch my scripts is to go into the settings ->scripts screen and pick the name of my script. i tried creating a shortcut to the python script so that i could pick the shortcut under programs but this did not work. i tried placing my python script in an apps folder but it didn't work either. is there any other way to launch a python script other than through the settings screen?

keep up the great work on the python interface! the possibilities are endless...
find quote
darkie Offline
Team-XBMC Developer
Posts: 529
Joined: Sep 2003
Reputation: 0
Post: #2
Quote:1. does the xbmc version of python provide hooks to access smb shares natively?  i found a pure python implementation of the smb client side protocol and have been able to get that working nicely but i was just wondering if there already exists a way to do this?  i know that xbmc.player() can access files over smb shares if the "url" is constructed properly but i haven't found a way to do this using, for example, nt.listdir(dir).
no, this is not possible.
Quote:2. xbmc obviously parses xml.  is this exposed anywhere in the python interpreter?  in order to bootstrap to the mysql database, i need a place to store the hostname, database name, user, and password.  i was thinking of adding this to my xboxmediacenter.xml file.  if there was a way for python scripts to get access to the parsed config file or to call the xml parser on a file, that would be handy.
python has some xml parser modules in it's library but i haven't add those yet to python for xbmc (just forgot to add it, but will do it soon).
if you read some documentation on http://www.python.org you will see that there is support for xml files.
Quote:3. does anyone know of a pure python mysql client interface module?  in order to learn python, i wrote a python module that supports connecting and authenticating to mysql over a socket, select, insert, update, and deleting of rows in the database, creating and dropping databases.  it does what i need it to do and i'm willing to contribute this to the project... but i'd like to add some more documentation to it and use it in a useful script so that i can make sure i'm happy with the api.  if there already exists such a beast, then there's no point in me working any further on it.
there is a pure mysql python client but it is only available as a python dll module. and if there is only one big problem left for python it is loading dll modules and especially if they are not compiled for the xbox. so currently not possible.
and if you want to share what you already have, please. i think a lot of other user find this usefull.
Quote:the avi starts to play as expected but when i hit stop on the xbox remote, the screen goes black and the xbmc interface never comes back.  i haven't waited to see what happens when the entire avi finishes.  i am using the march 9, 2004 build... is this a known problem?  if you replace the avi file with a mp3 file, it seems to work fine.  any ideas?
fixed in current cvs
Quote:5. someone mentioned in the forum about having buttons bound to python scripts... it would be fantastic if a user could add a button to the main xbmc menu (e.g. mythtv) that launches a python script.  at the moment, the only way i could launch my scripts is to go into the settings ->scripts screen and pick the name of my script.  i tried creating a shortcut to the python script so that i could pick the shortcut under programs but this did not work.  i tried placing my python script in an apps folder but it didn't work either.  is there any other way to launch a python script other than through the settings screen?
binding scripts to buttons is possible. have a look at cvs/skinning.txt. somewhere at the end of the document there is this
Quote:button control:

 <control>
...
...
<script>q:\scripts\update_tvguide.py</script>
 </control>

Always read the XBMC online-manual, FAQ and search the forum before posting.
Do not e-mail XBMC-Team members directly asking for support. Read/follow the forum rules.
For troubleshooting and bug reporting please make sure you read this first.


[Image: badge.gif]
find quote
stickman Offline
Junior Member
Posts: 34
Joined: Mar 2004
Reputation: 0
Post: #3
i've been thinking about this for some time. recently i suggested adding mythtv frontend support as a feature, but maybe it will be possible to implement at least the main features through python.

i assume you already might know this, or maybe there's even better documentation, but i'll link it anyway.

as soon as you have some working code i'll beta test it for you and i'll try to help to improve it Smile
find quote
madtw Offline
Senior Member
Posts: 174
Joined: Mar 2004
Reputation: 0
Post: #4
thanks darkie for the quick reply and the info.

stickman thanks for the info. at the moment, i'm focusing on getting access to the mythtv information in the database without using the mythtv protocol. the main driver for this is so that i can watch recorded shows without firing up the full blown linux mythtv frontend on the xbox. also, i'd like to be able to view tv listings on the xbox and since mythtv has it all in the database already, i might as well grab it from there instead of hitting zap2it again.

eventually, i'd like to get scheduling, etc. working... so at some point i'll have to delve into the protocol.

anyway, for those interested, here is a tar file containing the mysql python module that i wrote... it also includes the pysmb modules for accessing smb/cifs remote file systems.
find quote
alx5962 Offline
Senior Member
Posts: 174
Joined: Jan 2004
Reputation: 0
Location: Lille, FRANCE
Post: #5
as i said in another topic, i managed to read the listing.xml created by xmltv but there's a bug in thecurrent version of¨xbox python that prevents it to work. but darkie said he will fixes this soon.
find quote
Hullebulle Offline
Posting Freak
Posts: 1,901
Joined: Sep 2003
Reputation: 0
Post: #6
(alx5962 @ mar. 24 2004,13:01 Wrote:as i said in another topic, i managed to read the listing.xml created by xmltv but there's a bug in thecurrent version of¨xbox python that prevents it to work. but darkie said he will fixes this soon.
i think it is ficxed already.

cvs-note:
24-03-04 added: pyexpat module to python, should fix all those (pyhon) xml problems

read the xbmc online-manual, faq and search the forums before posting! do not e-mail the xbmc-team asking for support!
read/follow the forum rules! note! team-xbmc never have and never will host or distribute ms-xdk binaries/executables!
find quote
jswu Offline
Junior Member
Posts: 20
Joined: Mar 2004
Reputation: 0
Post: #7
i think this is great idea. thank you for doing this.

i can help test the scripts for you but i only have the xbmc build from 3/9/2004.
find quote
madtw Offline
Senior Member
Posts: 174
Joined: Mar 2004
Reputation: 0
Post: #8
Quote:i can help test the scripts for you but i only have the xbmc build from 3/9/2004.

i wasn't sure by your comment if you meant the xml stuff or if you meant the mythtv stuff. if you want to test the mythtv stuff, i started on the 3/9/2004 build and i think it is fine or at least as good as the 3/16/2004 build. i switched to the unofficial 3/16/2004 build hoping that it would include the stuff that darkie added but it didn't.

oh well... patience. Smile
find quote
jswu Offline
Junior Member
Posts: 20
Joined: Mar 2004
Reputation: 0
Post: #9
Quote:i wasn't sure by your comment if you meant the xml stuff or if you meant the mythtv stuff.  if you want to test the mythtv stuff, i started on the 3/9/2004 build
i meant the mythtv stuff. i downloaded the 0.2 xbmc-mythtv files from your site, and was able to get everything running. i needed to install the python.rar files. i also needed to include the username/password for the tv recording folder on my mythtv box in the mytv.xml smb setting.

excellent work! it was able to query the mysql db and get a list of recorded tv programs and access the tv program share when i selected a program. but a couple issues:
1. when you select a program, it starts playing (you can hear the audio) but it does not display the video. you have to press x or display to see the video playing.
2. when i press stop or reach the end of the video, the whole thing freezes and the screen goes black. i can't get back to xbmc or play the tv program anymore.
find quote
madtw Offline
Senior Member
Posts: 174
Joined: Mar 2004
Reputation: 0
Post: #10
Quote:1. when you select a program, it starts playing (you can hear the audio) but it does not display the video. you have to press x or display to see the video playing.

yeah, i've noticed that too... there isn't much that i can do about it in the script as far as i can tell (maybe someone can correct me if i'm wrong). i think it is an xbmc issue in that it sets focus to the python script window instead of the player screen even though the python window was closed in the code. it might also be related to the window close issue i posted about earlier... where the window seems to get events even after a close. darkie any ideas on what i can do in the python code to fix this?

Quote:2. when i press stop or reach the end of the video, the whole thing freezes and the screen goes black. i can't get back to xbmc or play the tv program anymore.

this is a known issue with python. darkie said that it has been fixed in cvs but we need to get a new build of the python library to fix the problem. hopefully someone will do that soon...
find quote
BHeremans Offline
Junior Member
Posts: 5
Joined: Mar 2004
Reputation: 0
Post: #11
take a look at the python script at this page : http://www.visi.com/~erl/
find quote
madtw Offline
Senior Member
Posts: 174
Joined: Mar 2004
Reputation: 0
Post: #12
Quote:1. when you select a program, it starts playing (you can hear the audio) but it does not display the video. you have to press x or display to see the video playing.

2. when i press stop or reach the end of the video, the whole thing freezes and the screen goes black. i can't get back to xbmc or play the tv program anymore.

looks like the latest build resolved these problems! thanks darkie and whoever else fixed those issues. i haven't had a chance to try the virtual keyboard yet... but i'll get back to it this weekend.

i haven't made much progress over the last couple of days because i was busy getting the tuner card working in linux 2.6.4. everything is working great now so i'll get back to python scripting.

bheremans: thanks for the link... that comes in handy for learning the mythtv protocol.
find quote
madtw Offline
Senior Member
Posts: 174
Joined: Mar 2004
Reputation: 0
Post: #13
fyi... here is a new pre-release version of the mythtv frontend for xbmc. this version includes a gui settings screen as well as mythtv recorded show playback. any issues/comments are welcome.
find quote
jswu Offline
Junior Member
Posts: 20
Joined: Mar 2004
Reputation: 0
Post: #14
just gave it a try. everything is working and looking great! good job!

i have been using xbmc-mythtv to view my mythtv recordings and then using the mythtv web interface to schedule and delete my recordings. thanks!
find quote
madtw Offline
Senior Member
Posts: 174
Joined: Mar 2004
Reputation: 0
Post: #15
jswu: cool... i think i'll add the ability to delete recordings soon as well. i've been finding myself using the web interface to delete stuff but it would be handy to be able to do it from the xbmc after watching the show. Smile
find quote
Post Reply