Ricardo Author

Re: @monk-time:
Nice catch, monk-time! Thanks for the great bug report!

Yes, I was lazy an naive, so I trusted that IMDb would always produce a valid CSV file. It doesn't. So I changed the code from using regex to something hopefully more robust and legible. At first it seemed to work fine, but then I found another problem with the IMDb data (notice the line feed after "Morto":
"798","tt0365748","Thu Feb 16 11:00:00 2006","Wed Aug 10 20:05:39 2011","Todo Mundo Quase Morto (ou Zombies Party - Uma Noite... de Morte?)","Shaun of the Dead","Feature Film","Edgar Wright","10","8.0","99","2004","comedy, horror","330366","2004-03-29","http://www.imdb.com/title/tt0365748/"

Now this will cause the following output in the console:

[!] 5 fields in "798","tt0365748","Thu Feb 16 11:00:00 2006","Wed Aug 10 20:05:39 2011","Todo Mundo Quase Morto [!] 12 fields in (ou Zombies Party - Uma Noite... de Morte?)","Shaun of the Dead","Feature Film","Edgar Wright","10","8.0","99","2004","comedy, horror","330366","2004-03-29","http://www.imdb.com/title/tt0365748/" [X] Error getting IMDb const from: (ou Zombies Party - Uma Noite... de Morte?)","Shaun of the Dead","Feature Film","Edgar Wright","10","8.0","99","2004","comedy, horror","330366","2004-03-29","http://www.imdb.com/title/tt0365748/"

Well, I don't think it's worth working around all possible CSV problems, so I think I'll try to submit a bug report to IMDb. As lazy as I am, I noticed that the code still works for me even with the error above, but let me know if you have any problem.

FIY, here are the changes I've made:

  var lines = request.responseText.split("\n");
  var res, movieCode;
  for (var i=0; i < lines.length; i++) {
     if (lines[i].length < 50) continue;
     fields = lines[i].split('","');
     // 00:position   | 06:Title type    |12:Genres                       
     // 01:const      | 07:Directors     |13:Num. Votes
     // 02:created    | 08:You rated     |14:Release Date (month/day/year)
     // 03:modified   | 09:IMDb Rating   |15:URL
     // 04:description| 10:Runtime (mins)|
     // 05:Title      | 11:Year          |
     if (fields.length != 16) console.warn(fields.length + " fields in " + lines[i]);
     var tt = fields[1];
     if (tt == 'const') continue; // skip first line of csv file
     var ratingMine = fields[8];
     var ratingIMDb = fields[9];
     if (tt.substr(0,2) != 'tt') {
        console.error("Error getting IMDb const from: "+lines[i]);
        continue;
     }
     ttNum = parseInt(tt.substr(2));
     
     // I "encode" the movie number with "base 36" to save memory
     movieCode = ttNum.toString(36);
     myLists[idx].movies[movieCode] = {m:ratingMine, i:ratingIMDb};
  }