MovieBox demo app on GitHub


Just a quick note, I have a project up on GitHub called MovieBox. This was based on keyStream by Cory Fail, but is built on top of the ColdBox framework. Right now it is in a holding pattern because I am going to rewrite it using AngularJS for the frontend and Taffy for the backend REST API. I have been wanting a good learning project for Angular, bower, gulpjs, et al so this will be my guinea pig..

This project does have some pretty good bits, it can scan a directory of movies and pull the metadata from themoviedb.org and update your library accordingly. You will need to specify the default location of your movie directory which is set in /config/Coldbox.cfc under custom settings. Currently the indexer does not run automatically, it must be forced by calling http://localhost/wtf/indexMovies. There is a SQL script for the database creation (mySQL format, but may work on others) to setup the database schema. It expects a data source named moviebox to be setup in the web/server administrator. Additionally, it is assumes the movies are stored as X:/movies/moviename or even better X:/movies/moviename (year).

All videos should be available to the web server under the /media directory. Assuming you are using Nginx as the front end proxy it is an easy as creating an alias in your site definition, but it should be easy enough to do in other servers.

If your server does not support SES URLs you must edit the /config/Routes.cfm and add “index.cfm” to the setBaseURL() line. Also, I would definitely recommend using the development branch as it is the most updated (and also contains the SQL script for database generation).

Aside from that, everything should work great. 🙂  The indexer will attempt to download the movie poster and backdrop and will copy the data into the movie folder as well as the data folder under the web root. If the data folder does not exist it will be created for you. If you have a lot of data, expect the initial look up to take a while. Subsequent scans will ignore titles that are already known.

You can check it out here: https://github.com/robertz/moviebox/tree/development

Advertisements

CommandBox is not just for ColdBox


A few weeks ago I think it was Ray who had posted something about CommandBox. I had heard about it before its release, but I totally missed it when it was unveiled at Into the Box.

I have to say it has quite a few features that I really love. Being able to completely setup a ColdBox application scaffold with just one command is great. The package management system is another awesome feature in and of itself; one that other languages have had a leg up on ColdFusion for a very long time.

One feature that might be easily overlooked (I certainly did) is the embedded server. I did play around with it initially then I promptly forgot all about it. Which brings me to today when I wanted to check out a project from github (Taffy, but that is another post), I wasn’t anywhere near my home machine and I really didn’t want to install Railo Express just to test something out. Turns out it wasn’t an issue, I just extracted all the files out to a directory, fired up CommandBox, typed “server start” and fired up a Railo server I could play around with without any additional configuration needed.

Incidentally, you can access the web/server administrator and it will retain your configuration data for that folder so your settings will persist which also is really awesome.

If you haven’t looked into CommandBox because you don’t use ColdBox it might be worth a look. I look forward to seeing where this project goes in the future. You can see the intro video here: http://www.ortussolutions.com/products/commandbox

themoviedb.org API and ColdFusion


Last week while hanging out in the #coldfusion IRC channel I came across a nifty new app called keyStream created by Cory Fail. In a nutshell, it is a ColdFusion application that allows you to stream your media to your devices while you are attached to your home network. This appeals to my tender sensibilities since I tend to watch movies online more than on a TV.

KeyStream is a great application, one thing that was missing for me was being able to hit an API to pull down movie metadata. If you have a lot of media files it is nice to have an automated way of scanning through a whole directory of files in one fell swoop ala XBMC or comparable media applications. With that in mind, I set to see how difficult it would be to interface with tmdb.org in ColdFusion and I found that it actually was not that difficult.

Here is the TMDBService object for ColdBox although it could easily be ported:

First step though is getting an API key. Cruise over to themoviedb.org and sign up for an API key. It is free so even us starving developers can afford it.

Doing a lookup basically requires two steps. First we will pass the movie name in as a string to the findMovie(name, year) function which goes to the APIs /search/movie endpoint. This will return a list of matches back from tmdb.org, if there is an exact match it will be pushed up to the top of the list. Assuming the first position is the movie we want it is time to go to the APIs /movie/{id} endpoint(getMovieData(id) function in the gist if you are following along), passing it the id we got in the first call. This is where we get all the fun stuff such as the poster and backdrop data, overview, release date and IMDB rating. If you would want to see it when viewing your media, this is where you would find it.

To speed the process up a little bit I created the scrape() method that fires these two calls in one swoop. It assumes it will always have an exact match in the movie title, things get a little hairy when there isn’t an exact match but this is still a work in progress.

 

The final step is to call the APIs /configuration endpoint if you are wanting to download the cover and background art. This data tells you where to look on their image server for the images since they are sorted out by size and then it is just a matter of making a cfhttp call out and downloading the images to your local server. Assuming there is enough interest I could provide a more detailed accounting of getting this done. The finished product could look something like this:

Nginx and locking down your WEB-INF folder


I was working on some URL rewriting rules on my server this evening when I was taking a break at work. Just out of curiosity I tried hitting some of the files that are available in the WEB-INF directory and was surprised to find out that I could easily view all my context logs and anything that was not a ColdFusion template. In retrospect, I should not have been surprised but I should have taken steps to prevent that from ever happening.

I have a drop.conf file that gets loaded on every site so blocking directory access on all my sites was just a matter of adding the directive to block access to the directory and restarting nginx.

In hindsight, I should have checked that a long time ago. Hopefully someone will learn from my mistake.

Adding ColdFusion tags to jEdit’s JTidy plugin


Lately I have been using jEdit almost exclusively as my editor of choice when coding. While one could argue that it lacks many features found in other editors such as Eclipse it more than makes up for with the many plugins you can install. One of those plugins is JTidy, a java implementation of HTML Tidy that comes in real handy for cleaning up malformed or faulty HTML.

Installation in jEdit is a breeze using the plugin manager so I quickly had it installed, but the one issue I quickly ran into was the fact that JTidy did not know how to handle CFML tags. After a lot of googling I found Ron Stewart’s config file for JTidy that has the CF tag rules:

http://www.we3geeks.org/files/tidy-cfml.config

Copy the tag names into the correct blocks in the JTidy area of jEdit’s plugin options and you should be in business. I managed to get everything configured this evening but I really have not had a chance to test it out.

Using PostFix to send emails using Amazon SES


Of all the Amazon Web Services I use,  the Simple Email Service would have to be the service I use the most. ColdFusion allows me to easily create a component that sends emails pragmatically but, however, it would be much nicer to use the CFMAIL tag and be done with it. As it turns out, Amazon SES allows you to send a raw email so you can run PostFix  to relay the message through Amazon SES using a perl script.

I found a good tutorial on getting this configured here. I did have an issue getting perl to find the SES.pm file, but this post details how to work around that issue. The great thing about handling it this way is other applications on the server can send messages through the gateway, not just ColdFusion applications.

Improved connector for Nginx proxy to Railo


Edit: This post is outdated. Please see this post https://kisdigital.wordpress.com/2013/03/04/my-final-nginxrailo-connector/

I have been working with Nginx quite a bit in the last week and I have had a little time to fine-tune my configuration a bit. Here is my stock Railo configuration. I have saved the settings to their own file and include the connector in each separate server configuration that requires Railo. This also remaps the standard Railo administrator to a more secure location and optionally sets basic authentication.

 # /etc/nginx/railo_connector.conf
 # Block default Railo admin
 if ($request_uri ~* ^/railo-context){
  return 404;
 }

 # Hide the Railo Administrator and optionally lock down with password
 location ~ ^/hardtoguesslocation/(.*)$ {
  #auth_basic $host;
  #auth_basic_user_file /path/to/htpasswd;
  if($request_uri ~^/railo-context/admin){
   return 404;
  }
  location ~^/hardtoguesslocation/{
   rewrite ^/hardtoguesslocation/(.*)$ /railo-context/admin/$1 last;
  }
 }

 # Main Railo proxy handler
 location ~ \.(cfm|cfml|cfc|jsp|cfr)(.*)$ {
  proxy_pass http://127.0.0.1:8888;
  proxy_redirect off;
  proxy_set_header Host $host;
  proxy_set_header X-Forwarded-Host $host;
  proxy_set_header X-Forwarded-Server $host;
  proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  proxy_set_header X-Real-IP $remote_addr;
 }

Also, Nginx allows you to use variables in your server configuration so it allows you to easily create a “catch all” virtual host. You can quickly add a new website just by adding it to your server.xml in Railo with no additional configuration required unless you require domain specific rewrites etc. Here is an example server configuration with a default virtual host and a separate domain configured:

server {
 #Catchall vhost
 listen    80; ## listen for ipv4
 server_name _;
 root /var/www/$host;
 index index.cfm;
 access_log  /var/logs/nginx/$host-access.log;
 # Do not log missing favicon.ico errors
 location = /favicon.ico { access_log off; log_not_found off; }
 # Do not serve any .hidden files
 location ~ /\. { access_log off; log_not_found off; deny all; }
 include /etc/nginx/railo_connector.conf;
# End of catch-all Server Configuration
}

server {
 #A domain with custom handling
 listen    80; ## listen for ipv4
 server_name mydomain.com www.mydomain.com;
 root /var/www/mydomain.com;
 index index.cfm;
 access_log  /var/logs/nginx/mydomain.com-access.log;
 # Do not log missing favicon.ico errors
 location = /favicon.ico { access_log off; log_not_found off; }
 # Do not serve any .hidden files
 location ~ /\. { access_log off; log_not_found off; deny all; }
 # Handle FW/1 style SES urls (i.e. http:/domain.com/main/default/key/value)
 location /{
  try_files $uri $uri/ @ses;
 }
 location @ses{
  rewrite ^/index.cfm/$uri last;
 }
 include /etc/nginx/railo_connector.conf;
# End of custom Server Configuration
}

If you want the X-Real-IP reported correctly on the Railo server you will also need to add the RemoteIP valve to your Tomcat configuration.

Overall Nginx makes a very nice front-end to Railo and as always I welcome any comments or suggestions to make it better.