Metadata-Version: 2.4
Name: pptmedia
Version: 1.0.2
Summary: Extract images and videos from PowerPoint presentations
Author-email: MaDyEl <madyel83@gmail.com>
License: MIT License
        
        Copyright (c) 2020 MaDyEl
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
Project-URL: Homepage, https://github.com/madyel/pptmedia
Project-URL: Repository, https://github.com/madyel/pptmedia
Project-URL: Issues, https://github.com/madyel/pptmedia/issues
Keywords: powerpoint,pptx,media,extract,images,videos
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Topic :: Multimedia
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE.txt
Requires-Dist: lxml>=6.0.2
Requires-Dist: Pillow>=12.1.1
Requires-Dist: python-pptx>=1.0.2
Provides-Extra: dev
Requires-Dist: pytest>=8.0; extra == "dev"
Requires-Dist: ruff>=0.4; extra == "dev"
Dynamic: license-file

# Extract Media PowerPoint

[![PyPI version](https://badge.fury.io/py/Extract-Media-PowerPoint.svg)](https://badge.fury.io/py/Extract-Media-PowerPoint)
[![Python](https://img.shields.io/pypi/pyversions/Extract-Media-PowerPoint.svg)](https://pypi.org/project/Extract-Media-PowerPoint/)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE.txt)

A lightweight Python library to extract images and videos from PowerPoint (`.pptx`) presentations, with optional filtering by media type, file extension, and automatic organization by slide number.

## Features

- Extract **all** embedded media (images and videos) from a `.pptx` file
- Extract **filtered** media by type (`image` or `video`) and custom extensions
- Output organized in subdirectories by **slide number**
- Supports custom output directories
- Built on top of [`python-pptx`](https://python-pptx.readthedocs.io/)

## Requirements

- Python >= 3.10
- lxml >= 6.0.2
- Pillow >= 12.1.1
- python-pptx >= 1.0.2

## Installation

```bash
pip install pptmedia
```

## Quick Start

### Extract all media (no filtering)

```python
from extract import PowerPointMediaExtractor

extractor = PowerPointMediaExtractor(
    filepath="presentation.pptx",
    output_dir="output"
)
count = extractor.extract_all_media()
print(f"Extracted {count} media files")
```

Files are saved under `output/ppt/media/`.

### Extract images filtered by extension

```python
from extract import PowerPointMediaExtractor

extractor = PowerPointMediaExtractor(
    filepath="presentation.pptx",
    media_type="image",
    output_dir="output",
    extensions=["png", "jpg"]
)
count = extractor.extract_filtered_media()
```

Files are saved under `output/<slide_number>/ppt/media/`.

### Extract videos

```python
from extract import PowerPointMediaExtractor

extractor = PowerPointMediaExtractor(
    filepath="presentation.pptx",
    media_type="video",
    output_dir="output",
    extensions=["mp4", "avi"]
)
count = extractor.extract_filtered_media()
```

## API Reference

### `PowerPointMediaExtractor`

```python
PowerPointMediaExtractor(
    filepath: str | Path,
    media_type: str = "image",      # "image" or "video"
    output_dir: str | Path = "temp",
    extensions: list[str] | None = None,
)
```

| Parameter    | Type                    | Default    | Description                                              |
|-------------|-------------------------|------------|----------------------------------------------------------|
| `filepath`  | `str \| Path`           | —          | Path to the `.pptx` file                                |
| `media_type`| `str`                   | `"image"`  | Media type to extract: `"image"` or `"video"`           |
| `output_dir`| `str \| Path`           | `"temp"`   | Directory where media will be saved                      |
| `extensions`| `list[str] \| None`     | `None`     | Allowed extensions (defaults to all for the media type) |

**Default extensions:**

| Type    | Default extensions                    |
|---------|---------------------------------------|
| `image` | `png`, `jpeg`, `jpg`, `bmp`, `svg`   |
| `video` | `mp4`, `avi`, `mpg`, `mpeg`, `wmv`   |

#### Methods

| Method                    | Returns | Description                                              |
|--------------------------|---------|----------------------------------------------------------|
| `extract_all_media()`    | `int`   | Extracts all embedded media, returns count               |
| `extract_filtered_media()` | `int` | Extracts media filtered by type/extension, organized by slide |

### `MediaInfo`

Dataclass representing a media item found in the presentation.

```python
@dataclass
class MediaInfo:
    shape_id: int
    filename: str
    slide_number: int
```

## Logging

The library uses Python's standard `logging` module under the logger name `extract.service`. To see output:

```python
import logging
logging.basicConfig(level=logging.INFO)
```

## License

MIT — see [LICENSE.txt](LICENSE.txt).
