feat(booklet): Allow booklet detection #2
This commit is contained in:
		
							parent
							
								
									c85737a57d
								
							
						
					
					
						commit
						d94735a9e8
					
				
					 1 changed files with 29 additions and 5 deletions
				
			
		|  | @ -1,4 +1,4 @@ | ||||||
| import {firefox, Page, BrowserContext, Download, Browser} from 'playwright'; | import {firefox, Page, BrowserContext, Download, Browser, Locator} from 'playwright'; | ||||||
| 
 | 
 | ||||||
| async function lucida(album: URL, baseTimeout: number, context: BrowserContext): Promise<void> { | async function lucida(album: URL, baseTimeout: number, context: BrowserContext): Promise<void> { | ||||||
|     const page: Page = await context.newPage(); |     const page: Page = await context.newPage(); | ||||||
|  | @ -33,6 +33,28 @@ async function lucida(album: URL, baseTimeout: number, context: BrowserContext): | ||||||
|     // TODO Set path (configurable)
 |     // TODO Set path (configurable)
 | ||||||
|     await download.saveAs('/home/tdpeuter/Downloads/lucida/' + download.suggestedFilename()); |     await download.saveAs('/home/tdpeuter/Downloads/lucida/' + download.suggestedFilename()); | ||||||
| 
 | 
 | ||||||
|  |     // TODO Check if booklet is available.
 | ||||||
|  | 
 | ||||||
|  |     await page.close(); | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | async function booklet(album: URL, context: BrowserContext): Promise<void> { | ||||||
|  |     const page: Page = await context.newPage(); | ||||||
|  | 
 | ||||||
|  |     const bookletURL: URL = new URL('http://audiofil.hostronavt.ru/booklet.php?name=' + encodeURIComponent(album.href)); | ||||||
|  |     await page.goto(bookletURL.href); | ||||||
|  | 
 | ||||||
|  |     // Find link with goodies
 | ||||||
|  |     const link: Locator = page.locator('a').filter({hasText: '/goodies/'}); | ||||||
|  |     const linkCount: number = await link.count(); | ||||||
|  |     if (linkCount > 0) { | ||||||
|  |         console.log(await link.innerHTML()); | ||||||
|  |     } else { | ||||||
|  |         console.log('No goodies link found'); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     // TODO Download the booklet.
 | ||||||
|  | 
 | ||||||
|     await page.close(); |     await page.close(); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | @ -43,7 +65,7 @@ async function lucida(album: URL, baseTimeout: number, context: BrowserContext): | ||||||
|         'https://www.qobuz.com/us-en/album/shes-gone-dance-on-disclosure/xrylx7j5794ab', |         'https://www.qobuz.com/us-en/album/shes-gone-dance-on-disclosure/xrylx7j5794ab', | ||||||
|         'https://www.qobuz.com/us-en/album/tondo-disclosure-eko-roosevelt/tlb5v175fbyxb' |         'https://www.qobuz.com/us-en/album/tondo-disclosure-eko-roosevelt/tlb5v175fbyxb' | ||||||
|     ]; |     ]; | ||||||
|     const testAlbums: string[] = [ |     const withBooklet: string[] = [ | ||||||
|         'https://www.qobuz.com/us-en/album/moon-safari-air/0724384497859' |         'https://www.qobuz.com/us-en/album/moon-safari-air/0724384497859' | ||||||
|     ]; |     ]; | ||||||
| 
 | 
 | ||||||
|  | @ -55,9 +77,11 @@ async function lucida(album: URL, baseTimeout: number, context: BrowserContext): | ||||||
|         baseURL: 'https://lucida.to' |         baseURL: 'https://lucida.to' | ||||||
|     }); |     }); | ||||||
| 
 | 
 | ||||||
|     for (const album of testAlbums) { |     // for (const album of testAlbums) {
 | ||||||
|         await lucida(new URL(album), timeout, context); |     //     await lucida(new URL(album), timeout, context);
 | ||||||
|     } |     // }
 | ||||||
|  | 
 | ||||||
|  |     await booklet(new URL(withBooklet[0]), context); | ||||||
| 
 | 
 | ||||||
|     // Close the browser
 |     // Close the browser
 | ||||||
|     await browser.close(); |     await browser.close(); | ||||||
|  |  | ||||||
		Reference in a new issue