8

After searching for such a thing for a long time, I've just discovered that yt-dlp, which I already have installed and use daily to download YouTube (and other) videos, supports fetching the user comments and saving them as a JSON file.

But, frustratingly, I cannot find any option to only do that, and not also download the video at the same time. How is that done? Is it even possible? If not, that's such a shame, since this is an amazing "stand-alone" feature which I often want to do without having to also download the massive video file. It's near-impossible to implement myself because YouTube makes it extremely difficult and convoluted to stop bots/automation.

I've looked at this manual for a long time now: https://github.com/yt-dlp/yt-dlp

kirogasa
  • 130
  • 9

4 Answers4

9

You can dump a JSON with --dump-single-json (or simply -J) or use the --no-download parameter.

# writes info.json in working dir
yt-dlp --write-comments --no-download "$url"

dump complete JSON with comments

yt-dlp --write-comments --dump-single-json -o "$file" "$url" yt-dlp --write-comments --dump-single-json "$url" > "$file"

Pretty print with JQ (JSON processor, package needs to be installed)

yt-dlp --write-comments --dump-single-json "$url" | jq yt-dlp --write-comments --dump-single-json "$url" | jq > "$file"

Then, use JQ to query the comments.

jq '.comments' "$file" > comments_only.json # file input
jq '.comments' <<<"$json" > comments_only.json # var input

or

some_command | jq '.comments'

.comments is the JQ selector for the JSON property 'comments' here.

The JQ approach becomes somewhat more complicated if you want to integrate those comments that you isolated with JQ into a another JSON file.

Here is an example where I'm doing this with entries to boost you forward in case you chose to go this route.

  old_json=$(jq '.' "$json_file")
  entries=$(jq -s '.[0].entries += .[1].entries | .[0].entries | sort_by(.date) | reverse' <<<"$old_json" <<<"$json")
  json=$(jq -s '.[0].entries = .[1] | .[0]' <<<"$old_json" <<<"$entries")
progonkpa
  • 271
5

yt-dlp has an option called --skip-download which seems to work for me. Here's the relevant part of the documentation:

--skip-download    Do not download the video but write all related files (Alias: --no-download)
0

I have also looked at the documentation of yt-dlp, and it doesn't seem to have an option for downloading only the comments. You could suggest this feature to the developer.

If you're into programming, you could use the YouTube Data API to get the comments yourself.

The article Extracting & Pre-processing the YouTube Comments contains detailed explanations as well as Python code to extract the comments and write them out as a CSV file. It also contains advice on cleaning out redundant characters such as emojis and language detection (if you want only English comments).

harrymc
  • 498,455
-1

I'm using --get-description. It downloads the description of the Video, not the user comments.

It is an option from YouTube-dl and it is still working in yt-dlp.

gx360
  • 1