Added lirycs
Build and Publish / Build and Publish Docker Image (push) Failing after 25s

This commit is contained in:
ab committed 2026-11-23 01:45:22 +02:00
1 parent eefe8a9777
commit beea7c1c0a
37 files changed
+1779 -34

No files matched your search

+24
View File
@@ -0,0 +1,24 @@
const assert=require('node:assert/strict'),{test}=require('node:test'),fs=require('node:fs'),vm=require('node:vm');
const template=fs.readFileSync(`${__dirname}/../templates/admin/v2.html`,'utf8');
const ui=fs.readFileSync(`${__dirname}/../templates/admin/ui.html`,'utf8').match(/<script>([\s\S]*?)<\/script>/)[1];
const script=ui+'\n'+template.match(/<script>\s*(function adminV2\(\)[\s\S]*?)<\/script>/)[1];
function setup(){
const context=vm.createContext({crypto:{randomUUID:()=> 'fixture-uuid'},setTimeout(){}});vm.runInContext(script,context);
const app=context.adminV2();app.icons=()=>{};app.showToast=()=>{};app.refreshCountsOnly=async()=>{};
app.activeLibraryItem={kind:'tracks',id:1};app.editorDetail={};app.editorDraft={title:'Song',hidden:'false',release_id:2,artist_ids:[]};app.editorCanSave=()=>true;
return app;
}
test('track save includes alternative lyrics and retry, preserving untouched provider text',async()=>{
const app=setup(),requests=[];app.editorLyrics=[{id:'lrclib:1',label:'Original',source:'lrclib',source_id:'1',language:null,plain_text:' words\n',synced_lrc:'[00:01]words\n',instrumental:false}];app.editorLyricsRetry=true;
app.request=async(url,options)=>{requests.push(JSON.parse(options.body));return {id:1,kind:'tracks',title:'Song'};};
app.replaceLibraryItem=()=>{};app.loadEditorDetail=async()=>{};
await app.saveLibraryItem();
assert.equal(requests[0].lyrics.versions[0].plain_text,' words\n');
assert.equal(requests[0].lyrics.versions[0].source,'lrclib');
assert.equal(requests[0].lyrics.retry_lookup,true);
});
test('manual alternatives have unique local identities and a bounded count',()=>{
const app=setup();app.addLyricsVersion();
assert.equal(app.editorLyrics[0].id,'manual:fixture-uuid');assert.equal(app.editorLyrics[0].source,'manual');
app.editorLyrics=Array.from({length:16},(_,i)=>({id:String(i)}));app.addLyricsVersion();assert.equal(app.editorLyrics.length,16);
});
+44
View File
@@ -0,0 +1,44 @@
const {chromium}=require(process.env.PLAYWRIGHT_MODULE||'playwright');
const fs=require('node:fs'),assert=require('node:assert/strict');
const html=fs.readFileSync('target/lyrics-admin-fixture.html','utf8'),alpine=fs.readFileSync('target/podcast-alpine.min.js','utf8');
(async()=>{
const browser=await chromium.launch({headless:true,...(process.env.CHROME_PATH?{executablePath:process.env.CHROME_PATH}:{})});
try {
for(const viewport of [{width:1440,height:1000},{width:390,height:844}]){
const page=await browser.newPage({viewport}),errors=[];page.on('pageerror',e=>errors.push(e.message));
await page.route('**/*',route=>{
const url=new URL(route.request().url());
if(url.hostname==='lyrics-admin.test'&&url.pathname==='/')return route.fulfill({contentType:'text/html',body:html});
if(url.hostname==='cdn.jsdelivr.net'&&url.pathname.includes('alpine'))return route.fulfill({contentType:'application/javascript',body:alpine});
if(url.hostname==='cdn.jsdelivr.net')return route.fulfill({contentType:'application/javascript',body:'window.lucide={createIcons(){}};'});
return route.fulfill({json:{items:[],total:0}});
});
await page.goto('http://lyrics-admin.test/');await page.waitForFunction(()=>window.Alpine?.$data(document.querySelector('.admin-shell'))?.routeReady);
await page.evaluate(()=>{
const app=Alpine.$data(document.querySelector('.admin-shell'));
app.activeLibraryItem={kind:'tracks',id:1,title:'Example song'};
app.editorDetail={item:app.activeLibraryItem,metadata_tags:[],artists:[],releases:[]};
app.editorDraft={title:'Example song',hidden:'false',artist_ids:[],release_id:1,release_tracks:[]};
app.editorLyrics=[{id:'original',label:'Original',source:'lrclib',source_id:'123',language:'en',plain_text:'Words of a song',synced_lrc:'[00:12.50]Words of a song',instrumental:false}];
app.editorLoading=false;app.editorOpen=true;
});
await page.waitForSelector('.lyrics-editor textarea');
await page.locator('.lyrics-editor').getByRole('button',{name:'Add version',exact:true}).click();
await page.waitForFunction(()=>document.querySelectorAll('.lyrics-editor-version').length===2);
assert.equal(await page.locator('.lyrics-editor-version').count(),2);
await page.locator('.lyrics-editor-version').nth(1).getByLabel('Plain text',{exact:true}).fill('A second version');
await page.locator('.lyrics-editor').getByText('Retry LRCLIB lookup on the next run',{exact:false}).click();
assert.equal(await page.evaluate(()=>Alpine.$data(document.querySelector('.admin-shell')).editorLyricsRetry),true);
const checkbox=await page.locator('.lyrics-editor input[type=checkbox]').first().boundingBox();assert.ok(checkbox.width<=20&&checkbox.height<=20);
await page.locator('.lyrics-editor').scrollIntoViewIfNeeded();
await page.screenshot({path:`target/lyrics-admin-${viewport.width}.png`,fullPage:true});
const outside=await page.locator('.lyrics-editor-version').evaluateAll(elements=>elements.some(el=>el.getBoundingClientRect().right>innerWidth));assert.equal(outside,false);
await page.evaluate(()=>{const app=Alpine.$data(document.querySelector('.admin-shell'));app.editorOpen=false;app.activeView='settings';});
const toggle=page.locator('#settings-lyrics input[type=checkbox]');await toggle.waitFor({state:'visible'});
const toggleBox=await toggle.boundingBox();assert.ok(toggleBox.width<=20&&toggleBox.height<=20);
assert.equal(await toggle.isChecked(),true);
assert.deepEqual(errors,[]);await page.close();
}
console.log('Lyrics admin desktop/mobile checks passed.');
}finally{await browser.close();}
})().catch(e=>{console.error(e);process.exitCode=1;});
+59
View File
@@ -0,0 +1,59 @@
// Render with FURU_PODCAST_RENDER_FIXTURE=1 cargo test renders_podcast_navigation_and_views.
const {chromium}=require(process.env.PLAYWRIGHT_MODULE||'playwright');
const fs=require('node:fs'),assert=require('node:assert/strict');
const html=fs.readFileSync('target/podcast-player-fixture.html','utf8');
const alpine=fs.readFileSync('target/podcast-alpine.min.js','utf8');
const track={id:1,title:'A song with synchronized lyrics',artists:[{id:1,name:'Example artist'}],duration_seconds:120,has_lyrics:true,release_title:'Album'};
const text=Array.from({length:24},(_,i)=>`[00:${String(i*2).padStart(2,'0')}.00] ${i===3?'<img src=x onerror=alert(1)>':`Line ${i+1} of the song`}`).join('\n');
(async()=>{
const browser=await chromium.launch({headless:true,...(process.env.CHROME_PATH?{executablePath:process.env.CHROME_PATH}:{})});
try {
for(const viewport of [{width:1440,height:1000},{width:390,height:844}]){
const page=await browser.newPage({viewport,reducedMotion:'reduce'}),errors=[];
page.on('pageerror',e=>errors.push(e.message));
await page.route('**/*',async route=>{
const u=new URL(route.request().url());
if(u.hostname==='lyrics-ui.test'&&u.pathname==='/') return route.fulfill({contentType:'text/html',body:html});
if(u.hostname==='cdn.jsdelivr.net'&&u.pathname.includes('alpine'))return route.fulfill({contentType:'application/javascript',body:alpine});
if(u.pathname==='/api/player/lyrics/1')return route.fulfill({json:{versions:[{id:'plain',label:'Plain translation',plain_text:'A plain text translation',source:'manual'},{id:'timed',label:'Original',synced_lrc:text,source:'lrclib'}]}});
if(u.pathname==='/api/player/lyrics/2')return route.fulfill({json:{versions:[]}});
if(u.pathname==='/api/player/lyrics/3')return route.fulfill({json:{versions:[{id:'plain',label:'Plain',plain_text:'Third track lyrics\nAnother line',source:'manual'}]}});
if(u.pathname==='/api/player/artists')return route.fulfill({json:{items:[],total:0,has_more:false}});
if(u.pathname.startsWith('/api/'))return route.fulfill({json:[]});
return route.fulfill({status:404,body:''});
});
await page.goto('http://lyrics-ui.test/');
await page.waitForFunction(()=>window.Alpine?.store('lyrics')&&Alpine.store('player'));
await page.evaluate(t=>{Alpine.store('player').currentTrack=t;Alpine.store('player').currentTime=0;},track);
if(viewport.width<700) await page.evaluate(()=>Alpine.store('mobile').playerExpanded=true);
await page.locator('.lyrics-toggle:visible').first().click();
await page.waitForSelector('.lyrics-line').catch(async error=>{console.error({viewport,errors,state:await page.evaluate(()=>({visible:Alpine.store('lyrics').visible,loading:Alpine.store('lyrics').loading,error:Alpine.store('lyrics').error,track:Alpine.store('lyrics').track,versions:Alpine.store('lyrics').versions,lines:Alpine.store('lyrics').lines}))});await page.screenshot({path:'target/lyrics-error.png'});throw error;});
assert.equal(await page.locator('.lyrics-fullscreen').count(),1);
assert.equal(await page.locator('.lyrics-line').count(),24);
assert.equal(await page.locator('.lyrics-line img').count(),0,'lyrics are text, never HTML');
await page.evaluate(()=>Alpine.store('player').currentTime=30);
await page.waitForFunction(()=>document.querySelector('.lyrics-line.active')?.textContent==='Line 16 of the song');
await page.waitForFunction(()=>document.querySelector('.lyrics-scroll').scrollTop>100);
await page.screenshot({path:`target/lyrics-${viewport.width}.png`,fullPage:true});
const bounds=await page.locator('.lyrics-dialog').boundingBox();
assert.equal(Math.round(bounds.width),viewport.width);assert.equal(Math.round(bounds.height),viewport.height);
assert.equal(await page.evaluate(()=>document.documentElement.scrollWidth>innerWidth),false);
await page.selectOption('#lyrics-version','1');
await page.waitForFunction(()=>document.querySelector('.lyrics-plain')?.textContent==='A plain text translation');
await page.evaluate(()=>{Alpine.store('player').currentTrack={id:2,title:'No lyrics',artists:[]};Alpine.store('player').currentTime=0;});
await page.waitForFunction(()=>Alpine.store('lyrics').loadedKey==='2'&&!Alpine.store('lyrics').loading);
assert.equal(await page.locator('.lyrics-fullscreen').count(),1);assert.equal(await page.locator('.lyrics-line').count(),0);
await page.evaluate(()=>Alpine.store('player').currentTrack={id:3,title:'Plain lyrics track',artists:[]});
await page.waitForFunction(()=>document.querySelector('.lyrics-plain')?.textContent.includes('Third track'));
await page.keyboard.press('Escape');assert.equal(await page.locator('.lyrics-overlay').count(),0);
await page.evaluate(t=>Alpine.store('library').openTrackInfo(t),track);
await page.getByRole('button',{name:'Available · view',exact:true}).click();
await page.waitForSelector('.lyrics-line');
assert.equal(await page.locator('.lyrics-fullscreen').count(),0);
assert.ok((await page.locator('.lyrics-dialog').boundingBox()).height<viewport.height);
assert.deepEqual(errors,[]);
await page.close();
}
console.log('Lyrics desktop/mobile browser checks passed.');
} finally {await browser.close();}
})().catch(e=>{console.error(e);process.exitCode=1;});
+55
View File
@@ -0,0 +1,55 @@
const assert=require('node:assert/strict');
const {test}=require('node:test');
const fs=require('node:fs'),vm=require('node:vm');
const source=fs.readFileSync(`${__dirname}/../templates/player/lyrics_scripts.html`,'utf8').replace(/<\/?script>/g,'');
function setup(fetchImpl=async()=>({ok:true,json:async()=>({versions:[]})})) {
const stores={player:{currentTrack:{id:1,title:'One'},currentTime:0,seek(time){this.currentTime=time;}},info:{close(){}}};
const document={documentElement:{lang:'en'},body:{style:{overflow:''}},activeElement:{focus(){}},addEventListener(_,fn){fn();},querySelector(){return null;}};
vm.runInNewContext(source,{document,Alpine:{store(name,value){if(value)stores[name]=value;return stores[name];}},GUEST:false,SHARE_TOKEN:'',fetch:fetchImpl,Date,requestAnimationFrame:fn=>fn(),window:{matchMedia:()=>({matches:true})}});
return {store:stores.lyrics,stores,document};
}
const plain={id:'plain',label:'Plain',plain_text:'Plain words',synced_lrc:null};
const timed={id:'timed',label:'Timed',plain_text:'Timed words',synced_lrc:'[00:02.00]First\n[00:05.50]Second'};
const settle=()=>new Promise(resolve=>setImmediate(resolve));
test('LRC parses repeated timestamps, offsets and malformed tags',()=>{
const {store}=setup();
assert.deepEqual(JSON.parse(JSON.stringify(store.parse('[ar:Artist]\n[offset:-500]\n[00:02.50][01:03] words\n[00:00.1]start\n[00:60]bad'))),[{ms:0,text:'start'},{ms:2000,text:'words'},{ms:62500,text:'words'}]);
assert.equal(store.parse('plain\n[00:NaN]bad').length,0);
});
test('timed version is selected first; playback and backward seeks select the correct line',async()=>{
const {store,stores}=setup(async()=>({ok:true,json:async()=>({versions:[plain,timed]})}));
store.open(stores.player.currentTrack,true);await settle();
assert.equal(store.currentVersion().id,'timed');
store.tick(stores.player.currentTrack,1);assert.equal(store.active,-1);
store.tick(stores.player.currentTrack,6);assert.equal(store.active,1);
store.tick(stores.player.currentTrack,3);assert.equal(store.active,0);
store.seek(store.lines[1]);assert.equal(stores.player.currentTime,5.5);
store.choose(1);assert.equal(store.plain(),'Plain words');assert.equal(store.lines.length,0);
});
test('late responses cannot overwrite a new track; fullscreen stays open across misses',async()=>{
let resolveFirst;
const first=new Promise(resolve=>resolveFirst=resolve);
const {store,stores}=setup(async url=>url.endsWith('/1')?first:{ok:true,json:async()=>({versions:[]})});
store.open(stores.player.currentTrack,true);
stores.player.currentTrack={id:2,title:'Two'};
store.tick(stores.player.currentTrack,0);await settle();
resolveFirst({ok:true,json:async()=>({versions:[timed]})});await settle();
assert.equal(store.track.id,2);assert.equal(store.versions.length,0);assert.equal(store.visible,true);
stores.player.currentTrack={id:3,title:'Three'};store.tick(stores.player.currentTrack,0);await settle();
assert.equal(store.track.id,3);
});
test('preview does not follow playback or seek a different track; close restores scrolling',async()=>{
const {store,stores,document}=setup(async()=>({ok:true,json:async()=>({versions:[timed]})}));
store.open({id:9,title:'Preview'},false);await settle();
store.tick(stores.player.currentTrack,10);assert.equal(store.track.id,9);assert.equal(store.active,-1);
store.seek(store.lines[0]);assert.equal(stores.player.currentTime,0);
assert.equal(document.body.style.overflow,'hidden');store.close();assert.equal(document.body.style.overflow,'');
});
test('errors remain retryable and podcast transitions clear previous lyrics',async()=>{
let fail=true;
const {store,stores}=setup(async()=>{if(fail)throw Error('offline');return {ok:true,json:async()=>({versions:[timed]})};});
store.open(stores.player.currentTrack,true);await settle();assert.equal(store.error,true);
fail=false;await store.load(stores.player.currentTrack);assert.equal(store.error,false);assert.equal(store.lines.length,2);
stores.player.currentTrack={id:'ep1:one',podcast:{}};store.tick(stores.player.currentTrack,0);
assert.equal(store.versions.length,0);assert.equal(store.visible,true);
});