Skip to main content

flet-media-scanner

A Flet extension for Android MediaStore integration — save, list, and delete media files in the device Gallery / Music / Pictures without requiring broad storage permissions.

Supports video, audio, and image files. MIME type is resolved automatically from the file extension.

Requirements

  • Platform: Android only (no-op on other platforms)
  • Android: API 23+ (minSdk 23)
  • Flet: >= 0.86.0

Supported Formats

🎬 Video

Extension MIME Type Destination
.mp4 video/mp4 Movies/<album>/
.mkv video/x-matroska Movies/<album>/
.webm video/webm Movies/<album>/
.avi video/x-msvideo Movies/<album>/
.mov video/quicktime Movies/<album>/
.3gp video/3gpp Movies/<album>/
.ts video/mp2t Movies/<album>/
.flv video/x-flv Movies/<album>/

🎵 Audio

Extension MIME Type Destination
.mp3 audio/mpeg Music/<album>/
.m4a audio/mp4 Music/<album>/
.aac audio/aac Music/<album>/
.flac audio/flac Music/<album>/
.opus audio/opus Music/<album>/
.wav audio/wav Music/<album>/
.ogg audio/ogg Music/<album>/
.wma audio/x-ms-wma Music/<album>/

🖼 Image

Extension MIME Type Destination
.jpg / .jpeg image/jpeg Pictures/<album>/
.png image/png Pictures/<album>/
.gif image/gif Pictures/<album>/
.webp image/webp Pictures/<album>/
.bmp image/bmp Pictures/<album>/
.heic image/heic Pictures/<album>/
.heif image/heif Pictures/<album>/
.avif image/avif Pictures/<album>/
.tiff image/tiff Pictures/<album>/

Installation

pip install flet-media-scanner

Setup

Register the extension in your pyproject.toml:

[tool.flet.extensions]
flet_media_scanner = "flet_media_scanner.Extension"

Usage

import flet as ft
from flet_media_scanner import MediaScanner, SaveResult

async def main(page: ft.Page):
    scanner = MediaScanner()
    page.services.append(scanner)
    page.update()

    # ── Video ──────────────────────────────────────────────────────────────
    result: SaveResult = await scanner.save_video(
        "/data/user/0/com.example.app/cache/video.mp4",
        file_name="my_video.mp4",
        album="MyApp",
    )
    if result.success:
        print(f"Video saved: {result.content_uri}")

    videos = await scanner.list_videos(album="MyApp")
    for v in videos:
        print(v["display_name"], v["content_uri"])

    # ── Audio ──────────────────────────────────────────────────────────────
    result = await scanner.save_audio(
        "/data/user/0/com.example.app/cache/song.mp3",
        file_name="song.mp3",
        album="MyApp",
    )
    if result.success:
        print(f"Audio saved: {result.content_uri}")

    tracks = await scanner.list_audio(album="MyApp")
    for t in tracks:
        print(t["display_name"], t["mime_type"])

    # ── Image ──────────────────────────────────────────────────────────────
    result = await scanner.save_image(
        "/data/user/0/com.example.app/cache/photo.jpg",
        file_name="photo.jpg",
        album="MyApp",
    )
    if result.success:
        print(f"Image saved: {result.content_uri}")

    images = await scanner.list_images(album="MyApp")
    for img in images:
        print(img["display_name"], img["size"])

    # ── Delete (works for any media type) ──────────────────────────────────
    deleted = await scanner.delete_media("content://media/external/video/media/123")
    print("Deleted:", deleted)

ft.run(main)

API

MediaScanner (Service)

Add to page.services before calling any methods.


Video

await save_video(file_path, file_name=None, album="MyApp") → SaveResult

Copies a private app video into Movies/<album> via Android MediaStore.

await list_videos(album="MyApp") → list[dict]

Returns all videos saved to the album.


Audio

await save_audio(file_path, file_name=None, album="MyApp") → SaveResult

Copies a private app audio file into Music/<album> via Android MediaStore.

await list_audio(album="MyApp") → list[dict]

Returns all audio files saved to the album.


Image

await save_image(file_path, file_name=None, album="MyApp") → SaveResult

Copies a private app image into Pictures/<album> via Android MediaStore.

await list_images(album="MyApp") → list[dict]

Returns all images saved to the album.


Delete

await delete_media(content_uri) → bool

Deletes any MediaStore item (video, audio, or image) by its content:// URI.

await delete_video(content_uri) → bool

Alias for delete_media(). Kept for backwards compatibility.


Common parameters for save_*

Parameter Type Description
file_path str Absolute path to the source file
file_name str | None Display name (defaults to the source file basename)
album str Subfolder inside Movies/, Music/, or Pictures/

SaveResult (dataclass)

Field Type Description
success bool Whether the operation succeeded
content_uri str MediaStore content:// URI
display_name str File name as shown in the gallery/app
mime_type str e.g. video/mp4, audio/mpeg, image/jpeg
relative_path str e.g. Movies/MyApp/
source_path str Original source file path
size int File size in bytes
error str Error message if success=False

List item fields (list_videos, list_audio, list_images)

Each dict contains: content_uri, display_name, mime_type, relative_path, size, date_added, date_modified.

License

MIT

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

flet_media_scanner-0.86.3.tar.gz (12.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

flet_media_scanner-0.86.3-py3-none-any.whl (13.2 kB view details)

Uploaded Python 3

File details

Details for the file flet_media_scanner-0.86.3.tar.gz.

File metadata

  • Download URL: flet_media_scanner-0.86.3.tar.gz
  • Upload date:
  • Size: 12.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.6

File hashes

Hashes for flet_media_scanner-0.86.3.tar.gz
Algorithm Hash digest
SHA256 6307a0833402f8b8219ecfc6e8b9efceec868db6c4584aecaa77fd79427f73da
MD5 60cd5b3a29f5650bba81da2027e18a28
BLAKE2b-256 cc9cc19931ba7b2f3a48b93d8298be4664f85c2cef5e3c23e0724a6c1c823fb5

See more details on using hashes here.

File details

Details for the file flet_media_scanner-0.86.3-py3-none-any.whl.

File metadata

File hashes

Hashes for flet_media_scanner-0.86.3-py3-none-any.whl
Algorithm Hash digest
SHA256 aabc7d505ed8430e8f4ec56728f7ba85cd012bbe51dfdbdb1047fd3d50baa054
MD5 5bbc2448f2087c9e9fd935f5781a0cce
BLAKE2b-256 89bd92892d12102dfc4ba6c6b36bb1f71239ef60b29af1cddf6d708364066cd5

See more details on using hashes here.

Release history Release notifications | RSS feed

1.7.0

2 files

1.6.0

2 files

1.5.0

2 files

1.4.0

2 files

1.3.0

2 files

1.2.0

2 files

1.1.0

2 files

1.0.1

2 files

1.0.0

2 files

0.86.5

2 files

0.86.4

2 files

This release

0.86.3 This release

2 files

0.86.2

2 files

0.86.1

2 files

0.86.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page