Something went wrong. Try again.
A concatenating Youtube uploader
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171# ytcat
`ytcat` concatenates video files without re-encoding and uploads the result toYouTube for archival. Concatenation and upload run as a single stream: ffmpegwrites MPEG-TS to stdout, and `ytcat` feeds that pipe straight into YouTube'sresumable upload API. The video data is never written to disk and nothing needsto seek; only a small concat playlist file is placed in the system tempdirectory.
## Requirements
A Nix flake is included. It pins the stable `nixos-26.05` channel and provides`ffmpeg`, `go_1_27` and `golangci-lint`:
```shnix develop# or, with direnv:direnv allow```
`ffmpeg` must also be on `PATH` when running `ytcat`, unless `-ffmpeg` is givenor `nix` is available (see below).
### Running without installing ffmpeg
On a Nix system, `ytcat` can obtain ffmpeg without installing it into the useror system environment. Build it as usual:
```shgo build -o ytcat .```
At runtime, ffmpeg is resolved in this order:
1. the executable given with `-ffmpeg <path>` (fails if it does not exist)2. `ffmpeg` in `PATH`3. `nix shell nixpkgs#ffmpeg -c ffmpeg`
The last step requires `nix` with flakes enabled and fetches ffmpeg from the`nixpkgs` flake registry on first use.
## One-time YouTube setup
1. Create a project in the [Google Cloud Console](https://console.cloud.google.com/).2. Enable the **YouTube Data API v3**.3. Configure the OAuth consent screen (an "External" app in testing mode is enough for personal use; add your Google account as a test user).4. Create an OAuth client ID of type **Desktop app** and download the JSON.5. Place it at `~/.config/ytcat/client_secret.json` (or pass `-client-secret`).6. If you want to use `-wait`, add the `https://www.googleapis.com/auth/youtube.readonly` scope to the OAuth consent screen's scopes (Data access). It is a sensitive scope; an app in testing mode with your own account as a test user is sufficient.
On the first upload, `ytcat` prints a URL. Open it, approve access, and the tokenis cached at `~/.config/ytcat/token.json` (override with `-token`). You can run`ytcat -auth` to complete this step without uploading; it requests both theupload and read-only scopes. Existing tokens created before `-wait` supportare re-authorized automatically the first time `-wait` needs read access. Toforce a fresh consent, delete the token file.
For backwards compatibility, if a file does not exist under `~/.config/ytcat`,`ytcat` falls back to the pre-rename `~/.config/yup` path for the OAuth clientsecret and token cache. Existing installations therefore keep working withoutre-authentication.
### Authenticating from a remote or headless machine
The default `-auth` flow listens for the OAuth callback on the machine running`ytcat`. If that machine cannot receive the browser callback, use one of these:
1. **Copy the token (simplest).** Run `ytcat -auth` on a machine with a browser, then copy `~/.config/ytcat/token.json` to the same path on the remote host. The file contains a refresh token, so transfer it securely and keep it mode `0600`.2. **Paste the redirect URL.** Run `ytcat -auth-manual` on the remote host. Open the printed URL in any browser. After approving, the browser will try to open `http://127.0.0.1:8090/...` and probably fail; copy the full URL from the address bar and paste it back into `ytcat`. Change the port with `-auth-port`.3. **SSH port forwarding.** Run `ytcat -auth -auth-port 8090` on the remote host and `ssh -L 8090:127.0.0.1:8090 user@remote` from your local machine. Then open the printed URL locally; the callback reaches the remote `ytcat` through the tunnel.
## Usage
```shytcat [flags] video1.mp4 video2.mp4 ...```
Common flags:
| Flag | Default | Meaning || --- | --- | --- || `-title` | first file name | video title || `-description` | empty | video description || `-tags` | empty | comma-separated tags || `-category` | `22` | YouTube category ID (22 = People & Blogs) || `-privacy` | `private` | `private`, `unlisted` or `public` || `-client-secret` | `~/.config/ytcat/client_secret.json` | OAuth client JSON || `-token` | `~/.config/ytcat/token.json` | OAuth token cache || `-dry-run` | `false` | write the TS stream to stdout, do not upload || `-ffmpeg` | from `PATH`, then `nix` | ffmpeg executable; must exist if set || `-i` | `false` | prompt for title, description, visibility and category || `-wait` | `false` | wait for YouTube processing to finish (requires `youtube.readonly`) || `-check` | | poll an existing video ID's processing status and exit || `-auth` | `false` | authenticate with YouTube and exit || `-auth-manual` | `false` | authenticate by pasting the redirect URL (no callback) || `-auth-port` | `0` | callback port (0 = ephemeral; manual defaults to 8090) || `-quiet` | `false` | suppress ffmpeg output and the progress bar || `-verbose` | `false` | verbose ffmpeg logging; disables the progress bar |
By default, `ytcat` shows a progress bar with the transfer rate and an ETA basedon the total input file size. `-verbose` and `-quiet` disable it and aremutually exclusive.
With `-i`, `ytcat` prompts for the title, description, visibility and category,using the current values as defaults. The category is selected by number from atable of the standard YouTube categories.
With `-wait`, `ytcat` polls `videos.list` until YouTube reports processing as`succeeded` or `failed`, printing processing progress and YouTube's estimatedtime remaining. This requests the`https://www.googleapis.com/auth/youtube.readonly` scope in addition to`youtube.upload`. `-check <videoID>` polls an existing video the same waywithout uploading or requiring ffmpeg.
Examples:
```sh# Upload two files as a private videoytcat -title "Archive 2024-01" -tags "archive,backup" part1.mp4 part2.mp4
# Enter the metadata interactivelyytcat -i part1.mp4 part2.mp4
# Check an existing uploadytcat -check dQw4w9WgXcQ
# Authenticate without uploadingytcat -auth
# Authenticate on a remote host without an HTTP callbackytcat -auth-manual
# Inspect the concatenated stream locallyytcat -dry-run part1.mp4 part2.mp4 > combined.ts```
## Limitations
- The inputs must be compatible for stream copy: same codecs and codec parameters (resolution, pixel format, sample rate, ...). ffmpeg cannot concatenate arbitrary formats without re-encoding.- YouTube receives an MPEG-TS upload (`video/mp2t`) and transcodes it as usual.- A successful upload means YouTube has received the file. Processing (checks, transcoding, visibility) continues asynchronously, so YouTube Studio can show 0% and "checks starting soon" for a while. `ytcat` prints the returned `uploadStatus` (`uploaded` or `processed`).- If ffmpeg fails after YouTube accepted the stream, the upload is not rolled back automatically.
## Development
```shnix developgolangci-lint run ./...go test ./...```