mediapack is a Python application for generating video metadata XML files for major streaming platforms: Netflix, Amazon, Apple, and Disney. It is designed to be easily extensible for additional platforms and uses a clean, maintainable architecture based on the Factory and Builder design patterns.
- The
MetadataFactoryclass is responsible for instantiating the correct metadata builder based on the target platform (e.g., Netflix, Apple, Disney, Amazon). - This allows for easy extension: adding a new platform only requires implementing a new builder and registering it in the factory.
- Each platform has its own builder class (e.g.,
NetflixMetadataBuilder,AppleMetadataBuilder, etc.) that inherits from the abstractMetadataBuilderbase class. - Each builder implements the steps to construct the XML metadata according to the platform's requirements.
- The user provides a data dictionary with all required metadata fields.
- The
MetadataFactoryselects the appropriate builder for the requested platform. - The builder constructs the XML tree using the provided data.
- Clone the repository:
git clone <repo-url> cd MetadataGen
- (Optional) Create and activate a virtual environment:
python3 -m venv .venv source .venv/bin/activate - Install dependencies:
pip install -r requirements.txt # or, if using pyproject.toml pip install .
To run all unit tests:
python -m unittest discover tests -vOr, if you use pytest:
pytest tests/You can use the library in your own Python scripts. Here is a typical usage example:
from mediapack import MetadataFactory
from mediapack.data.sample_data import sample_data
# Choose a platform: 'netflix', 'apple', 'disney', 'amazon'
builder = MetadataFactory.get_builder('netflix', sample_data)
xml_root = builder.build()
# To get a pretty-printed XML string:
from lxml import etree
print(etree.tostring(xml_root, pretty_print=True, encoding='unicode'))Here is an example of the data dictionary expected by the builders:
sample_data = {
"localizations": [
{"language": "en", "title": "Sample Movie", "short_synopsis": "Short desc.", "long_synopsis": "Long description."},
{"language": "es", "title": "Película de Ejemplo", "short_synopsis": "Descripción corta.", "long_synopsis": "Descripción larga."}
],
"studio": "Sample Studio",
"release_date": "2024-06-12",
"duration": "120:00",
"rating_system": "MPAA",
"rating": "PG-13",
"genres": ["Action", "Adventure"],
"cast": ["Actor 1", "Actor 2"],
"crew": {"Director": "Jane Doe", "Producer": "John Smith"},
"images": [
{"type": "poster", "language": "en", "url": "http://example.com/poster_en.jpg"},
{"type": "poster", "language": "es", "url": "http://example.com/poster_es.jpg"}
],
"video_codec": "H.264",
"resolution": "4K",
"audio": [
{"language": "en", "codec": "AAC"},
{"language": "es", "codec": "AAC"}
],
"subtitles": ["en", "es"]
}<NetflixVideo>
<Localization language="en">
<Title>Sample Movie</Title>
<Short>Short desc.</Short>
<Long>Long description.</Long>
</Localization>
...
<Studio>Sample Studio</Studio>
<ReleaseDate>2024-06-12</ReleaseDate>
<Duration>120:00</Duration>
<Rating system="MPAA">PG-13</Rating>
<Genres>
<Genre>Action</Genre>
<Genre>Adventure</Genre>
</Genres>
<People>
<Actor>Actor 1</Actor>
<Actor>Actor 2</Actor>
<Director>Jane Doe</Director>
<Producer>John Smith</Producer>
</People>
<Assets>
<Image type="poster" language="en">http://example.com/poster_en.jpg</Image>
...
<Video codec="H.264" resolution="4K"/>
</Assets>
<Audio>
<Track language="en" codec="AAC"/>
...
</Audio>
<Subtitles>
<Subtitle language="en"/>
<Subtitle language="es"/>
</Subtitles>
</NetflixVideo><AppleVideo>
<Localization language="en">
<Title>Sample Movie</Title>
<ShortDescription>Short desc.</ShortDescription>
<LongDescription>Long description.</LongDescription>
</Localization>
...
<Provider>Sample Studio</Provider>
<ReleaseDate>2024-06-12</ReleaseDate>
<Duration>120:00</Duration>
<Rating system="MPAA">PG-13</Rating>
<Genres>
<Genre>Action</Genre>
<Genre>Adventure</Genre>
</Genres>
<People>
<Cast>
<Actor>Actor 1</Actor>
...
</Cast>
<Crew>
<Director>Jane Doe</Director>
...
</Crew>
</People>
<Assets>
<Image type="poster" language="en">http://example.com/poster_en.jpg</Image>
...
<Video codec="H.264" resolution="4K"/>
</Assets>
<Audio>
<Track language="en" codec="AAC"/>
...
</Audio>
<Subtitles>
<Subtitle language="en"/>
<Subtitle language="es"/>
</Subtitles>
</AppleVideo><DisneyVideo>
<Localization language="en">
<Title>Sample Movie</Title>
<Synopsis>Short desc.</Synopsis>
<ExtendedSynopsis>Long description.</ExtendedSynopsis>
</Localization>
...
<ContentProvider>Sample Studio</ContentProvider>
<ReleaseDate>2024-06-12</ReleaseDate>
<Duration>120:00</Duration>
<ContentRating system="MPAA">PG-13</ContentRating>
<ContentGenres>
<Genre>Action</Genre>
<Genre>Adventure</Genre>
</ContentGenres>
<ContentPeople>
<Cast>
<Actor>Actor 1</Actor>
...
</Cast>
<Crew>
<Director>Jane Doe</Director>
...
</Crew>
</ContentPeople>
<ContentAssets>
<Image type="poster" language="en">http://example.com/poster_en.jpg</Image>
...
<Video codec="H.264" resolution="4K"/>
</ContentAssets>
<AudioTracks>
<Track language="en" codec="AAC"/>
...
</AudioTracks>
<SubtitleTracks>
<Subtitle language="en"/>
<Subtitle language="es"/>
</SubtitleTracks>
</DisneyVideo><AmazonVideo>
<Localization language="en">
<Title>Sample Movie</Title>
<Synopsis>Short desc.</Synopsis>
<ExtendedSynopsis>Long description.</ExtendedSynopsis>
</Localization>
...
<Studio>Sample Studio</Studio>
<ReleaseDate>2024-06-12</ReleaseDate>
<Duration>120:00</Duration>
<Rating system="MPAA">PG-13</Rating>
<Genres>
<Genre>Action</Genre>
<Genre>Adventure</Genre>
</Genres>
<People>
<Cast>
<Actor>Actor 1</Actor>
...
</Cast>
<Crew>
<Director>Jane Doe</Director>
...
</Crew>
</People>
<Assets>
<Image type="poster" language="en">http://example.com/poster_en.jpg</Image>
...
<Video codec="H.264" resolution="4K"/>
</Assets>
<Audio>
<Track language="en" codec="AAC"/>
...
</Audio>
<Subtitles>
<Subtitle language="en"/>
<Subtitle language="es"/>
</Subtitles>
</AmazonVideo>To add support for a new company/platform:
-
Create a new builder class in
mediapack/builders/, e.g.,mycompany.py:- Inherit from
MetadataBuilder. - Implement all abstract methods to build the XML structure for your platform.
- Inherit from
-
Register the new builder in the factory:
- Edit
mediapack/factory.pyand add your builder to thebuildersdictionary:from mediapack.builders.mycompany import MyCompanyMetadataBuilder # ... builders = { # ... "mycompany": MyCompanyMetadataBuilder, }
- Edit
-
(Optional) Add tests:
- Add a test case for your new builder in
tests/test_builders.py.
- Add a test case for your new builder in
-
(Optional) Add sample data:
- If your platform requires unique fields, update or add a new sample data file in
mediapack/data/.
- If your platform requires unique fields, update or add a new sample data file in
-
(Optional) Update documentation:
- Add your platform to the README and provide an example output.
- All builders and the factory use Python's logging module for info/debug output.
- Logs are written to both the console and a rotating file in the
logs/directory.
MIT License (or specify your own)