Skip to content

Instantly share code, notes, and snippets.

@redaktor
Last active August 29, 2015 14:00
Show Gist options
  • Select an option

  • Save redaktor/11404745 to your computer and use it in GitHub Desktop.

Select an option

Save redaktor/11404745 to your computer and use it in GitHub Desktop.

Revisions

  1. redaktor revised this gist May 2, 2014. 1 changed file with 15 additions and 9 deletions.
    24 changes: 15 additions & 9 deletions EXIF makernotes to JSON
    Original file line number Diff line number Diff line change
    @@ -1,10 +1,10 @@
    // http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/Canon.html#CameraInfo5DmkII

    var vendorToJSON = 'Canon';
    var vendorToJSON = 'Nikon';

    var scraper = require('scraper');
    var util = require('util');
    scraper('http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/'+vendorToJSON+'.html', function(err, jQuery) {
    scraper('http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/'+vendorToJSON+'Custom.html', function(err, jQuery) {
    if (err) {throw err}
    var h2 = [];
    var ta = [];
    @@ -22,24 +22,30 @@ scraper('http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/'+vendorToJSON+'.
    trs.each(function(j,tr) {
    if(j>0){
    var tds = jQuery('td', tr);

    if(tds.length==4){
    var val = '';
    if(tds[3].textContent.indexOf(' = ')>-1){
    var str = (tds[3].textContent.trim().substr(0,1)=='[' && tds[3].textContent.trim().indexOf(']')>-1) ? tds[3].textContent.split(']')[1].trim() : tds[3].textContent.trim();
    var vStr = tds[1].textContent.trim();

    if(str.indexOf(' = ')>-1){
    // '0 = Off, 1 = On (1), 2 = On (2)'
    var vals = tds[3].textContent.trim().replace(/\n/g, '",').replace(/ = /g,':"');
    val = { name:tds[1].textContent.trim(), values:'{"'+vals+'"}' }
    var vals = str.replace(/\n/g, '",').replace(/ = /g,':"');
    val = { name:vStr, val:'{'+vals+'"}' }
    vals = null;
    } else if(tds[3].textContent.indexOf('-->')>-1){
    val = { reference:tds[3].textContent.trim().replace(/__>/g, ""), name: tds[1].textContent.replace(/\n/g, ",")};
    } else if(str.indexOf('-->')>-1){
    val = { ref:str.replace(/-->/g, "") };
    } else {
    val = tds[1].textContent.trim().replace(/\n/g, ",");
    val = vStr.replace(/\n/g, ",");
    }

    ta[i].fields[tds[0].textContent] = val;

    val,str,vStr = null;
    }
    tds = null;
    }
    tds,val = null;

    });
    trs,ta[i].table = null;
    delete ta[i].table;
  2. redaktor revised this gist Apr 29, 2014. 1 changed file with 7 additions and 0 deletions.
    7 changes: 7 additions & 0 deletions EXIF makernotes to JSON
    Original file line number Diff line number Diff line change
    @@ -44,6 +44,13 @@ scraper('http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/'+vendorToJSON+'.
    trs,ta[i].table = null;
    delete ta[i].table;
    });
    var tmpTa = ta;
    var ta = {};
    tmpTa.forEach(function(t,i){
    var n = t.name;
    delete t.name;
    ta[n] = t;
    })
    console.log(util.inspect(ta, false, null));
    // ta is our OBJECT! Do something with ta. E.g. write to file ...
    });
  3. redaktor revised this gist Apr 29, 2014. 1 changed file with 1 addition and 6 deletions.
    7 changes: 1 addition & 6 deletions EXIF makernotes to JSON
    Original file line number Diff line number Diff line change
    @@ -3,6 +3,7 @@
    var vendorToJSON = 'Canon';

    var scraper = require('scraper');
    var util = require('util');
    scraper('http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/'+vendorToJSON+'.html', function(err, jQuery) {
    if (err) {throw err}
    var h2 = [];
    @@ -13,20 +14,15 @@ scraper('http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/'+vendorToJSON+'.
    jQuery('blockquote table.inner').each(function() {
    ta.push({table:this, name:'', fields:{}});
    });
    console.log( h2.length );
    console.log( ta.length );
    //var map = {};
    ta.forEach(function(t,i){
    ta[i].name = h2[i];

    var trs = jQuery('tr', t.table);
    if(i<5) console.log('trs', trs.length );
    trs.each(function(j,tr) {
    if(j>0){
    var tds = jQuery('td', tr);
    if(i<5) console.log('tds', tds.length );
    if(tds.length==4){
    console.log( i );
    var val = '';
    if(tds[3].textContent.indexOf(' = ')>-1){
    // '0 = Off, 1 = On (1), 2 = On (2)'
    @@ -48,7 +44,6 @@ scraper('http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/'+vendorToJSON+'.
    trs,ta[i].table = null;
    delete ta[i].table;
    });

    console.log(util.inspect(ta, false, null));
    // ta is our OBJECT! Do something with ta. E.g. write to file ...
    });
  4. redaktor revised this gist Apr 29, 2014. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion EXIF makernotes to JSON
    Original file line number Diff line number Diff line change
    @@ -48,5 +48,7 @@ scraper('http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/'+vendorToJSON+'.
    trs,ta[i].table = null;
    delete ta[i].table;
    });
    console.log( ta[0] );

    console.log(util.inspect(ta, false, null));
    // ta is our OBJECT! Do something with ta. E.g. write to file ...
    });
  5. redaktor revised this gist Apr 29, 2014. 1 changed file with 7 additions and 3 deletions.
    10 changes: 7 additions & 3 deletions EXIF makernotes to JSON
    Original file line number Diff line number Diff line change
    @@ -29,9 +29,12 @@ scraper('http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/'+vendorToJSON+'.
    console.log( i );
    var val = '';
    if(tds[3].textContent.indexOf(' = ')>-1){
    val = { name:tds[1].textContent.trim(), values:tds[3].textContent.trim().replace(/\n/g, ",") }
    // '0 = Off, 1 = On (1), 2 = On (2)'
    var vals = tds[3].textContent.trim().replace(/\n/g, '",').replace(/ = /g,':"');
    val = { name:tds[1].textContent.trim(), values:'{"'+vals+'"}' }
    vals = null;
    } else if(tds[3].textContent.indexOf('-->')>-1){
    val = tds[3].textContent.trim().concat(tds[1].textContent).replace(/\n/g, ",");
    val = { reference:tds[3].textContent.trim().replace(/__>/g, ""), name: tds[1].textContent.replace(/\n/g, ",")};
    } else {
    val = tds[1].textContent.trim().replace(/\n/g, ",");
    }
    @@ -40,8 +43,9 @@ scraper('http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/'+vendorToJSON+'.

    }
    }
    tds,val = null;
    });
    ta[i].table = null;
    trs,ta[i].table = null;
    delete ta[i].table;
    });
    console.log( ta[0] );
  6. redaktor created this gist Apr 29, 2014.
    48 changes: 48 additions & 0 deletions EXIF makernotes to JSON
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,48 @@
    // http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/Canon.html#CameraInfo5DmkII

    var vendorToJSON = 'Canon';

    var scraper = require('scraper');
    scraper('http://www.sno.phy.queensu.ca/~phil/exiftool/TagNames/'+vendorToJSON+'.html', function(err, jQuery) {
    if (err) {throw err}
    var h2 = [];
    var ta = [];
    jQuery('h2').each(function() {
    h2.push(jQuery(this).text().trim());
    });
    jQuery('blockquote table.inner').each(function() {
    ta.push({table:this, name:'', fields:{}});
    });
    console.log( h2.length );
    console.log( ta.length );
    //var map = {};
    ta.forEach(function(t,i){
    ta[i].name = h2[i];

    var trs = jQuery('tr', t.table);
    if(i<5) console.log('trs', trs.length );
    trs.each(function(j,tr) {
    if(j>0){
    var tds = jQuery('td', tr);
    if(i<5) console.log('tds', tds.length );
    if(tds.length==4){
    console.log( i );
    var val = '';
    if(tds[3].textContent.indexOf(' = ')>-1){
    val = { name:tds[1].textContent.trim(), values:tds[3].textContent.trim().replace(/\n/g, ",") }
    } else if(tds[3].textContent.indexOf('-->')>-1){
    val = tds[3].textContent.trim().concat(tds[1].textContent).replace(/\n/g, ",");
    } else {
    val = tds[1].textContent.trim().replace(/\n/g, ",");
    }

    ta[i].fields[tds[0].textContent] = val;

    }
    }
    });
    ta[i].table = null;
    delete ta[i].table;
    });
    console.log( ta[0] );
    });