Skip to content

Instantly share code, notes, and snippets.

@saitamanodoruji
Created October 31, 2012 13:44
Show Gist options
  • Save saitamanodoruji/3987111 to your computer and use it in GitHub Desktop.
Save saitamanodoruji/3987111 to your computer and use it in GitHub Desktop.
SoundCloud から Tumblr に audio ポストする tombloo パッチ
////////////////////////////////////////////////////////////////
// SoundCloud から Tumblr に audio ポストする tombloo パッチ
// SoundCloud へリンクするタイプの Audio ポストができる
// 音声ファイルつきの Audio ポストにはならない
////////////////////////////////////////////////////////////////
// ポストするとき tombloo の小窓にタイトル等が表示されない.
// quickPostForm.js を編集すると表示できるけど
// パッチからいじる方法がわからないのでそのまま.
// 他のポストタイプを真似して audio ポストタイプを作る
Tombloo.Post.initialize = function(){
try{
return this.db.execute(<>
CREATE VIEW posts AS
SELECT "regular" AS type, id, user, date,
title,
body,
"" AS source,
"" AS player,
"" AS imageId
FROM regulars
UNION ALL
SELECT "photo" AS type, id, user, date,
"" AS title,
body,
"" AS source,
"" AS player,
imageId
FROM photos
UNION ALL
SELECT "video" AS type, id, user, date,
"" AS title,
body,
source,
player,
"" AS imageId
FROM videos
UNION ALL
SELECT "link" AS type, id, user, date,
title,
body,
source,
"" AS player,
"" AS imageId
FROM links
UNION ALL
SELECT "conversation" AS type, id, user, date,
title,
body,
"" AS source,
"" AS player,
"" AS imageId
FROM conversations
UNION ALL
SELECT "quote" AS type, id, user, date,
"" AS title,
body,
source,
"" AS player,
"" AS imageId
FROM quotes
UNION ALL
SELECT "audio" AS type, id, user, date,
body,
source,
"" AS player,
"" AS imageId
FROM audios
</>);
} catch(e if e instanceof Database.AlreadyExistsException){}
}
Tombloo.Audio = Tombloo.Entity({
name : 'audios',
fields : {
id : 'INTEGER PRIMARY KEY',
user : 'TEXT',
date : 'TIMESTAMP',
title : 'TEXT',
source : 'TEXT',
body : 'TEXT',
}
});
Tombloo.initialize = function(){
with(this){
Tag.initialize();
Regular.initialize();
Photo.initialize();
Video.initialize();
Link.initialize();
Conversation.initialize();
Quote.initialize();
Audio.initialize();
Post.initialize();
db.version = SCHEMA_VERSION;
}
}
// extracotor
Tombloo.Service.extractors.register([
{
name : 'Audio - SoundCloud',
ICON : 'http://soundcloud.com/favicon.ico',
check : function(ctx){
return ctx.href.match('^http://soundcloud\.com/[^/]+/.+');
},
extract : function(ctx){
// Tombloo の設定を開くたびに prefs.js の postConfig の値が更新されて
// audio のポスト先がひとつもない状態になる.
// だから extractor を呼ぶタイミングでポスト先の設定を更新し直す.
// prefs.xul をパッチからいじれなさそうなのでこうした.
var config = eval(getPref('postConfig'));
config.Tumblr.audio = 'default';
setPref('postConfig', uneval(config));
var desc = $x('//div[@class="description"]', ctx.window.document);
var ps = {
type : 'audio',
item : ctx.title,
itemUrl : ctx.href,
description : desc ? desc.innerHTML : '' ,
artist : ctx.window.document.querySelector('a.user-name').textContent,
}
return ps
},
},
],'Audio');
// Tumblr オブジェクトが model として
// ps.type == 'audio' な ps を受けつけるようにする
Tumblr.check = function(ps){
return (/(regular|photo|quote|link|conversation|video|audio)/).test(ps.type);
}
// model
Tumblr.Audio = {
convertToModel : function(post, info){
return update(info, {
source : ''+ post['audio-url'],
body : ''+ post['audio-description'],
});
},
convertToForm : function(ps){
return {
'post[type]' : ps.type,
'post[two]' : '<a href="' + ps.itemUrl + '">' + ps.item + '</a>'
+ '<blockquote cite="' + ps.itemUrl + '" title="' + ps.item
+ '">' + ps.description + '</blockquote>',
'post[three]' : ps.itemUrl,
'id3_tags[artist]' : ps.artist,
};
},
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment