James' Tech Blog

Tag: hackery

How to update Mythvideo file titles

by on Sep.13, 2010, under Uncategorized

The title of the post is a little confusing, I’ll admit that straight away. Here is the problem. I had a bunch of series AVI files name as such: 101.avi 102.avi 103.avi … ad nauseum. This was great, but episode titles make it easier to pick out which one I really want to watch. Especially when I’m using UPNP. So I renamed all my files to be like 101.Rose.avi. Great, super easy to tell what the episode is about!

Good thing mythtv is smart and made hashes of all the files. Now it knows that 101.Rose.avi might as well be 101.avi. Awesome! If I had trailers, poster-art, and other metadata it would be right there with the files with new names. Unfortunately, what it didn’t change was the title. So when I look at my videos in mythfrontend 101.Rose.avi is called 101. The titles didn’t update. Well, this is good behavior. If we’re going to track which file is which by hashes, then we don’t want to change the title just because the filename changed (or path I’m presuming).

This is not the behavior I wanted though. I searched a little bit, but couldn’t find anything. I did find out the structure of videometadata though. That gave me the clue to just write a script to update the titles based on the filenames. Here we go, in glorious PHP:


//replace master_IP with your MySQL IP address and password with whatever your password is
$con = mysql_connect("master_IP","mythtv","password");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("mythconverg", $con);
//if you want all the files the next line is good. Otherwise see line after that
$myquery = "SELECT intid,title,filename FROM videometadata";
//I did it for a subset of files which is why I used LIKE to match part of the path in the filename field
//$myquery = "SELECT intid,title,filename FROM videometadata WHERE filename ". 'LIKE "%who%"';
$myquery_rows = mysql_query($myquery);
while ($myrow = mysql_fetch_array($myquery_rows)) {
//update query
$new_title = substr(basename($myrow['filename']), 0, strrpos(basename($myrow['filename']), '.'));
$up_query = "UPDATE videometadata SET title = '" . $new_title . "' WHERE intid = '" . $myrow['intid'] . "'";
print $up_query;
//mysql_query($up_query); //uncomment this after you're satisfied with the output
}
mysql_close($con);

To protect the innocent I have it just print what it would change the titles to. All you have to do is uncomment the mysql_query line. Sorry the code plugin I have squashed my tabs. Not a deal breaker, but it would be easier to read. Also, the code plugin doesn’t like php tags you’ll have to add them. The next script is probably the one you want to run first. It just prints the intid, title, and filename (which in my case included path) for each file. This is handy to see if the filenames/titles match. Also, to see if your update went well.


$con = mysql_connect("master_IP","mythtv","password");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
mysql_select_db("mythconverg", $con);

//if you want all the files the next line is good. Otherwise see line after that
$myquery = "SELECT intid,title,filename FROM videometadata";
//I did it for a subset of files which is why I used LIKE to match part of the path in the filename field
//$myquery = "SELECT intid,title,filename FROM videometadata WHERE filename ". 'LIKE "%who%"';
$myquery_rows = mysql_query($myquery);
while ($myrow = mysql_fetch_array($myquery_rows)) {
  print $myrow['intid'] . " | " . $myrow['title'] . " | " . $myrow['filename'] ."\n";
  }
mysql_close($con);

Please don’t go running amok in your database and blame me for it getting screwed. Use mysqldump before running the update script. Although it should be pretty innocuous because you can always use mythfrontend to rebuild the videometadata database. Though you would lose any metadata you had input for your files. Happy hunting! Maybe I’ll port this to a proper scripting language like PERL or python. Or maybe someone’s nice enough to do it for the rest of us???

Leave a Comment :, more...

Western Digital Elements

by on Jul.11, 2010, under Uncategorized

So I bought a Western Digital Elements 1TB drive last week. For some reason it’s a mystery what’s inside these devices. I decided to disassemble, open up, take apart, dismantle, autopsy or whatever you call it so that I can document what’s inside. Mine which has the model number “wdbaau001hbk-01” on the bottom has a “wd10ears-00y5b1” drive in it, WD Caviar Green SATA/64MB cache 5400RPM. I think it’s a pretty enclosure, but not at all necessary. I apologize, I can’t find where I found instructions to open it. It’s pretty straight forward. Use a knife or something with a good edge to pry it open a little. Then I used a guitar pick to go around the edge and pry the clips along the inside. I’m going to do some crazy stuff to it, more to come. Maybe some pictures!

1 Comment : more...

iNoPhone Update

by on Feb.28, 2010, under iNoPhone

So I decided to get smaller buttons for my iNoPhone. I had to unsolder the old buttons which wasn’t hard. The new buttons are smaller in diameter so it was harder to get them secured to the plastic face. There’s a blurry Katrina in the background.

Small buttons

I tested all the buttons and they seem to work. It’s a lot lower profile. If you lay it like it originally would be it looks almost like a regular mouse. I almost got some really small tactile switches, but I thought they might be too short.

Fashion Show

The latest fashions!

Fashion Show

It’s almost the same size as my HTC Hero.

Katrina phone

A comparison with Katrina, she’s a pretty big cat though!

Other updates on first post:

Charging works, I’ve done it a couple times now. The speaker/mic aren’t the best, but I think I just need more holes in the face plate.

Leave a Comment :, more...

Shell and PHP script for dynamic IP address

by on Dec.05, 2009, under Remote Admin

This is the second post in the series “Remote admin your mama’s gentoo boxen” This post I will be going over how I am going to handle the “dynamic” IP address on the WAN of my router. I say “dynamic” because I’m not really sure how dynamic it is. It’s likely only dynamic in the way that Comcast could give it to someone else (like if they wanted to pay for it) and there’s nothing I could do about it (unless I told them I would pay more for it!).

You probably just said to yourself, “DyDNS! Don’t they have services for that already?” The answer is yeah, they do, if you want your router to have a URL and probably be poked at more. Oh and dydns has sent me emails before about my IP not being “dynamic enough” and that I should “use static registration!” Besides, this way I can encrypt my IP not only when I update it, but when the client retrieves it. Not to mention client authentication.

Here is the scheme:

Router runs ash script reporting IP to remote server

Server does it’s thing and records IP

Client runs bash script getting IP from remote server

From there the client knows the router IP and can connect with reverse SSH.

Here comes some code. I would have prefered to write this in PERL but my router doesn’t have PERL! Also, less dependencies on client. Everyone has a shell. I decided to send the IP as hexadecimal without separators. As I’m not really proficient at shell scripts I looked up how to convert IP’s to hex: http://blog.mecworks.com/articles/2007/07/05/bash-scripting-tip-convert-ip-address-to-hex/ I did some fun stuff for the client. It probably looks horrible, but it should work.

First up is the router script:


#!/bin/sh
SUCCESS=1
while [ $SUCCESS -eq "1" ]
do
RTR_IP=`ifconfig eth0.1 | awk -F "[: ]+" 'NR==2 {print $4}'`
UPDATE_IP=`printf '%02X' ${RTR_IP//./ }; echo`
SUCCESS=`wget -q -O - "http://www.ultravstudios.com/myphpscript.php?update=$UPDATE_IP"`
sleep 5
done

I’ll break it down for y’all. It loops until it works. We use ifconfig to get the IP of WAN (eth0.1), use printf to turn it into 8 character hexadecimal, send it to the special secret PHP page. The PHP page will return a value 0 on success 1 on error. Next is client side


#!/bin/bash
GET_IP=`wget -q -O - "http://www.ultravstudios.com/myphpscript.php?get=0"`
K=`printf "%d". "0x"${GET_IP:0:2} "0x"${GET_IP:2:2} "0x"${GET_IP:4:2} "0x"${GET_IP:6:2}`
RTR_IP=$(echo ${K%\.})

So this one’s really easy.  Get the value from the special secret PHP page. Turn it back to decimal with period separators. Chop the last period off. Okay, so that’s just the part to retrieve the IP. Next is my PHP code for the remote server. It seems like WordPress doesn’t like me adding php tags?!


$filename = "supersecretfilename";
//open file and get old ip
$file = fopen($filename, 'r');
$old_ip = fgets($file);
if ($_REQUEST['get'] == "0") {//the client does want the ip
print $old_ip;
fclose($file);
return;
}
//so the rest means that the client does not want ip
if (is_null($_REQUEST['update']) || $_REQUEST['update'] == "") {//there is not data
fclose($file);
print "1"; //tell client there was error
}
elseif ($_REQUEST['update'] == $old_ip) {
//there was no update close file and return
fclose($file);
print "0";
return;
}
else {//ip is new
fclose($file);
$file2 = fopen($filename, 'w');
fwrite($file2, $_REQUEST['update']);
fclose($file2);
print "0";
}

Apparently I comment my php code more than my bash! So it’s pretty dumb right now. There is no authentication, no encryption, very few fail-safes. If my router is somehow having problems updating the IP, like the script doesn’t work, it will try forever until it works. I assure you, this is just the beginning, a quick hack to get things rolling.

Leave a Comment :, , , , more...

iNoPhone2

by on Nov.27, 2009, under iNoPhone

My wonderful cat Perry decided to chew up a bluetooth headset (Jabra BT5020). I’ve seen before the iNoPhone which is totally awesome! I decided to rip it all the way apart and make my own iNoPhone from a spare Apple mouse that I had.

iNoPhone2

It wasn’t too hard after I figured out what wire to use. At first I tried 22 or 24 gauge wire. It worked, but the wires were stiff and it was hard to solder onto the tiny switches. Also, I pulled a trace off so I decided that it wasn’t going to work. I previously cut up an IDE cable to wire an SD card in my WRT54GL. There was plenty of spare ribbon to go into this project as well.

iNoPhone2

On top of pulling a trace off, I broke the wire for the mic. One problem with the design of the iNoPhone was charging. So I used a headphone jack and drilled out the normal cable hole to accommodate. This was awesome till I pulled the single trace I had found that went to the +5V on the USB. After a lot more searching I gave up cause the 22 gauge wire was too big to solder to the tiny _8_ pins for the USB on the board.

Close-up

In comes the IDE ribbon cable. Definitely small enough to solder to the USB pin and alot easier to solder to the pins of the switches. Now I was having problems with the mic. I just couldn’t get it soldered well. I needed a couple more hands, but I didn’t have them so I did the next best. I pulled out the mic from an old “desktop mic” I had around. Plenty of room to solder!

As above I wired in a headphone jack to charge the unit. Then I cut the end off a USB cable and soldered a male stereo plug on. Now if I only had smaller buttons it would look pretty awesome.

Charging jack

I haven’t been able to verify that charging works. The LED is not the right color when it’s supposed to be charging. I did get my multimeter out and checked the voltage on the battery, 3.86V without charger, 3.96V with charger. So, I think it works.

I will close with thanks to Mark from geektechnique.org I probably would have never thought of this without first seeing his iNoPhone.

I never knew you, but R.I.P. Mark

Leave a Comment :, more...

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!

Blogroll

A few highly recommended websites...