Skip to content

Latest commit

 

History

3 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

mediapack

Overview

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.


Design Patterns Used

Factory Pattern

  • The MetadataFactory class 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.

Builder Pattern (Abstract Base Class)

  • Each platform has its own builder class (e.g., NetflixMetadataBuilder, AppleMetadataBuilder, etc.) that inherits from the abstract MetadataBuilder base class.
  • Each builder implements the steps to construct the XML metadata according to the platform's requirements.

How They Interact

  • The user provides a data dictionary with all required metadata fields.
  • The MetadataFactory selects the appropriate builder for the requested platform.
  • The builder constructs the XML tree using the provided data.

Installation

  1. Clone the repository:
    git clone <repo-url>
    cd MetadataGen
  2. (Optional) Create and activate a virtual environment:
    python3 -m venv .venv
    source .venv/bin/activate
  3. Install dependencies:
    pip install -r requirements.txt
    # or, if using pyproject.toml
    pip install .

Running Unit Tests

To run all unit tests:

python -m unittest discover tests -v

Or, if you use pytest:

pytest tests/

Usage: Running the Application

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'))

Sample Data Structure

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"]
}

Example Output XML

Netflix

<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>

Apple

<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>

Disney

<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>

Amazon

<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>

Extending: Adding More Companies/Builders

To add support for a new company/platform:

  1. 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.
  2. Register the new builder in the factory:

    • Edit mediapack/factory.py and add your builder to the builders dictionary:
      from mediapack.builders.mycompany import MyCompanyMetadataBuilder
      # ...
      builders = {
          # ...
          "mycompany": MyCompanyMetadataBuilder,
      }
  3. (Optional) Add tests:

    • Add a test case for your new builder in tests/test_builders.py.
  4. (Optional) Add sample data:

    • If your platform requires unique fields, update or add a new sample data file in mediapack/data/.
  5. (Optional) Update documentation:

    • Add your platform to the README and provide an example output.

Logging

  • 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.

License

MIT License (or specify your own)

About

xml creator

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages