---
# System prepended metadata

title: yt-dlp 功能紀錄

---

<style>
    .better_eng{
        font-family:consolas;
    }
</style>

# yt-dlp 功能紀錄



## using Cmd

<span class = "better_eng">print out every format available</span>

```
yt-dlp -F [url]
```

```
yt-dlp --format [format_id] -o "%(title)s.%(ext)s" [url]
```

<span class = "better_eng">available options list</span>
https://github.com/yt-dlp/yt-dlp#usage-and-options

<span class = "better_eng">use bestvideo+bestaudio</span>
<span class = "better_eng">To merge these two into one single video requires FFmpeg to be installed.</span>

<span class = "better_eng">output template options</span>
https://github.com/yt-dlp/yt-dlp#output-template

[Built-in Types — Python 3.11.3 documentation](https://docs.python.org/3/library/stdtypes.html#printf-style-string-formatting)


```
yt-dlp "ytsearch[x]:[keywords]"
```
<span class = "better_eng">it'll search youtube and print out top [x] results. Can be used with --cookies-from-browser [browser] or login stuff</span>


<span class = "better_eng">download streams</span>

```
yt-dlp --live-from-start [url]
```




## using python module

<span class = "better_eng">YoutubeDL options</span>
[yt-dlp/YoutubeDL.py at master · yt-dlp/yt-dlp (github.com)](https://github.com/yt-dlp/yt-dlp/blob/master/yt_dlp/YoutubeDL.py#L184)
<span class = "better_eng">main usage:using dict to change options</span>


![](https://i.imgur.com/5LgVlZ4.png)

```python
"""from subprocess import run

search = input("輸入想搜尋的關鍵字\n")
cmd = f'yt-dlp "ytsearch5:{search}" --get-title --get-id --cookies-from-browser edge'


title_output = run(cmd, capture_output=True).stdout
title_output = title_output.decode(encoding="utf-8")
title_output = title_output.splitlines()
for idx,title in enumerate(title_output):
    if idx %2 == 0:
        print(title)
    elif idx%2 != 0:
        print(f"https://youtu.be/{title}")
"""

import yt_dlp


options = {
    "outtmpl":"%(title)s.%(ext)s",
    "default_search":"auto",
    "cookiesfrombrowser":("edge", )
}

with yt_dlp.YoutubeDL(options) as ytdl:
    info = ytdl.extract_info(url = "ytsearch5:Hoshimachi suisei", download = False)
    print(info.keys())
    for ent in info["entries"]:
        print(ent["title"])
        print(f"https://youtu.be/{ent['id']}")

```
