play_similar
Find and play related videos from the same channel to continue watching similar content. Automatically queues or replaces playback based on your selection.
Instructions
Play videos similar to what is currently playing. Fetches the current video's channel and searches for related content, then queues or plays the results.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| limit | No | Number of similar videos to find (default 10) | |
| play_now | No | Replace current playback (true) or add to queue (false) |
Implementation Reference
- src/index.ts:588-633 (handler)The handler function that executes the 'play_similar' tool logic. It checks if a video is playing, searches for related content based on the current title, and then either plays the similar videos immediately or adds them to the queue.
async ({ limit, play_now }) => { const depErr = checkDeps(); if (depErr) return errorResult(depErr); if (!mpv.isPlaying()) return errorResult('No video is currently playing.'); let currentTitle: string; try { currentTitle = (await mpv.getProperty('media-title')) as string; if (!currentTitle) return errorResult('Cannot determine current video title.'); } catch { return errorResult('Cannot get current video info. Is a video playing?'); } try { const result = await fetchFeed( `https://www.youtube.com/results?search_query=${encodeURIComponent(currentTitle)}`, limit + 5 // fetch extra to filter out the current video ); const videos = (result.entries || []) .filter((e) => e.title !== currentTitle) .slice(0, limit); if (videos.length === 0) return textResult('No similar videos found.'); if (play_now) { const urls = videos.map((e) => e.url as string).filter(Boolean); const playlistFile = mpv.writeTempPlaylist(urls); await mpv.launch({ playlistFile, socketTimeoutMs: 15_000 }); let title = 'Similar videos'; try { title = (await mpv.getProperty('media-title')) as string || title; } catch { /* loading */ } return textResult({ status: 'playing_similar', basedOn: currentTitle, title, total: urls.length }); } else { let queued = 0; for (const e of videos) { const vUrl = e.url as string; if (vUrl) { await mpv.appendUrl(vUrl); queued++; } } return textResult({ status: 'queued_similar', basedOn: currentTitle, queued }); } } catch (err) { return errorResult(`Error: ${err instanceof Error ? err.message : String(err)}`); } } - src/index.ts:581-587 (registration)Tool registration for 'play_similar', including description and input validation schema definition.
server.tool( 'play_similar', 'Play videos similar to what is currently playing. Fetches the current video\'s channel and searches for related content, then queues or plays the results.', { limit: z.number().min(1).max(20).default(10).describe('Number of similar videos to find (default 10)'), play_now: z.boolean().default(false).describe('Replace current playback (true) or add to queue (false)'), },