Apple - iTunes - iTunes Match

����Υ�ϥӥ����Ƥ�ˡ�

Demo:

  • �ʲ����п�����ʬ�˳ڶʥե������drag & drop���Ƥ���������
  • �ǥ����ȥåפ�������ǤϤʤ���iTunes.app�����ľ��drag & drop�Ǥ��ޤ���
  • ʣ���ե����뤬drop���줿��硢�ǽ�Τ�Τ����������оݤˤʤ�ޤ�
  • ���㥱���ò¥¯¥ï¿½Ã¥ï¿½ï¿½ï¿½ï¿½ï¿½È¡ï¿½iTunes Store�����Ӥޤ���
  • Drop the matched song here!

    Info:
    iTunes ID:
    Lookup:

    ����

    ��äƤ��뤳�ȤϤ���Ȥۤ��Ѥ��ޤ���

    �������Ȥ������������Ȥ�������iTunes¦�ˤϰ��ڤ��ѹ���ä��ʤ��Ȥ������㤤�Ǥ�����

    �ǡ���äƤߤ�Ф狼��ΤǤ��������μ�ϻȤ��٤��ǤϤ���ޤ�����

    ����äȹͤ��Ƥߤ�Ф狼��ΤǤ�������Ʊ���ڶʡפȤ��äƤ⡢������Ͽ���Ƥ��륢��Х�Ϥ����Ĥ⤢��ޤ������ʤ���Let it be�ϺǸ�Υ���Х�Ǥ����Ĥ��ۤǤ�������Ȥ�1�Ǥ���?���뤤�Ϥ褽�ι�Ǻ��줿����ԥ졼����󥢥�Х�Ǥ���?

    ��μ긵�Ǥ�The Essential Micheal Jackson�˼�Ͽ����Ƥ���Bad������˥ޥå��������Τä����ˤϥԥ������᤭�ޤ����褿��ꤷ����

    Enjoy!

    Dan the Man with Too Many Songs to Match and Upload

    Demo Source:

    HTML


JavaScript

(function(global){
if (!global.FileReader) return; /* throw new Error('FileReader not supported'); */

var $ = function (id) {
    return document.getElementById(id)
};

var itxt = 'innerText' in document.body ? 'innerText' : 'textContent';

var mingif = 'data:image/gif;base64,' +
    'R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==';

/* var countries = 'JP US GB CA AU FR DE IT DZ AO AI AG AR AM AT AZ BS BH BD BB BY BE BZ BM BO BW BR BN BG CM KY CL CN CO CR CI HR CY CZ DK DM DO EC EG SV EE ET FI GH GR GD GT GY HN HK HU IS IN ID IE IL JM JO KZ KE KR KW LV LB LY LI LT LU MO MK MG MY MV ML MT MU MX MD MS MM NP NL NZ NI NE NG NO OM PK PA PY PE PH PL PT QA RO RU KN LC VC SA SN RS SG SK SI ZA ES LK SR SE CH TW TZ TH TT TN TR TC UG UA AE UY UZ VE VN VG YE'.split(' '); */
var countries = 'JP US CA GB AU NZ HK SG JM'.split(' ')

var readit = function (files) {
    var file = files[0],
        info = {
            name: file.name,
            lastModifiedDate: file.lastModifiedDate,
            size: file.size,
            type: file.type
        };
    $('fileInfo').textContent = JSON.stringify(info, null, '  ');
    if (file.type.indexOf('audio/') === 0) {
        checkid(file, $('itsID'));
    } else {
        noitsid();
    }
};

var noitsid = function () {
    $('itsID')[itxt] = 'No iTS ID Found.';
    $('lookup')[itxt] = '';
    clsArtwork();
};

var clsArtwork = function () {
    $('trackViewUrl').href = '';
    $('artworkUrl100').src = mingif;
};

var checkid = function (file, node) {
    var reader = new FileReader();
    reader.onload = function (ev) {
        var head = ev.target.result.slice(0, 1023),
            idx = head.indexOf('song');
        if (idx !== -1) {
            var itsID = (head.charCodeAt(idx + 4) << 24) + (head.charCodeAt(
                    idx + 5) << 16) + (head.charCodeAt(idx + 6) << 8) +
                head.charCodeAt(idx + 7);
            node[itxt] = itsID;
            JSONP.cidx = 0;
            JSONP.get(itsID);
        } else {
            noitsid();
        }
    };
    reader.readAsBinaryString(file);
}

global.JSONP = {
    get: function (itsID) {
        if (JSONP.cidx >= countries.length) return;
        var d = document,
            u = 'http://itunes.apple.com/lookup?callback=JSONP.run' + '&id=' +
            itsID,
            s = d.createElement('script'),
            c = countries[JSONP.cidx++];
        $('lookup')[itxt] = 'Looking up: ' + c;
        if (c !== 'US') u += '&country=' + c;
        s.charset = 'UTF-8';
        s.id = s.src = u;
        d.body.appendChild(s);
    },
    run: function (json) {
        $('lookup')[itxt] = JSON.stringify(json, null, 2);
        if (!json['resultCount']) {
            clsArtwork();
            JSONP.get($('itsID')[itxt]);
        } else {
            $('artworkUrl100').src = json.results[0]['artworkUrl100'];
            $('trackViewUrl').href = json.results[0]['trackViewUrl'];
        }
    },
    cidx: 0
};

var ondragover = function (ev) {
    ev.stopPropagation();
    ev.preventDefault();
    ev.dataTransfer.dropEffect = 'copy';
};
var ondrop = function (ev) {
    ev.stopPropagation();
    ev.preventDefault();
    readit(ev.dataTransfer.files);
};

$('dropfile').addEventListener('dragover', ondragover, false);
$('dropfile').addEventListener('drop', ondrop, false);

})(this);