Chinachuで録画番組をストリーミングで連続再生したかったので、そのためのXSPFプレイリストを生成する簡易的なブックマークレットを作った。
使い方
ソース
ブックマーク用リンクは下にある。
コンテナはM2TS、コーデックは映像・音声ともに無変換とした。これらパラメータは無名関数の引数として指定している。この辺りは、普通に番組をストリーミングする時に使いたい設定にしてダウンロードしたxspfファイルやAPIを参考に変更するとよいと思われる。
(function(prm){ t='<?xml version="1.0" encoding="UTF-8"?><playlist version="1" xmlns="http://xspf.org/ns/0/"><trackList>'; d=document.getElementsByClassName("id"); for(i=0;i<d.length;i++){ b=d[i].textContent.substr(1); s=""; for(e of Array.from(d[i].parentNode.childNodes)){ if(e.nodeName=="#text"){ s+=e.nodeValue }else if(e.getAttribute("class")=="episode"){ s+=e.textContent } } t+='<track><location>http://'+window.location.host+'/api/recorded/'+b +'/watch.'+prm+'&prefix=http%3A%2F%2F' +window.location.host+'%2Fapi%2Frecorded%2F'+b+'%2F</location><title>'+s+'</title></track>'; } t+='</trackList></playlist>'; e=document.createEvent("MouseEvents"); e.initMouseEvent("click",true,f=false,window,0,0,0,0,0,f,f,f,f,0,null); a=document.createElementNS("http://www.w3.org/1999/xhtml","a"); a.href=(window.URL||window.webkitURL).createObjectURL(new Blob([t],{"type":"application/xspf+xml"})); a.download="playlist.xspf"; a.dispatchEvent(e); })('m2ts?ext=m2ts&c:v=copy&c:a=copy'.replace(/&/g,"&"));