The Paul's Tech MythTV Project: Phase 5
OK, as promised in Phase 4, here are a few customizations you may wish to add to your MythTV box. Most of these are relatively simple, and if you have gotten this far in setting up your MythTV box, there should be nothing here you can't handle.
The first addition I made to my machine was to add a way to check the system temperatures and voltages from within the MythTV GUI. The simplest way to do so, that I have found, is to make a webpage that can be opened in the MythTV web browser. You will need the Mythbrowser add-on in order to use this.
If you recall, in Phase 3, I mentioned installing lm-sensors. Assuming you did that, you can get a listing of the voltages and temperatures with the sensors command. This works great from the command line, but needs help for use in the MythTV GUI. Fortunately, we can use scripting to make it easy. I chose to use php for my version of this webpage, but if you like perl or something else better, it is easy to change. Here is the webpage in its entirety.

Yes, that is all you need. What you have is this: The first line indicates to the webserver that this is a php script. The last line closes the script. The two lines that begin with echo send the pre tags to the browser. This just makes the output prettier. The meat of the code is the system command. This command sends the command in the parentheses to the command line, and captures the output. When run, all of the output you get from the sensors command will be caught and sent to the web browser. Simply save the above text in a .php file (I used temperature.php) in your webserver webpage directory. For me, that is in the /var/www directory.
Now, in the MythTV GUI, go into the Info Center Settings, Web Settings, and create a New Bookmark. Name it whatever works for you (I used CPU Temperature), and for the URL, use http://localhost/temperature.php. Once that's done, you can go into Information Center and Web sections, and if you select the CPU Temperature bookmark, your sensors output should appear as a webpage. Refreshing the page will get you updated output. Handy, eh!
If you are interested in tracking temperature or voltage over a period of hours or days, you could expand on this idea to do so. Let's say you wanted to track it once every day. What I would do is to set up a cron job to run the sensors command. To add regularly scheduled tasks, you will need to edit the crontab file in the /etc directory. Here is an example of what to add.
01 01 * * 00 root sensors 1>/var/www/temperature1.txt
What this says is, run the sensors command at 1:01am every Sunday, the output of which will be redirected to the temperature1.txt file in the webserver directory. You would then add 6 more similar commands for the other days of the week in seperate text files. You can then add new bookmarks for the new text files, and view them in the browser as well. If you are really handy with scripting, you may even want to make a script to read the 7 text files, strip out the pertinent information, and create an attractive webpage with graphs and everything.
The second addition I made had to do with my desire to have the machine automatically download some of my favorite video podcasts to my media directory. If you have MythStream installed, you may be happy with streaming podcasts to your TV, but I wanted them downloaded at night when my internet connection traffic was low or nil. I did this again with a relatively small php script.
Here is the script.

NOTE: I had to make a small change to the above script. The preg_match would fail if the url contained the letters AVI, for example, before the .AVI extension. The above line should now be as follows:
preg_match_all ("/http:+[^\s]+\.+".$fileext."+/", $data, $matches);
The script starts running at the $url=... line. The $url holds the location of the RSS feed of the video podcast in question. This example is for the DL.TV podcast. The extension line below that is the file type we are looking for. With both of those variables set, the script calls the download_videos function.
The download_videos function is where all the magic happens. The first line goes out and gets the RSS feed webpage, dumps it into an array, and then converts the array into one long string. The second line then searches that string for any sections that start with http:, and end with the $ext file type. All of the links found are stored in the $matches array. Those matches are then used in the 3rd and 4th lines to collect the actual mp4 files. The 3rd line calls the command 'wget' with the first matching link. 'Wget' is a program for retrieving files over the internet. The 4th line does the same with the second link found. It seemed that sometimes the first link didn't work, so I added the second one in just in case. If the first one works, the second attempt will not overwrite the first download. Most RSS feeds have the most recent podcast listed first, thus that is the one it will always grab.
The last thing I had to do once I had the script written was to create a cron job to run daily at night to execute the script, much like in the previous cron example. To run it, I just used the line 'php podcastgrabber.php'.
This is a bit of a quick and dirty script to perform the task, but it works well for me. I can check the Videos section of MythTV every day and see what new podcasts have shown up overnight. And, if I find another podcast I wish to download, I simply add 3 more lines to the script with the new RSS feed. Some shows may not have an RSS feed, but they probably have some webpage listing their most recent shows, and that will work in most cases.
So, these are a few customizations I have added to my machine that I find particularly useful. Feel free to use them on yours as well. This is the last major posting on the Paul's Tech MythTV Project, but as new features develop, I will likely be adding new articles now and then. Come back and check often.
Posted by PH on 09-28-2007 04:18:44 CST
The first addition I made to my machine was to add a way to check the system temperatures and voltages from within the MythTV GUI. The simplest way to do so, that I have found, is to make a webpage that can be opened in the MythTV web browser. You will need the Mythbrowser add-on in order to use this.
If you recall, in Phase 3, I mentioned installing lm-sensors. Assuming you did that, you can get a listing of the voltages and temperatures with the sensors command. This works great from the command line, but needs help for use in the MythTV GUI. Fortunately, we can use scripting to make it easy. I chose to use php for my version of this webpage, but if you like perl or something else better, it is easy to change. Here is the webpage in its entirety.

Yes, that is all you need. What you have is this: The first line indicates to the webserver that this is a php script. The last line closes the script. The two lines that begin with echo send the pre tags to the browser. This just makes the output prettier. The meat of the code is the system command. This command sends the command in the parentheses to the command line, and captures the output. When run, all of the output you get from the sensors command will be caught and sent to the web browser. Simply save the above text in a .php file (I used temperature.php) in your webserver webpage directory. For me, that is in the /var/www directory.
Now, in the MythTV GUI, go into the Info Center Settings, Web Settings, and create a New Bookmark. Name it whatever works for you (I used CPU Temperature), and for the URL, use http://localhost/temperature.php. Once that's done, you can go into Information Center and Web sections, and if you select the CPU Temperature bookmark, your sensors output should appear as a webpage. Refreshing the page will get you updated output. Handy, eh!
If you are interested in tracking temperature or voltage over a period of hours or days, you could expand on this idea to do so. Let's say you wanted to track it once every day. What I would do is to set up a cron job to run the sensors command. To add regularly scheduled tasks, you will need to edit the crontab file in the /etc directory. Here is an example of what to add.
01 01 * * 00 root sensors 1>/var/www/temperature1.txt
What this says is, run the sensors command at 1:01am every Sunday, the output of which will be redirected to the temperature1.txt file in the webserver directory. You would then add 6 more similar commands for the other days of the week in seperate text files. You can then add new bookmarks for the new text files, and view them in the browser as well. If you are really handy with scripting, you may even want to make a script to read the 7 text files, strip out the pertinent information, and create an attractive webpage with graphs and everything.
The second addition I made had to do with my desire to have the machine automatically download some of my favorite video podcasts to my media directory. If you have MythStream installed, you may be happy with streaming podcasts to your TV, but I wanted them downloaded at night when my internet connection traffic was low or nil. I did this again with a relatively small php script.
Here is the script.

NOTE: I had to make a small change to the above script. The preg_match would fail if the url contained the letters AVI, for example, before the .AVI extension. The above line should now be as follows:
preg_match_all ("/http:+[^\s]+\.+".$fileext."+/", $data, $matches);
The script starts running at the $url=... line. The $url holds the location of the RSS feed of the video podcast in question. This example is for the DL.TV podcast. The extension line below that is the file type we are looking for. With both of those variables set, the script calls the download_videos function.
The download_videos function is where all the magic happens. The first line goes out and gets the RSS feed webpage, dumps it into an array, and then converts the array into one long string. The second line then searches that string for any sections that start with http:, and end with the $ext file type. All of the links found are stored in the $matches array. Those matches are then used in the 3rd and 4th lines to collect the actual mp4 files. The 3rd line calls the command 'wget' with the first matching link. 'Wget' is a program for retrieving files over the internet. The 4th line does the same with the second link found. It seemed that sometimes the first link didn't work, so I added the second one in just in case. If the first one works, the second attempt will not overwrite the first download. Most RSS feeds have the most recent podcast listed first, thus that is the one it will always grab.
The last thing I had to do once I had the script written was to create a cron job to run daily at night to execute the script, much like in the previous cron example. To run it, I just used the line 'php podcastgrabber.php'.
This is a bit of a quick and dirty script to perform the task, but it works well for me. I can check the Videos section of MythTV every day and see what new podcasts have shown up overnight. And, if I find another podcast I wish to download, I simply add 3 more lines to the script with the new RSS feed. Some shows may not have an RSS feed, but they probably have some webpage listing their most recent shows, and that will work in most cases.
So, these are a few customizations I have added to my machine that I find particularly useful. Feel free to use them on yours as well. This is the last major posting on the Paul's Tech MythTV Project, but as new features develop, I will likely be adding new articles now and then. Come back and check often.
