Limechatのマクロ/スクリプトについて。


CH上でURLを含む発言があった際に、そのURLのtitleを取得して返すスクリプトを書ける方、作成していただけませんか。
youtubeやニコニコ動画だった場合、動画のタイトル取得ができるようにもお願いいたします。

回答の条件
  • 1人2回まで
  • 登録:
  • 終了:2011/02/07 10:39:12
※ 有料アンケート・ポイント付き質問機能は2023年2月28日に終了しました。

ベストアンサー

id:Cherenkov No.2

回答回数1504ベストアンサー獲得回数493

ポイント50pt

OSはなんですか。

回答1のスクリプトの動作確認しました。

Limechat Script - Cathode Music


「壁に耳あり」と発言すると有効になります。(スクリプトの設定も有効に)

これを元に改造できると思うので要望があればお答えします。

id:kitamati

あ、有効化コマンドがあったんですね・・・正常に動作しました。

その上で、ちょっと確認を。

ニコニコ動画のURLからページ情報の取得はうまくいっています。

通常のURLも同様です。

Youtubeについては、タイトルの取得は出来ていますが

> 再生数:取得不可能|コメント:取得不可能|レスポンス:取得不可能

> 説明:取得不可能

のようになっています。そちらでも同じ状況でしょうか?

※ポイントが切れてしまったため、コメント欄にご返信いただければ幸いです。

2011/02/04 16:57:36

その他の回答1件)

id:snmp No.1

回答回数20ベストアンサー獲得回数1

ポイント20pt

動作確認はしてませんが、下記URLで配布されてます。


URLタイトル取得

URLを貼るとページのタイトルを取得して発言します。ニコニコ動画、YouTube、pixiv、ニコニコミュニティー、ニコニコ生放送のURLを貼るとさらに詳しい情報が返されます。

Limechat Script - Cathode Music

id:kitamati

動きません。改造できる方引き続き回答お願いします。

2011/02/04 15:04:38
id:Cherenkov No.2

回答回数1504ベストアンサー獲得回数493ここでベストアンサー

ポイント50pt

OSはなんですか。

回答1のスクリプトの動作確認しました。

Limechat Script - Cathode Music


「壁に耳あり」と発言すると有効になります。(スクリプトの設定も有効に)

これを元に改造できると思うので要望があればお答えします。

id:kitamati

あ、有効化コマンドがあったんですね・・・正常に動作しました。

その上で、ちょっと確認を。

ニコニコ動画のURLからページ情報の取得はうまくいっています。

通常のURLも同様です。

Youtubeについては、タイトルの取得は出来ていますが

> 再生数:取得不可能|コメント:取得不可能|レスポンス:取得不可能

> 説明:取得不可能

のようになっています。そちらでも同じ状況でしょうか?

※ポイントが切れてしまったため、コメント欄にご返信いただければ幸いです。

2011/02/04 16:57:36
  • id:kitamati
    仕様としては、htmlタグのtitle,javascriptタグのtitlebodyの取得ができること
    とりあえずとしてYouTube,ニコニコ動画のAPIにアクセスして動画のタイトルを取得できるようにする
    といったところでしょうか。
  • id:Cherenkov
    自動で有効にする改造でも。
    まず6行目のloadLmf()という関数は見つからないので
    //loadLmf();
    のようにコメントアウトしておいたほうが。
    次にevent::onChannelText関数を以下のようにすると自動で有効になります。
    function event::onChannelText(prefix, channel, text){
    var url = getUrl.exec(text);
    if (url&&url.index==0){
    if(text.match(/watch\/([s|n]m\d*)/)){
    nico2title(channel,RegExp.$1);
    return;
    }else if(text.match(/watch\/(lv\d*)/)){
    nicolive2title(channel,RegExp.$1);
    return;
    }else if(text.match(/member_illust\.php\?mode=medium&illust_id=(\d*)/)){
    pixiv2title(channel,RegExp.$1);
    return;
    }else if(text.match(/ch\.nicovideo\.jp\/community\/(co\d*)/)){
    nicom2title(channel,RegExp.$1);
    return;
    }else if(text.match(/youtube\.com\/watch\?v=/)){
    youtube2title(url,channel);
    return;
    }
    url2title(url,channel);
    return;
    }
    }
  • id:Cherenkov
    取得不可能になりますね。ポイントほしいですね。
    確か仕様ではタイトルだけですね。
    レスポンスと説明はいらない場合は以下のように。

    function youtube2title(url,channel){
    var xmlhttp = XMLHttpRequest();
    if (xmlhttp) {
    xmlhttp.setTimeouts(5*1000,5*1000,15*1000,15*1000);
    xmlhttp.onreadystatechange = function() {
    if (xmlhttp.readyState == 4 && xmlhttp.responseText.length) {
    var s = xmlhttp.responseText.replace(/\n/g,"").replace(/\r/g,"");
    var title = getRegExp(s,"<title>(.+?)<\/title>").replace(/^YouTube - /,"");
    var desc = getRegExp(s,"<span class=\"description\">(.+?)<\/span>");
    var viewcnt = getRegExp(s,"<span class=\"watch-view-count\">\\s+<strong>(.+)<\/strong>\\s+<\/span>");
    var comcnt = getRegExp(s,"<p id=\"eow-description-short\" >(.+?)<\/p>");
    comcnt = comcnt.replace(/(<a href=[^>]+>)|(<wbr>&shy;)/g,"").replace(/(<\/a>)/g,"");
    var resp = getRegExp(s,"<span id=\"watch-comments-numresponses\">(.+?)<\/span>");
    send(channel,"【"+title+"】");
    send(channel,"再生数:"+viewcnt+"|コメント:"+comcnt);
    }
    }
    try{
    xmlhttp.open("GET",url,true);
    }catch(e){
    send(channel,e);
    }
    xmlhttp.setRequestHeader("User-Agent","Mozilla/5.0 (compatible; url2title@limechat;)");
    xmlhttp.send("");
    }
    }
  • id:kitamati
    おお、ありがとうございます。今のところ正常に動作しているんですが、
    Amazonのタイトルを取得しようとしたときに、文字コードを認識していないみたいです。わがままついでに修正お願いしてもいいですか?
  • id:Cherenkov
    前の修正のresp変数はいらない。

    function url2title(url,channel){
    var xmlhttp = XMLHttpRequest();
    if (xmlhttp) {
    xmlhttp.setTimeouts(5*1000,5*1000,15*1000,15*1000);
    xmlhttp.onreadystatechange = function() {
    if (xmlhttp.readyState == 4 && xmlhttp.responseText.length) {
    var s = xmlhttp.responseText.replace(/\n/g,"").replace(/\r/g,"");
    if(s.match(/<title>(.+?)<\/title>/)){
    var title = RegExp.$1;
    title = title.replace(/&#x[0-9A-F]+;/g, function(m){ return String.fromCharCode(parseInt(m.replace(/&#x|;$/g,''), 16)); });
    send(channel,"【"+title+"】");
    }
    }
    }
    try{
    xmlhttp.open("GET",url,true);
    }catch(e){
    send(channel,e);
    }
    xmlhttp.setRequestHeader("User-Agent","Mozilla/5.0 (compatible; url2title@limechat;)");
    xmlhttp.send("");
    }
    }
  • id:kitamati
    たびたびすみません。
    文字化けは直りましたが、Youtubeの取得の際に、

    再生数:1,156,341</strong> </span> <button title="動画の統計情報を表示" type="button" id="watch-insight-button" onclick=";return false;" class="yt-uix-tooltip yt-uix-tooltip-reverse master-sprite yt-uix-button yt-uix-tooltip" data-button-action="yt.www.watch.watch5.stats" role="button" aria-pressed="false"><img class="yt-uix-button-icon-watch-insight" src="//s.ytimg.com/yt/img/pixel-vfl3z5WfW.gif" alt=""> </button>
    </div><span class="yt-uix-button-group"><button title="評価する" type="button" class="master-sprite start yt-uix-tooltip-reverse yt-uix-button yt-uix-tooltip" onclick=";return false;" id="watch-like" data-button-action="yt.www.watch.watch5.like" role="button" aria-pressed="false"><img class="yt-uix-button-icon-watch-like" src="//s.ytimg.com/yt/img/pixel-vfl3z5WfW.gif" alt=""> <span class="yt-uix-button-content">評
    価する</span></button><button title="評価しない" type="button" class="master-sprite end yt-uix-tooltip-reverse yt-uix-button yt-uix-tooltip" onclick=";return false;" id="watch-unlike" data-button-action="yt.www.watch.watch5.unlike" role="button" aria-pressed="false"><img class="yt-uix-button-icon-watch-unlike" src="//s.ytimg.com/yt/img/pixel-vfl3z5WfW.gif" alt=""> </button></span> <span dir="ltr" class="yt-uix-butto
    n-group addto-container show-label watch" data-video-ids="zcXoJhXYeAU" data-feature="watch"><button type="button" class="master-sprite start yt-uix-tooltip-reverse yt-uix-button yt-uix-tooltip" onclick=";return false;" title="キューに追加" data-button-action="yt.www.addtomenu.add" role="button" aria-pressed="false"><img class="yt-uix-button-icon-addto" src="//s.ytimg.com/yt/img/pixel-vfl3z5WfW.gif" alt=""> <span class="y

    このような形でソース毎?取得してしまっているようです。この点の修正だけお願いいたします。
  • id:Cherenkov
    function youtube2title(url,channel){
    var xmlhttp = XMLHttpRequest();
    if (xmlhttp) {
    xmlhttp.setTimeouts(5*1000,5*1000,15*1000,15*1000);
    xmlhttp.onreadystatechange = function() {
    if (xmlhttp.readyState == 4 && xmlhttp.responseText.length) {
    var s = xmlhttp.responseText.replace(/\n/g,"").replace(/\r/g,"");
    var title = getRegExp(s,"<title>(.+?)<\/title>").replace(/^YouTube - /,"");
    var desc = getRegExp(s,"<span class=\"description\">(.+?)<\/span>");
    var viewcnt = getRegExp(s,"<span class=\"watch-view-count\">\\s+<strong>([^<]+)");
    var comcnt = getRegExp(s,"<p id=\"eow-description-short\" >(.+?)<\/p>");
    comcnt = comcnt.replace(/(<a href=[^>]+>)|(<wbr>&shy;)/g,"").replace(/(<\/a>)/g,"");
    send(channel,"【"+title+"】");
    send(channel,"再生数:"+viewcnt+"|コメント:"+comcnt);
    }
    }
    try{
    xmlhttp.open("GET",url,true);
    }catch(e){
    send(channel,e);
    }
    xmlhttp.setRequestHeader("User-Agent","Mozilla/5.0 (compatible; url2title@limechat;)");
    xmlhttp.send("");
    }
    }
  • id:kitamati
    ありがとうございました。
    正常に動作していますので、Closeとさせていただきます。

この質問への反応(ブックマークコメント)

「あの人に答えてほしい」「この質問はあの人が答えられそう」というときに、回答リクエストを送ってみてましょう。

これ以上回答リクエストを送信することはできません。制限について

回答リクエストを送信したユーザーはいません