# How Postfix and Prefix Options Modify Output Filenames in you-get

> Learn how you-get's postfix and prefix options customize output filenames. Discover how to prepend strings and append video IDs for better file organization.

- Repository: [Mort Yao/you-get](https://github.com/soimort/you-get)
- Tags: internals
- Published: 2026-03-06

---

**The `--pre` (prefix) option prepends a bracketed string to the video title, while the `--post` (postfix) option appends the video ID in brackets, with both modifications applied in [`src/you_get/common.py`](https://github.com/soimort/you-get/blob/main/src/you_get/common.py) before the final filename is generated.**

When downloading media with **you-get**, the tool automatically derives output filenames from the detected video title. However, the **postfix and prefix options modify output filenames** to help you organize downloads by adding custom identifiers or unique video IDs. These options are processed in the core download routine before file writing begins.

## Understanding the Prefix Option (--pre)

The **prefix** option allows you to prepend a custom label to every downloaded file.

### How Prefix Modifies Filenames

When you invoke `you-get --pre "Label"`, the tool wraps your supplied string in square brackets and inserts it at the beginning of the title. The resulting filename follows this pattern:

```

[Label] OriginalVideoTitle.mp4

```

For example, downloading a lecture series with `--pre "Lecture"` transforms `Introduction_to_Python.mp4` into `[Lecture] Introduction_to_Python.mp4`.

### Implementation in common.py

The prefix logic resides in [`src/you_get/common.py`](https://github.com/soimort/you-get/blob/main/src/you_get/common.py). The command-line argument parser stores the value in a global `prefix` variable at line 1022. During filename construction, the code applies the transformation using Python string formatting:

```python
title = "[%s] %s" % (prefix, title)

```

This modification occurs before the extension is appended and before the final path is resolved.

## Understanding the Postfix Option (--post)

The **postfix** option appends the unique video identifier (VID) provided by the site extractor, ensuring you can distinguish between different versions or resolutions of the same title.

### How Postfix Modifies Filenames

When enabled with `--post`, you-get checks if the extractor provided a `vid` keyword argument. If present, the tool appends this ID in square brackets to the title:

```

OriginalVideoTitle [12345678].mp4

```

This is particularly useful when downloading from platforms where the same title might refer to multiple uploads or when you need to reference the original video ID later.

### Implementation Details

In [`src/you_get/common.py`](https://github.com/soimort/you-get/blob/main/src/you_get/common.py) (lines 1020-1022), the postfix application checks for the `postfix` flag and the presence of `vid` in the extractor's keyword arguments:

```python
if postfix and 'vid' in kwargs:
    title = "%s [%s]" % (title, kwargs['vid'])

```

The `vid` value is typically extracted by site-specific extractors in [`src/you_get/extractor.py`](https://github.com/soimort/you-get/blob/main/src/you_get/extractor.py) or its subclasses, which parse the video metadata from the source platform.

## Order of Operations: How Both Options Work Together

When you specify both **postfix and prefix options modify output filenames** in a single command, you-get applies them in a specific sequence to ensure predictable results.

The transformation order is:

1. **Postfix first**: The video ID is appended to the original title.
2. **Prefix second**: The custom label is prepended to the potentially postfixed title.

This sequence ensures that the prefix appears at the very beginning of the filename, while the postfix remains attached to the title content. For example:

```bash
you-get --pre "Course" --post "https://example.com/video/12345"

```

Produces:

```

[Course] Introduction_to_Python [12345].mp4

```

## Practical Examples

Here are concrete command-line examples demonstrating how **postfix and prefix options modify output filenames** in real-world usage:

### Basic Prefix Usage

```bash

# Download with a descriptive prefix

you-get --pre "Lecture_01" "https://www.bilibili.com/video/av123456"

# Output: [Lecture_01] Video_Title.mp4

```

### Basic Postfix Usage

```bash

# Download with video ID appended

you-get --post "https://www.youtube.com/watch?v=dQw4w9WgXcQ"

# Output: Video_Title [dQw4w9WgXcQ].mp4

```

### Combined Usage with Custom Output Directory

```bash

# Organize course materials with both options

you-get --pre "CS101" --post -o ./downloads/ "https://vimeo.com/123456789"

# Output: ./downloads/[CS101] Video_Title [123456789].mp4

```

### Batch Processing with Prefix

When processing playlists, the prefix applies to every item:

```bash

# Download entire playlist with series identifier

you-get --pre "Tutorial_Series" "https://www.youtube.com/playlist?list=PL..."

# Results in: [Tutorial_Series] Video_1 [vid1].mp4, [Tutorial_Series] Video_2 [vid2].mp4, etc.

```

## Summary

The **postfix and prefix options modify output filenames** in you-get by altering the detected media title before the final path is constructed:

- **Prefix (`--pre`)**: Prepends a user-defined string in square brackets to the title, implemented in [`src/you_get/common.py`](https://github.com/soimort/you-get/blob/main/src/you_get/common.py) using `title = "[%s] %s" % (prefix, title)`.
- **Postfix (`--post`)**: Appends the extractor-provided video ID in square brackets, applied when `postfix` is enabled and `vid` exists in `kwargs`.
- **Application Order**: Postfix is applied first, then prefix, ensuring the custom label appears at the absolute beginning of the filename.
- **Use Cases**: Prefixes help organize content by category or course name, while postfixes ensure unique identification when titles collide or when referencing original platform IDs.

## Frequently Asked Questions

### Can I use both prefix and postfix options simultaneously?

Yes, you-get supports using both options in the same command. The tool applies the postfix first (appending the video ID), then prepends the prefix to the resulting string. This produces filenames like `[Prefix] Title [VideoID].ext`, allowing you to categorize downloads while maintaining unique identifiers.

### What happens if the video extractor does not provide a vid parameter?

If you enable `--post` but the specific site extractor does not supply a `vid` keyword argument, the postfix modification is skipped. The filename will use only the detected title (plus any prefix you specified). Not all extractors in [`src/you_get/extractor.py`](https://github.com/soimort/you-get/blob/main/src/you_get/extractor.py) provide video IDs, so the postfix option works only on supported sites.

### Do prefix and postfix affect temporary files during multi-part downloads?

Yes, the modifications apply to the base title used for all file operations, including temporary `.download` files and video segments before merging. When you-get downloads large files in chunks or separate audio/video streams, it uses the modified title (with prefix and/or postfix) as the basename for these temporary files, ensuring consistency when the final merge occurs.

### Can I include spaces or special characters in the prefix string?

Yes, you can include spaces and many special characters in your prefix string, but you should quote the argument properly in your shell command. For example: `you-get --pre "Lecture 01: Intro" URL`. The brackets are added automatically by you-get, so you do not need to include them in your prefix string. Avoid characters that are illegal in your operating system's filenames, as these may cause write errors.