Skip to content

sh4869221b/go-nico-list

Repository files navigation

go-nico-list

Command line tool to fetch video IDs from a niconico user page.

Japanese README

Overview

Fetches video IDs from one or more nicovideo.jp/user/<id> pages, filters them by comment count and date range, sorts the results, and prints them to stdout.

Install

Go install

go install github.com/sh4869221b/go-nico-list@latest

Prebuilt binaries

Prebuilt binaries are available on the GitHub Releases page.

Usage

go-nico-list [nicovideo.jp/user/<id>...] [flags]

Examples:

go-nico-list nicovideo.jp/user/12345
go-nico-list https://www.nicovideo.jp/user/12345/video --url
go-nico-list nicovideo.jp/user/1 nicovideo.jp/user/2 --concurrency 10
go-nico-list --input-file users.txt
cat users.txt | go-nico-list --stdin

Output

  • One video ID per line (example: sm123).
  • With --url, each line is prefixed with https://www.nicovideo.jp/watch/.
  • With --tab, each line is prefixed with tabs.
  • With --json, stdout is a single JSON object (line output is disabled).

Exit status

  • 0: no fetch errors (invalid inputs are skipped; may produce no output).
  • non-zero: at least one fetch failed (any successfully retrieved IDs are still printed).
  • Validation errors (for example, --concurrency < 1) return non-zero.
  • context.Canceled / context.DeadlineExceeded during fetch is treated as a successful empty result.

Flags

Flag Description Default
-c, --comment lower comment limit number 0
-a, --dateafter date YYYYMMDD after 10000101
-b, --datebefore date YYYYMMDD before 99991231
-t, --tab id tab separated flag false
-u, --url output id add url false
-n, --concurrency number of concurrent requests 3
--rate-limit maximum requests per second (0 disables) 0
--min-interval minimum interval between requests 0s
--max-pages maximum number of pages to fetch 0
--max-videos maximum number of filtered IDs to collect 0
--timeout HTTP client timeout 10s
--retries number of retries for requests 10
--input-file read inputs from file (newline-separated) ""
--stdin read inputs from stdin (newline-separated) false
--logfile log output file path ""
--progress force enable progress output false
--no-progress disable progress output false
--strict return non-zero if any input is invalid false
--best-effort always exit 0 while logging fetch errors false
--dedupe remove duplicate output IDs before sorting false
--json emit JSON output to stdout false

Notes:

  • Inputs can be provided via arguments, --input-file, and --stdin (newline-separated).
  • Input lines from --input-file and --stdin are limited to 1 MiB per line; longer lines fail with an input read error.
  • Each input must contain nicovideo.jp/user/<id> (scheme optional). Plain digits or user/<id> without the domain are treated as invalid inputs and skipped.
  • Results are written to stdout; progress and logs are written to stderr. Use --logfile to redirect logs to a file.
  • Setting concurrency or retries to a value less than 1, or timeout to a value less than or equal to 0, will cause a runtime error.
  • --dateafter must be on or before --datebefore; inverted ranges return a validation error.
  • --max-pages and --max-videos are safety caps; 0 disables them.
  • When a safety cap is hit, fetching stops early and returns best-effort results without error.
  • Responses with HTTP status other than 200/404 after retries are treated as fetch errors.
  • HTTP 200 responses with meta.status != 200 are logged as warnings but still processed.
  • Rate limiting applies globally to all requests (including retries). HTTP 429 Retry-After is honored when present.
  • Progress is auto-disabled when stderr is not a TTY. Use --progress to force-enable or --no-progress to disable (takes precedence).
  • A run summary is printed to stderr after processing (even when the exit code is non-zero).
  • --strict makes invalid inputs return a non-zero exit code while still outputting valid results.
  • --best-effort forces exit code 0 even when fetch errors occur (errors are still logged).
  • --dedupe removes duplicate video IDs before sorting/output.
  • --json emits a single JSON object to stdout. --tab/--url do not affect JSON items, and the summary still prints to stderr.
  • In JSON output, users are sorted by numeric user_id in ascending order.

Design

This project separates the CLI layer from the domain logic so each part is easier to test and maintain.

  • main.go: resolves the version and bootstraps the CLI with a cancellation-aware context.
  • cmd/: Cobra command definitions, flags, and input/output handling (stdout/stderr separation).
  • internal/niconico/: core domain logic (fetching video lists, retries, sorting) and API response types.

Flow

  1. The CLI parses flags and user IDs.
  2. The command layer calls internal/niconico to fetch and filter video IDs.
  3. Results are sorted and printed; progress is written to stderr.

CI

GitHub Actions runs on pull requests to master and pushes to master, and enforces:

  • repository ruleset protection on master (PR-only updates with required go-ci status checks)
  • generated file checks (go mod tidy, go generate ./..., git diff --exit-code)
  • third-party notice sync (bash scripts/gen-third-party-notices.sh, git diff --exit-code -- THIRD_PARTY_NOTICES.md)
  • gofmt (format + diff check)
  • go vet ./...
  • go test -count=1 ./...
  • go test -race -count=1 ./...
  • GitHub Actions references are pinned to commit SHAs in workflow files.

Test layers

  • Integration-style command wiring tests: cmd/root_test.go (httptest + stdout/stderr/exit-code checks).
  • Contract tests: internal/niconico/nico_data_contract_test.go (fixture decode from internal/niconico/testdata/).
  • Fuzz tests: internal/niconico/fuzz_test.go, cmd/root_fuzz_test.go (sorting/JSON/url-parse panic safety).
  • E2E tests (opt-in): internal/niconico/e2e_test.go with -tags=e2e.
  • Benchmarks (opt-in): internal/niconico/benchmark_test.go.

Opt-in commands:

go test ./internal/niconico -run TestNicoDataContract -count=1
go test ./... -run=^$ -fuzz=Fuzz -fuzztime=10s
GO_NICO_LIST_E2E_USER_ID=<user-id> go test -tags=e2e ./internal/niconico -run TestGetVideoListE2E -count=1
go test ./internal/niconico -run=^$ -bench=BenchmarkNiconicoSort -benchmem -count=1

Contributing

See CONTRIBUTING.md.

Release

Releases are published by tagging a version and pushing it to GitHub.

  1. Create a tag like vX.Y.Z.
  2. Push the tag to GitHub.
  3. GitHub Actions runs the release workflow (verifies go mod tidy/go generate ./..., runs gofmt/go vet/go test/go test -race, and checks third-party notices).
  4. GoReleaser publishes the GitHub Release and uploads artifacts.
  5. Close the milestone after the release workflow succeeds.

Notes:

  • When a versioned milestone is complete, release using the same version number.
  • Release tags (vX.Y.Z) are governed by a repository tag ruleset.

About

Command line tool to get video list from niconico userID

Resources

License

Contributing

Stars

Watchers

Forks

Packages

 
 
 

Contributors