GithubHelp home page GithubHelp logo

miqwit / dedex Goto Github PK

View Code? Open in Web Editor NEW
22.0 5.0 11.0 4.36 MB

A generic efficient DDEX parser. Parse seemlessly the complex DDEX format and transform it into classes easily useable in your PHP project. Supports several versions (3.8.2, 4.1, 4.1.1) and is listed in the official DDEX page: https://kb.ddex.net/display/HBK/Open+Source+Software

License: MIT License

PHP 100.00%
music media ddex standard parser xml

dedex's Introduction

DeDEX

DeDEX is a DDEX XML file parser. DDEX is a standard used in the music industry to deliver rich media content. See more info at ddex.net. This covers only the ERN (Electronic Release Notification) standard, for versions 3.8.2 and 4.1.

In my past experiences as a developer, I always had to develop or enhanced a DDEX parser for ERN. I created one here that is as convenient to use as I always hoped for.

The Rule mechanism is pretty useful and flexible. The DDEX ERN standard is extremely vast and there are many ways to use it. Most providers generate a simplified yet comprehensive XML file covering most of the needs. The Rules helps checking during the parsing that not only the XML is valid, but contain the minimal consistent information.

It is possible to implement your own rules (contribute to this repository if you think other developers could make a use of it), and to implement a different set of rules for different provider.

For instance, it is possible to enforce that for a given XML the ISRC is provided for all recordings, but not for another one. Providers rules can be modelled in a Rules Set.

If you find this useful, please star this repository.

This repository provides Simple Entities that can be handy to parse your first XML files. They give a simplified model of an Album, with Tracks, Artists and Deals attached. You can ignored the Simple Entities and build your own set or superset of entities to serve your needs. Note that the Simple Entities give a limited usage of DDEX. Read the documentation carefully before using it.

Installation

composer require miqwit/dedex

Usage

Convert a DDEX file to a SimpleAlbum

use DedexBundle\Controller\ErnParserController;
use DedexBundle\Simplifiers\SimpleAlbum;

$xml_path = "tests/samples/with_assets/004_complete/1199119911991.xml";
$parser = new ErnParserController();
$ern = $parser->parse($xml_path);
$album = new SimpleAlbum($ern);

// Then you can access high level property of this album
$release_date = $album->getOriginalReleaseDate();
$artists_at_album_level = $album->getArtists();
$tracks_for_cd_1 = $album->getTracksPerCd()[1];

// You can also access exact XML mapping by getting 
// ddex objects at album or track level
$ddex_release = $album->getDdexRelease();
$ddex_release->getReleaseId()[0]->getICPN()->value(); // direct access
$ddex_track = $tracks_for_cd_1[1]->getDdexSoundRecording()->getDuration(); // direct access

Parse a file without XSD validation

use DedexBundle\Controller\ErnParserController;

$xml_path = "tests/samples/001_audioalbum_complete.xml";
$parser = new ErnParserController();
$ern = $parser->parse($xml_path);

// Then you can access properties of the ERN
$created_at = $ern->getMessageHeader()->getMessageCreatedDateTime();

Parse a file with XSD validation

XSD validation will load all XML and XSD in memory, making this library less efficient. Use with care. Is not adapted to gigantic files.

use DedexBundle\Controller\ErnParserController;

$xml_path = "tests/samples/001_audioalbum_complete.xml";
$parser = new ErnParserController();
$parser->setXsdValidation(true);
$ern = $parser->parse($xml_path);

Parse a file with Rules

use DedexBundle\Controller\ErnParserController;
use DedexBundle\Rule\AtLeastOneImage;
use DedexBundle\Exception\RuleValidationException;

$xml_path = "tests/samples/001_audioalbum_complete.xml";
$parser = new ErnParserController();
$parser->addRule(new AtLeastOneImage(Rule::LEVEL_ERROR));
// ... can add multiple rules one by one
// ... or multiple rules with $parser->addRuleSet([])
$ern = $parser->parse($xml_path);  // will raise an RuleValidationException if rule is broken

Parser config

Here are handy function from the parser.

$parser=new ErnParserController();

$parser->setDisplayLog(true);

Displays parsing logs. For debugging purpose mainly. (default: false)

$parser->setXsdValidation(true);

Validates XML against XSD. (default: false because will load XSD and XML in memory)

$parser->getRuleMessages();

Returns a formatted string (with new lines) of all the errors generated by the rule checking. To be called when parsing ended. If one of the ERROR rules fail, the parser will throw an exception with these messages. In the case of only WARNING raised during the parsing, this function is the only way to read them.

$parser->addRuleSet();

Will store a set of Rule (array). For example, each provider could be check with a specific rule set.

dedex's People

Contributors

dependabot[bot] avatar ignacioalles avatar miqwit avatar onelazydev avatar skyree avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

dedex's Issues

Add php 8 support

Current php version is restricted to "php": "^7.2", but code works fine with php 8.0 too.

Is it possible to allow this php version in composer.json file?

xml parse multibyte UTF8 string with invalid result

An invalid value is produced when multibyte char is present in XML file.
Altough it seams to be handled in:

// If the previous element was the same and had the same tag, concatenate value
// xml_parser is known to split values when encountering multibyte chars and call the character_data_handler multiple times
if (!empty($this->lastElement) && $this->lastElement[0] === $elem && $this->lastElement[1] === $tag) {
$value = $this->lastElement[2] . $value;
}

there is still an issue because the preceding value to which the new value is concatenated, was trimmed here:

$data_clean = trim($data);

thus removing the whitespaces that might be between them.

Current code works fine if special char is not preceded by whitespace (eg: Juan García) but produced wrong value if it is (eg: Juan Ávila results in JuanÁvila)

Uncaught Error: Call to undefined method DedexBundle\Simplifiers\SimpleAlbum::getTracks()

Hello, When I use the following code example, I get the Uncaught Error: Call to undefined method DedexBundle\Simplifiers\SimpleAlbum::getTracks()

use DedexBundle\Controller\ErnParserController;
use DedexBundle\Simplifiers\SimpleAlbum;

$xml_path = "tests/samples/with_assets/004_complete/1199119911991.xml";
$parser = new ErnParserController();
$ern = $parser->parse($xml_path);
$album = new SimpleAlbum($ern);

// Then you can access high level property of this album
$release_date = $album->getOriginalReleaseDate();
$artists_at_album_level = $album->getArtists();
$tracks_for_cd_1 = $album->getTracks()[1];

I checked SimpleAlbum class/file, there is no getTracks() method

Thanks

Problem with some unicode characters

Anybody encountered truncated strings while parsing XML files? For example, if song or artist contains characters 'ć', 'č' and 'š', portion of string before this character is truncated. In attachment is provided sample XML file.

ern.xml.zip

ERN 4.1: No functions found for this tag: Party. Path is NewReleaseMessage,PartyList

There is an error while parsing a message PartyList node in NewReleaseMessage using ERN 4.1 spec.
Error message is:

No functions found for this tag: Party. Path is NewReleaseMessage,PartyList

and the reason is that it seems an intermediate class PartyListType is required between NewReleaseMessage and PartyType.

Message looks like:

<ern:NewReleaseMessage 
   xmlns:ern="http://ddex.net/xml/ern/41"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="http://ddex.net/xml/ern/41 release-notification.xsd"
   ReleaseProfileVersionId="Audio" LanguageAndScriptCode="en">
   <MessageHeader>
   [....]
   </MessageHeader>
   <PartyList>
      <Party>
         <PartyReference>PSaekoShu</PartyReference>
         <PartyName>
            <FullName>Saeko Shu</FullName>
            <FullNameIndexed>Shu, Saeko</FullNameIndexed>
         </PartyName>
         <PartyName LanguageAndScriptCode="ja-Jpan">
            <FullName>しゅうさえこ</FullName>
         </PartyName>
      </Party>
      <Party>
         <PartyReference>PEMI</PartyReference>
         <PartyName>
            <FullName>EMI MUSIC JAPAN INC.</FullName>
         </PartyName>
      </Party>
   </PartyList>
   <ResourceList>
   [....]

Here is some documentation explaining the addition in ERN-4

I can make a pull request if you'd like.

How to store releases?

Hi. How to properly store releases and objects that have been parsed by this library, knowing that, for example, track data in different territories, release data, file data, and so on can be different depending on the territory?

Requires PHP >= 7.4

Probably worth noting in the readme. Without 7.4 you can't have typed class properties.

Get release info for specific territory

How do I get information about releases, tracks and other files for individual regions? For example one track (although it can be both a file and a release) contains information for Worldwide and US regions, how to get the release for US?

Support for other versions?

Do you have plans for supporting other versions?

341, 381, 383, 430

Thanks for making this project. Also, I'm curious what was your motivation for making it?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.