Skip to content

Instantly share code, notes, and snippets.

@shaoyanji
Last active January 6, 2026 09:12
Show Gist options
  • Select an option

  • Save shaoyanji/dbe38777514b96d50f81da4bc4ac2992 to your computer and use it in GitHub Desktop.

Select an option

Save shaoyanji/dbe38777514b96d50f81da4bc4ac2992 to your computer and use it in GitHub Desktop.
export def ytsearch [] {
http get https://www.youtube.com/results?search_query=(input "search> " | url encode)
| split row "var ytInitialData ="
| last
| split row ";</script>"
| first
| from json
| get -o contents.twoColumnSearchResultsRenderer.primaryContents.sectionListRenderer.contents.0.itemSectionRenderer.contents.videoRenderer
| uniq | sort | drop
| select title.runs.text.0 videoId
| flatten
| input list -f -d "title.runs.text.0"
| get videoId
| $"https://www.youtube.com/watch?v=($in)"
| mpv --ytdl-format="bv+ba" $"($in)"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment