UPNP/DLNA for IPS: new version

Moin Digihouse,
ich habe noch ein bisschen an der Umwandlung gearbeitet.
Es fehlen die Überprüfungen für metadata und res. :wink:


<?

function array_search_key($array,$pattern)
{    
    $key = preg_grep('/'.$pattern.'/', array_keys($array));
        if (isset($key[0])){
        return($key[0]);
        }    

    return false;   
    
}

        if(isset($DIDL['container'])) 
        { 
            $count = count($DIDL['container'])/2; 
            
            for ($i=0; $i < $count; $i++) 
            { 
                $liste[$i]['typ']                       = 'container'; 
                $liste[$i]['metadata']                  = $MetaData; 
                
                if(isset($DIDL['container'][$i."_attr"]['id']))
                $liste[$i]['id']                        = $DIDL['container'][$i."_attr"]['id']; 
                if(isset($DIDL['container'][$i."_attr"]['refID']))
                $liste[$i]['refid']                     = $DIDL['container'][$i."_attr"]['refID'];
                if(isset($DIDL['container'][$i."_attr"]['parentID'])) 
                $liste[$i]['parentid']                  = $DIDL['container'][$i."_attr"]['parentID']; 
                if(isset($DIDL['container'][$i."_attr"]['restricted']))
                $liste[$i]['restricted']                = $DIDL['container'][$i."_attr"]['restricted']; 
                
                $key = array_search_key($DIDL['container'][$i],"artist$");
                if($key)
                $liste[$i]['artist']                    = $DIDL['container'][$i][$key]; 
                $key = array_search_key($DIDL['container'][$i],"album$");
                if($key)
                $liste[$i]['album']                     = $DIDL['container'][$i][$key];
                $key = array_search_key($DIDL['container'][$i],"title$");
                if($key) 
                $liste[$i]['title']                     = $DIDL['container'][$i][$key]; 
            }
        } 
    
        if(isset($DIDL['item'])) 
        {  
            $count = count($DIDL['item'])/2; 
            
            for ($i; $i < $count; $i++) 
            { 
                $liste[$i]['typ']                       = 'item'; 
                $liste[$i]['metadata']                  = $MetaData; 
        
                if(isset($DIDL['item'][$i."_attr"]['id']))
                $liste[$i]['id']                        = $DIDL['item'][$i."_attr"]['id']; 
                if(isset($DIDL['item'][$i."_attr"]['refID']))
                $liste[$i]['refid']                     = $DIDL['item'][$i."_attr"]['refID']; 
                if(isset($DIDL['item'][$i."_attr"]['parentID']))
                $liste[$i]['parentid']                  = $DIDL['item'][$i."_attr"]['parentID']; 
                if(isset($DIDL['item'][$i."_attr"]['restricted']))
                $liste[$i]['restricted']                = $DIDL['item'][$i."_attr"]['restricted']; 
        
                $key = array_search_key($DIDL['item'][$i],"artist$");
                if($key)
                $liste[$i]['artist']                    = $DIDL['item'][$i][$key];
                $key = array_search_key($DIDL['item'][$i],"album$");
                if($key) 
                $liste[$i]['album']                     = $DIDL['item'][$i][$key]; 
                $key = array_search_key($DIDL['item'][$i],"title$");
                if($key)
                $liste[$i]['title']                     = $DIDL['item'][$i][$key]; 
        
                $liste[$i]['resource']                  = $DIDL['item'][$i]['res']; 
                $liste[$i]['duration']                  = $DIDL['item'][$i]['res_attr']['duration']; 
                $liste[$i]['size']                      = $DIDL['item'][$i]['res_attr']['size']; 
                $liste[$i]['bitrate']                   = $DIDL['item'][$i]['res_attr']['bitrate']; 
        
                $key = array_search_key($DIDL['item'][$i],"albumArtURI$");
                if($key)
                $liste[$i]['albumArtURI']               = $DIDL['item'][$i][$key];
                $key = array_search_key($DIDL['item'][$i],"genre$");
                if($key) 
                $liste[$i]['genre']                     = $DIDL['item'][$i][$key];
                $key = array_search_key($DIDL['item'][$i],"date$");
                if($key) 
                $liste[$i]['date']                      = $DIDL['item'][$i][$key]; 
                $key = array_search_key($DIDL['item'][$i],"originalTrackNumber$");
                if($key)
                $liste[$i]['originalTrackNumber']       = $DIDL['item'][$i][$key]; 
                $key = array_search_key($DIDL['item'][$i],"class$");
                if($key)
                $liste[$i]['class']                     = $DIDL['item'][$i][$key]; 
            } 
        } 


PS: Ich sehe bei der neuen Version kein Unterschied zwischen Chrome (mein Standardbrowser) und Firefox, liegt aber vl. auch daran, dass ich als DLNA Server „Universal Media Server“ nutze und dieser nicht gefunden wird.
Beim Suchvorgang taucht keine Fehlermeldung auf.

MFG MNB

Hi mnb,

prima. Sieht auf den ersten Blick gut aus! Ich teste es am Wochenende mal und schaue auch nach dem Universal Media Server. Der sieht auf den ersten Blick dem PS3 Media Server ähnlich. Letzteren hatte ich eine Weile im Einsatz, da er auch ISO’s streamen kann.

Viele Grüße

André

Hi mnb,

den Universal Media Server habe ich auch nicht lesen können. Erscheint auch nicht im Abfrage-Array (in UPNP_SSDP_Request). Hast Du mal andere Server probiert ? Twonky, Asset-UPNP und Plex sind momentan meine Hitlist.

Meine Kenntnisse von PHP gehen noch nicht so weit Fehler vernünftig abzufangen. Die Devices bzw. Server werden in UPNP_SSDP_Server bzw. UPNP_SSDP_Device mit file_get_contents abgefragt. Hier wäre wahrscheinlich ein Abbruch der Schleife bei Fehler sinnvoll.

ab Zeile 48:

	//---------------------------------------------------------------------------
	//nur auswerten, wenn erreichbar---------------------------------------------
	//---------------------------------------------------------------------------

	if (ping($ServerIP, $ServerPort, $timeout="1") == "true")
		{
		//Description des Gerätes abrufen-----------------------------------------
		$xml = file_get_contents("$ServerDescription", -1);
		print_r($xml);

...

Ach übrigens: wofür steht $pattern in der letzten Function ?

Viele Grüße

André

Moin DigiHouse,

habe noch ein paar Bugs gefunden und behoben.
Es ist zwar nicht perfekt aber es sollte funktionieren. :smiley:
Mit $pattern im altem Script(jetzt $search) war der Suchbegriff gemeint
um den richtigen Schlüssel im Array zu ermitteln.
Damit kann man das Problem mit u: oder m: … umgehen.

Werde mal die anderen DLNA Server ausprobieren.

MFG MNB


<?

function array_search_key($array,$search)
{    
        $key = preg_grep('/'.$search.'/', array_keys($array));
        if (isset($key[0])){
        return($key);
        }    

    return false;   
    
}

function array_check($array,$key)
{
    return (isset($array[$key]) || array_key_exists($key,$array));
}

    $liste = array(); 
    $i = 0;
	 
        if(array_check($DIDL,'container'))
        { 

	    $keys = array_search_key($DIDL['container'],"[0-9]$");
            $count = count($keys);
            
            for ($i=0; $i < $count; $i++) 
            { 
                $liste[$i]['typ']                       = 'container'; 
                $liste[$i]['metadata']                  = $MetaData; 
                
                if(isset($DIDL['container'][$i."_attr"]['id']))
                $liste[$i]['id']                        = $DIDL['container'][$i."_attr"]['id']; 
                if(isset($DIDL['container'][$i."_attr"]['refID']))
                $liste[$i]['refid']                     = $DIDL['container'][$i."_attr"]['refID'];
                if(isset($DIDL['container'][$i."_attr"]['parentID'])) 
                $liste[$i]['parentid']                  = $DIDL['container'][$i."_attr"]['parentID']; 
                if(isset($DIDL['container'][$i."_attr"]['restricted']))
                $liste[$i]['restricted']                = $DIDL['container'][$i."_attr"]['restricted']; 
                
                $key = array_search_key($DIDL['container'][$i],"artist$")[0];
                if($key)
                $liste[$i]['artist']                    = $DIDL['container'][$i][$key]; 
                $key = array_search_key($DIDL['container'][$i],"album$")[0];
                if($key)
                $liste[$i]['album']                     = $DIDL['container'][$i][$key];
                $key = array_search_key($DIDL['container'][$i],"title$")[0];
                if($key) 
                $liste[$i]['title']                     = $DIDL['container'][$i][$key]; 
            }
        } 
    
        if(array_check($DIDL,'item'))
        {  
            $keys = array_search_key($DIDL['item'],"[0-9]$");
            $count = (count($keys));
            $n = $i;
            
            for ($i=0; $i < $count; $i++)
            { 
                $liste[$n+$i]['typ']                       = 'item';
                $liste[$n+$i]['metadata']                  = $MetaData;
        
                if(isset($DIDL['item'][$i."_attr"]['id']))
                $liste[$n+$i]['id']                        = $DIDL['item'][$i."_attr"]['id'];
                if(isset($DIDL['item'][$i."_attr"]['refID']))
                $liste[$n+$i]['refid']                     = $DIDL['item'][$i."_attr"]['refID'];
                if(isset($DIDL['item'][$i."_attr"]['parentID']))
                $liste[$n+$i]['parentid']                  = $DIDL['item'][$i."_attr"]['parentID'];
                if(isset($DIDL['item'][$i."_attr"]['restricted']))
                $liste[$n+$i]['restricted']                = $DIDL['item'][$i."_attr"]['restricted'];
        
                $key = array_search_key($DIDL['item'][$i],"artist$")[0];
                if($key)
                $liste[$n+$i]['artist']                    = $DIDL['item'][$i][$key];
                $key = array_search_key($DIDL['item'][$i],"album$")[0];
                if($key) 
                $liste[$n+$i]['album']                     = $DIDL['item'][$i][$key];
                $key = array_search_key($DIDL['item'][$i],"title$")[0];
                if($key)
                $liste[$n+$i]['title']                     = $DIDL['item'][$i][$key];
        
                if(isset($DIDL['item'][$i]['res'][0]))
                $liste[$n+$i]['resource']                  = $DIDL['item'][$i]['res'][0];
                if(isset($DIDL['item'][$i]['res']['0_attr']['duration']))
                $liste[$n+$i]['duration']                  = $DIDL['item'][$i]['res']['0_attr']['duration'];
                if(isset($DIDL['item'][$i]['res']['0_attr']['size']))
                $liste[$n+$i]['size']                      = $DIDL['item'][$i]['res']['0_attr']['size'];
                if(isset($DIDL['item'][$i]['res']['0_attr']['bitrate']))
                $liste[$n+$i]['bitrate']                   = $DIDL['item'][$i]['res']['0_attr']['bitrate'];
        
                $key = array_search_key($DIDL['item'][$i],"albumArtURI$")[0];
                if($key)
                $liste[$n+$i]['albumArtURI']               = $DIDL['item'][$i][$key];
                
                $key = array_search_key($DIDL['item'][$i],"genre$")[0];
                if($key) 
                $liste[$n+$i]['genre']                     = $DIDL['item'][$i][$key];
                
                $key = array_search_key($DIDL['item'][$i],"date$")[0];
                if($key) 
                $liste[$n+$i]['date']                      = $DIDL['item'][$i][$key];
                
                $key = array_search_key($DIDL['item'][$i],"originalTrackNumber$")[0];
                if($key)
                $liste[$n+$i]['originalTrackNumber']       = $DIDL['item'][$i][$key];
					  
                $key = array_search_key($DIDL['item'][$i],"class$")[0];
                if($key)
                $liste[$n+$i]['class']                     = $DIDL['item'][$i][$key];
            } 
        } 

?>


Hi mnb,

bekomme es nicht so richtig hin. Das Array bleibt leer. Mal folgendes Testfile:

<?

$xml1 = '<?xml version="1.0" encoding="UTF-8"?>
 <s:Envelope s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
  <s:Body>
   <u:BrowseResponse xmlns:u="urn:schemas-upnp-org:service:ContentDirectory:1">
    <Result><DIDL-Lite xmlns="urn:schemas-upnp-org:metadata-1-0/DIDL-Lite/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:upnp="urn:schemas-upnp-org:metadata-1-0/upnp/" xmlns:dlna="urn:schemas-dlna-org:metadata-1-0/"><item id="d8589-co11" parentID="co11" restricted="0"><dc:title>Get Back (ASAP)</dc:title><dc:creator>Alexandra Stan</dc:creator><dc:date>2011-01-01</dc:date><upnp:artist role="AlbumArtist">Alexandra Stan</upnp:artist><upnp:artist role="Performer">Alexandra Stan</upnp:artist><upnp:album>Saxobeats</upnp:album><upnp:genre>Pop</upnp:genre><upnp:albumArtURI dlna:profileID="JPEG_TN">http://192.168.178.64:26125/aa/67622...ber><res duration="0:03:23.000" size="3324093" bitrate="16364" bitsPerSample="16" sampleFrequency="44100" nrAudioChannels="2" protocolInfo="http-get:*:audio/mpeg:DLNA.ORG_PN=MP3;DLNA.ORG_OP=01">http://192.168.178.64:26125/content/...res><res duration="0:03:23.000" size="35831644" bitrate="176400" bitsPerSample="16" sampleFrequency="44100" nrAudioChannels="2" protocolInfo="http-get:*:audio/wav:DLNA.ORG_PN=WAV;DLNA.ORG_OP=01">http://192.168.178.64:26125/content/...res><res duration="0:03:23.000" size="35831600" bitrate="176400" bitsPerSample="16" sampleFrequency="44100" nrAudioChannels="2" protocolInfo="http-get:*:audio/L16:DLNA.ORG_PN=LPCM;DLNA.ORG_OP=01;DLNA.ORG_CI=1">http://192.168.178.64:26125/content/...res><res duration="0:03:23.000" size="3324093" bitrate="16364" bitsPerSample="16" sampleFrequency="44100" nrAudioChannels="2" protocolInfo="http-get:*:audio/mpeg:DLNA.ORG_PN=MP3;DLNA.ORG_OP=01">http://192.168.178.64:26125/content/c2/b16/f44100/d8589-co11.mp3</res><upnp:class>object.item.audioItem.musicTrack</upnp:class></item></DIDL-Lite></Result>
    <NumberReturned>1</NumberReturned>
    <TotalMatches>1</TotalMatches>
    <UpdateID>2296</UpdateID>
   </u:BrowseResponse>
  </s:Body>
 </s:Envelope>';

$xml2 = '<?xml version="1.0"?>
 <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
  <SOAP-ENV:Body>
   <m:BrowseResponse xmlns:m="urn:schemas-upnp-org:service:ContentDirectory:1">
    <Result xmlns:dt="urn:schemas-microsoft-com:datatypes" dt:dt="string"><DIDL-Lite xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:upnp="urn:schemas-upnp-org:metadata-1-0/upnp/"
xmlns="urn:schemas-upnp-org:metadata-1-0/DIDL-Lite/"
xmlns:microsoft="urn:schemas-microsoft-com:WMPNSS-1-0/"
xmlns:dlna="urn:schemas-dlna-org:metadata-1-0/"
><item id="6_eff1f3a5_7c0784c9-569" refID="4-569" restricted="1" parentID="6_eff1f3a5_7c0784c9"><dc:title>Mr. Saxobeat</dc:title><dc:creator>Alexandra Stan</dc:creator><res size="3122982" duration="0:03:11.608" bitrate="16000" protocolInfo="http-get:*:audio/mpeg:DLNA.ORG_PN=MP3;DLNA.ORG_OP=01;DLNA.ORG_FLAGS=01700000000000000000000000000000" sampleFrequency="44100" bitsPerSample="16" nrAudioChannels="2" microsoft:codec="{00000055-0000-0010-8000-00AA00389B71}">http://127.0.0.1:10243/WMPNSSv4/3561040673/1_Nl9lZmYxZjNhNV83YzA3ODRjOS01Njk.mp3</res><res duration="0:03:11.608" bitrate="176400" protocolInfo="http-get:*:audio/L16;rate=44100 /*[Objekt #44100 existiert nicht]*/;channels=2:DLNA.ORG_PN=LPCM;DLNA.ORG_OP=10;DLNA.ORG_CI=1;DLNA.ORG_FLAGS=01700000000000000000000000000000" sampleFrequency="44100" bitsPerSample="16" nrAudioChannels="2" microsoft:codec="{00000001-0000-0010-8000-00AA00389B71}">http://127.0.0.1:10243/WMPNSSv4/3561040673/Nl9lZmYxZjNhNV83YzA3ODRjOS01Njk.mp3?formatID=39</res><res duration="0:03:11.608" bitrate="88200" protocolInfo="http-get:*:audio/L16;rate=44100 /*[Objekt #44100 existiert nicht]*/;channels=1:DLNA.ORG_PN=LPCM;DLNA.ORG_OP=10;DLNA.ORG_CI=1;DLNA.ORG_FLAGS=01700000000000000000000000000000" sampleFrequency="44100" bitsPerSample="16" nrAudioChannels="1" microsoft:codec="{00000001-0000-0010-8000-00AA00389B71}">http://127.0.0.1:10243/WMPNSSv4/3561040673/Nl9lZmYxZjNhNV83YzA3ODRjOS01Njk.mp3?formatID=37</res><res duration="0:03:11.608" bitrate="24000" protocolInfo="http-get:*:audio/mp4:DLNA.ORG_PN=AAC_ISO_320;DLNA.ORG_OP=10;DLNA.ORG_CI=1;DLNA.ORG_FLAGS=01700000000000000000000000000000" sampleFrequency="48000" nrAudioChannels="2" microsoft:codec="{00001610-0000-0010-8000-00AA00389B71}">http://127.0.0.1:10243/WMPNSSv4/3561040673/Nl9lZmYxZjNhNV83YzA3ODRjOS01Njk.m4a?formatID=25</res><res duration="0:03:11.608" bitrate="32000" protocolInfo="http-get:*:audio/vnd.dolby.dd-raw:DLNA.ORG_PN=AC3;DLNA.ORG_OP=10;DLNA.ORG_CI=1;DLNA.ORG_FLAGS=01700000000000000000000000000000" sampleFrequency="48000" nrAudioChannels="2" microsoft:codec="{E06D802C-DB46-11CF-B4D1-00805F6CBBEA}">http://127.0.0.1:10243/WMPNSSv4/3561040673/Nl9lZmYxZjNhNV83YzA3ODRjOS01Njk.mp3?formatID=28</res><res duration="0:03:11.608" bitrate="24000" protocolInfo="http-get:*:audio/vnd.dlna.adts:DLNA.ORG_PN=AAC_ADTS_320;DLNA.ORG_OP=10;DLNA.ORG_CI=1;DLNA.ORG_FLAGS=01700000000000000000000000000000" sampleFrequency="48000" nrAudioChannels="2" microsoft:codec="{00001610-0000-0010-8000-00AA00389B71}">http://127.0.0.1:10243/WMPNSSv4/3561040673/Nl9lZmYxZjNhNV83YzA3ODRjOS01Njk.adts?formatID=30</res><res duration="0:03:11.608" bitrate="8000" protocolInfo="http-get:*:audio/x-ms-wma:DLNA.ORG_PN=WMABASE;DLNA.ORG_OP=10;DLNA.ORG_CI=1;DLNA.ORG_FLAGS=01700000000000000000000000000000" sampleFrequency="44100" nrAudioChannels="2" microsoft:codec="{00000161-0000-0010-8000-00AA00389B71}">http://127.0.0.1:10243/WMPNSSv4/3561040673/Nl9lZmYxZjNhNV83YzA3ODRjOS01Njk.wma?formatID=118</res><upnp:class>object.item.audioItem.musicTrack</upnp:class><upnp:genre>Dance</upnp:genre><dc:publisher>RMNradio</dc:publisher><upnp:artist role="AlbumArtist">Alexandra Stan</upnp:artist><upnp:artist role="Performer">Alexandra Stan</upnp:artist><upnp:author role="Composer">[Unbekannter Komponist]</upnp:author><upnp:album>Saxobeats</upnp:album><upnp:originalTrackNumber>0</upnp:originalTrackNumber><dc:date>2011-01-02</dc:date><upnp:actor role="Alexandra Stan">Alexandra Stan</upnp:actor><dc:description>www.radio-fx.de</dc:description><upnp:albumArtURI dlna:profileID="JPEG_SM">http://127.0.0.1:10243/WMPNSSv4/3561040673/0_Nl9lZmYxZjNhNV83YzA3ODRjOS01Njk.jpg?albumArt=true</upnp:albumArtURI><upnp:albumArtURI dlna:profileID="JPEG_TN">http://127.0.0.1:10243/WMPNSSv4/3561040673/Nl9lZmYxZjNhNV83YzA3ODRjOS01Njk.jpg?albumArt=true,formatID=32,width=160,height=160</upnp:albumArtURI><desc id="artist" nameSpace="urn:schemas-microsoft-com:WMPNSS-1-0/" xmlns:microsoft="urn:schemas-microsoft-com:WMPNSS-1-0/">&lt;microsoft:artistAlbumArtist&gt;Alexandra Stan&lt;/microsoft:artistAlbumArtist&gt;&lt;microsoft:artistPerformer&gt;Alexandra Stan&lt;/microsoft:artistPerformer&gt;</desc><desc id="author" nameSpace="urn:schemas-microsoft-com:WMPNSS-1-0/" xmlns:microsoft="urn:schemas-microsoft-com:WMPNSS-1-0/">&lt;microsoft:authorComposer&gt;[Unbekannter Komponist]&lt;/microsoft:authorComposer&gt;</desc><desc id="Year" nameSpace="urn:schemas-microsoft-com:WMPNSS-1-0/" xmlns:microsoft="urn:schemas-microsoft-com:WMPNSS-1-0/">&lt;microsoft:year&gt;2011&lt;/microsoft:year&gt;</desc><desc id="folderPath" nameSpace="urn:schemas-microsoft-com:WMPNSS-1-0/" xmlns:microsoft="urn:schemas-microsoft-com:WMPNSS-1-0/">&lt;microsoft:folderPath&gt;Freigegebene Musik\MP3´s - 05 fertig&lt;/microsoft:folderPath&gt;</desc><desc id="fileInfo" nameSpace="urn:schemas-microsoft-com:WMPNSS-1-0/" xmlns:microsoft="urn:schemas-microsoft-com:WMPNSS-1-0/">&lt;microsoft:fileIdentifier&gt;AMGa_id=R  2287667;AMGp_id=P  2354320;AMGt_id=T 24415507&lt;/microsoft:fileIdentifier&gt;</desc></item>
</DIDL-Lite></Result>
    <NumberReturned xmlns:dt="urn:schemas-microsoft-com:datatypes" dt:dt="ui4">1</NumberReturned>
    <TotalMatches xmlns:dt="urn:schemas-microsoft-com:datatypes" dt:dt="ui4">1</TotalMatches>
    <UpdateID xmlns:dt="urn:schemas-microsoft-com:datatypes" dt:dt="ui4">9</UpdateID>
   </m:BrowseResponse>
  </SOAP-ENV:Body>
 </SOAP-ENV:Envelope>';

//Functions---------------------------------------------------------------------

function xml2array($contents, $get_attributes=1, $priority = 'tag') {
    if(!$contents) return array();

    if(!function_exists('xml_parser_create')) {
        //print "'xml_parser_create()' function not found!";
        return array();
    }

    $contents = str_replace(array("<", ">", """, "&", "%3a", "%2f", "%25"), array("<", ">", "\"", "&", ":", "/", "%"), $contents);
    //Get the XML parser of PHP - PHP must have this module for the parser to work
    $parser = xml_parser_create('');
    xml_parser_set_option($parser, XML_OPTION_TARGET_ENCODING, "UTF-8");
    xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);
    xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1);
    xml_parse_into_struct($parser, trim($contents), $xml_values);
    xml_parser_free($parser);

    if(!$xml_values) return;//Hmm...

    //Initializations
    $xml_array = array();
    $parents = array();
    $opened_tags = array();
    $arr = array();

    $current = &$xml_array; //Refference

    //Go through the tags.
    $repeated_tag_index = array();//Multiple tags with same name will be turned into an array
    foreach($xml_values as $data) {
        unset($attributes,$value);//Remove existing values, or there will be trouble

        //This command will extract these variables into the foreach scope
        // tag(string), type(string), level(int), attributes(array).
        extract($data);//We could use the array by itself, but this cooler.

        $result = array();
        $attributes_data = array();

        if(isset($value)) {
            if($priority == 'tag') $result = $value;
            else $result['value'] = $value; //Put the value in a assoc array if we are in the 'Attribute' mode
        }

        //Set the attributes too.
        if(isset($attributes) and $get_attributes) {
            foreach($attributes as $attr => $val) {
                if($priority == 'tag') $attributes_data[$attr] = $val;
                else $result['attr'][$attr] = $val; //Set all the attributes in a array called 'attr'
            }
        }

        //See tag status and do the needed.
        if($type == "open") {//The starting of the tag '<tag>'
            $parent[$level-1] = &$current;
            if(!is_array($current) or (!in_array($tag, array_keys($current)))) { //Insert New tag
                $current[$tag] = $result;
                if($attributes_data) $current[$tag. '_attr'] = $attributes_data;
                $repeated_tag_index[$tag.'_'.$level] = 1;

                $current = &$current[$tag];

            } else { //There was another element with the same tag name

                if(isset($current[$tag][0])) {//If there is a 0th element it is already an array
                    $current[$tag][$repeated_tag_index[$tag.'_'.$level]] = $result;
                } else {//This section will make the value an array if multiple tags with the same name appear together
                    $current[$tag] = array($current[$tag],$result);//This will combine the existing item and the new item together to make an array

                    if(isset($current[$tag.'_attr'])) { //The attribute of the last(0th) tag must be moved as well
                        $current[$tag]['0_attr'] = $current[$tag.'_attr'];
                        unset($current[$tag.'_attr']);
                    }
                }
                if($attributes_data) $current[$tag][$repeated_tag_index[$tag.'_'.$level] . '_attr'] = $attributes_data;
                $repeated_tag_index[$tag.'_'.$level]++;
                $last_item_index = $repeated_tag_index[$tag.'_'.$level]-1;
                $current = &$current[$tag][$last_item_index];
            }

        } elseif($type == "complete") { //Tags that ends in 1 line '<tag/>'

            // turn empty array to empty string
            if (is_array($result) && empty($result)) {
                $result = '';
            }

            //See if the key is already taken.
            if(!isset($current[$tag])) { //New Key
                $current[$tag] = $result;
                $repeated_tag_index[$tag.'_'.$level] = 1;
                if($priority == 'tag' and $attributes_data) $current[$tag. '_attr'] = $attributes_data;

            } else { //If taken, put all things inside a list(array)

                if(isset($current[$tag][0]) and is_array($current[$tag])) {//If it is already an array...

                    // ...push the new element into that array.
                    $current[$tag][$repeated_tag_index[$tag.'_'.$level]] = $result;

                    if($priority == 'tag' and $get_attributes and $attributes_data) {
                        $current[$tag][$repeated_tag_index[$tag.'_'.$level] . '_attr'] = $attributes_data;
                    }
                    $repeated_tag_index[$tag.'_'.$level]++;

                } else { //If it is not an array...
                    $current[$tag] = array($current[$tag],$result); //...Make it an array using using the existing value and the new value
                    $repeated_tag_index[$tag.'_'.$level] = 1;
                    if($priority == 'tag' and $get_attributes) {
                        if(isset($current[$tag.'_attr'])) { //The attribute of the last(0th) tag must be moved as well

                            $current[$tag]['0_attr'] = $current[$tag.'_attr'];
                            unset($current[$tag.'_attr']);
                        }

                        if($attributes_data) {
                            $current[$tag][$repeated_tag_index[$tag.'_'.$level] . '_attr'] = $attributes_data;
                        }
                    }
                    $repeated_tag_index[$tag.'_'.$level]++; //0 and 1 index is already taken
                }
            }

        } elseif($type == 'close') { //End of tag '</tag>'
            $current = &$parent[$level-1];
        }
    }

    return($xml_array);
}


function array_search_key($array,$search)
{
        $key = preg_grep('/'.$search.'/', array_keys($array));
        if (isset($key[0])){
        return($key);
        }

    return false;

}

function array_check($array,$key)
{
    return (isset($array[$key]) || array_key_exists($key,$array));
}

//------------------------------------------------------------------------------

//XML in Array umwandeln
$DIDL = (xml2array($xml2));
print_r($DIDL);

$liste = array();
$i = 0;

if(array_check($DIDL,'container'))
	{
	$keys = array_search_key($DIDL['container'],"[0-9]$");
   $count = count($keys);

   for ($i=0; $i < $count; $i++)
   	{
		$liste[$i]['typ']                       = 'container';
		$liste[$i]['metadata']                  = $MetaData;

		if(isset($DIDL['container'][$i."_attr"]['id']))
		$liste[$i]['id']                        = $DIDL['container'][$i."_attr"]['id'];
		if(isset($DIDL['container'][$i."_attr"]['refID']))
		$liste[$i]['refid']                     = $DIDL['container'][$i."_attr"]['refID'];
		if(isset($DIDL['container'][$i."_attr"]['parentID']))
		$liste[$i]['parentid']                  = $DIDL['container'][$i."_attr"]['parentID'];
		if(isset($DIDL['container'][$i."_attr"]['restricted']))
		$liste[$i]['restricted']                = $DIDL['container'][$i."_attr"]['restricted'];

		$key = array_search_key($DIDL['container'][$i],"artist$")[0];
		if($key)
		$liste[$i]['artist']                    = $DIDL['container'][$i][$key];
		$key = array_search_key($DIDL['container'][$i],"album$")[0];
		if($key)
		$liste[$i]['album']                     = $DIDL['container'][$i][$key];
		$key = array_search_key($DIDL['container'][$i],"title$")[0];
		if($key)
		$liste[$i]['title']                     = $DIDL['container'][$i][$key];
   	}
	}

if(array_check($DIDL,'item'))
	{
   $keys = array_search_key($DIDL['item'],"[0-9]$");
   $count = (count($keys));
   echo($keys);
   $n = $i;

   for ($i=0; $i < $count; $i++)
   	{
		$liste[$n+$i]['typ']                       = 'item';
		$liste[$n+$i]['metadata']                  = $MetaData;

		if(isset($DIDL['item'][$i."_attr"]['id']))
		$liste[$n+$i]['id']                        = $DIDL['item'][$i."_attr"]['id'];
		if(isset($DIDL['item'][$i."_attr"]['refID']))
		$liste[$n+$i]['refid']                     = $DIDL['item'][$i."_attr"]['refID'];
		if(isset($DIDL['item'][$i."_attr"]['parentID']))
		$liste[$n+$i]['parentid']                  = $DIDL['item'][$i."_attr"]['parentID'];
		if(isset($DIDL['item'][$i."_attr"]['restricted']))
		$liste[$n+$i]['restricted']                = $DIDL['item'][$i."_attr"]['restricted'];

		$key = array_search_key($DIDL['item'][$i],"artist$")[0];
		if($key)
		$liste[$n+$i]['artist']                    = $DIDL['item'][$i][$key];
		$key = array_search_key($DIDL['item'][$i],"album$")[0];
		if($key)
		$liste[$n+$i]['album']                     = $DIDL['item'][$i][$key];
		$key = array_search_key($DIDL['item'][$i],"title$")[0];
		if($key)
		$liste[$n+$i]['title']                     = $DIDL['item'][$i][$key];

		if(isset($DIDL['item'][$i]['res'][0]))
		$liste[$n+$i]['resource']                  = $DIDL['item'][$i]['res'][0];
		if(isset($DIDL['item'][$i]['res']['0_attr']['duration']))
		$liste[$n+$i]['duration']                  = $DIDL['item'][$i]['res']['0_attr']['duration'];
		if(isset($DIDL['item'][$i]['res']['0_attr']['size']))
		$liste[$n+$i]['size']                      = $DIDL['item'][$i]['res']['0_attr']['size'];
		if(isset($DIDL['item'][$i]['res']['0_attr']['bitrate']))
		$liste[$n+$i]['bitrate']                   = $DIDL['item'][$i]['res']['0_attr']['bitrate'];

		$key = array_search_key($DIDL['item'][$i],"albumArtURI$")[0];
		if($key)
		$liste[$n+$i]['albumArtURI']               = $DIDL['item'][$i][$key];

		$key = array_search_key($DIDL['item'][$i],"genre$")[0];
		if($key)
		$liste[$n+$i]['genre']                     = $DIDL['item'][$i][$key];

		$key = array_search_key($DIDL['item'][$i],"date$")[0];
		if($key)
		$liste[$n+$i]['date']                      = $DIDL['item'][$i][$key];

		$key = array_search_key($DIDL['item'][$i],"originalTrackNumber$")[0];
		if($key)
		$liste[$n+$i]['originalTrackNumber']       = $DIDL['item'][$i][$key];

		$key = array_search_key($DIDL['item'][$i],"class$")[0];
		if($key)
		$liste[$n+$i]['class']                     = $DIDL['item'][$i][$key];
   	}
	}

print_r($liste);

?>

Gut wäre ein Array mit [Result], [NumberReturned], [TotalMatches], [UpdateID].
[Result] würde man dann weiter nach Array $liste konvertieren.

Viele Grüße

André

Moin DigiHouse,

ich bin jetzt dabei die Scripte zusammenzubringen und zu vervollständigen.
Dabei habe ich noch eine Frage, wie muss sich $MetaData zusammenstellen?
Nebenbei sind mir noch ein paar Sachen aufgefallen,
die sich je nach bekommenden Daten etwas anders verhalten.

Edit:das bisherige Script zum testen hinzugefügt.

MFG MNB



<?
$nxml = '<?xml version="1.0"?>
 <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
  <SOAP-ENV:Body>
   <m:BrowseResponse xmlns:m="urn:schemas-upnp-org:service:ContentDirectory:1">
    <Result xmlns:dt="urn:schemas-microsoft-com:datatypes" dt:dt="string"><DIDL-Lite xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:upnp="urn:schemas-upnp-org:metadata-1-0/upnp/"
xmlns="urn:schemas-upnp-org:metadata-1-0/DIDL-Lite/"
xmlns:microsoft="urn:schemas-microsoft-com:WMPNSS-1-0/"
xmlns:dlna="urn:schemas-dlna-org:metadata-1-0/"
><item id="6_eff1f3a5_7c0784c9-569" refID="4-569" restricted="1" parentID="6_eff1f3a5_7c0784c9"><dc:title>Mr. Saxobeat</dc:title><dc:creator>Alexandra Stan</dc:creator><res size="3122982" duration="0:03:11.608" bitrate="16000" protocolInfo="http-get:*:audio/mpeg:DLNA.ORG_PN=MP3;DLNA.ORG_OP=01;DLNA.ORG_FLAGS=01700000000000000000000000000000" sampleFrequency="44100" bitsPerSample="16" nrAudioChannels="2" microsoft:codec="{00000055-0000-0010-8000-00AA00389B71}">http://127.0.0.1:10243/WMPNSSv4/3561040673/1_Nl9lZmYxZjNhNV83YzA3ODRjOS01Njk.mp3</res><res duration="0:03:11.608" bitrate="176400" protocolInfo="http-get:*:audio/L16;rate=44100;channels=2:DLNA.ORG_PN=LPCM;DLNA.ORG_OP=10;DLNA.ORG_CI=1;DLNA.ORG_FLAGS=01700000000000000000000000000000" sampleFrequency="44100" bitsPerSample="16" nrAudioChannels="2" microsoft:codec="{00000001-0000-0010-8000-00AA00389B71}">http://127.0.0.1:10243/WMPNSSv4/3561040673/Nl9lZmYxZjNhNV83YzA3ODRjOS01Njk.mp3?formatID=39</res><res duration="0:03:11.608" bitrate="88200" protocolInfo="http-get:*:audio/L16;rate=44100;channels=1:DLNA.ORG_PN=LPCM;DLNA.ORG_OP=10;DLNA.ORG_CI=1;DLNA.ORG_FLAGS=01700000000000000000000000000000" sampleFrequency="44100" bitsPerSample="16" nrAudioChannels="1" microsoft:codec="{00000001-0000-0010-8000-00AA00389B71}">http://127.0.0.1:10243/WMPNSSv4/3561040673/Nl9lZmYxZjNhNV83YzA3ODRjOS01Njk.mp3?formatID=37</res><res duration="0:03:11.608" bitrate="24000" protocolInfo="http-get:*:audio/mp4:DLNA.ORG_PN=AAC_ISO_320;DLNA.ORG_OP=10;DLNA.ORG_CI=1;DLNA.ORG_FLAGS=01700000000000000000000000000000" sampleFrequency="48000" nrAudioChannels="2" microsoft:codec="{00001610-0000-0010-8000-00AA00389B71}">http://127.0.0.1:10243/WMPNSSv4/3561040673/Nl9lZmYxZjNhNV83YzA3ODRjOS01Njk.m4a?formatID=25</res><res duration="0:03:11.608" bitrate="32000" protocolInfo="http-get:*:audio/vnd.dolby.dd-raw:DLNA.ORG_PN=AC3;DLNA.ORG_OP=10;DLNA.ORG_CI=1;DLNA.ORG_FLAGS=01700000000000000000000000000000" sampleFrequency="48000" nrAudioChannels="2" microsoft:codec="{E06D802C-DB46-11CF-B4D1-00805F6CBBEA}">http://127.0.0.1:10243/WMPNSSv4/3561040673/Nl9lZmYxZjNhNV83YzA3ODRjOS01Njk.mp3?formatID=28</res><res duration="0:03:11.608" bitrate="24000" protocolInfo="http-get:*:audio/vnd.dlna.adts:DLNA.ORG_PN=AAC_ADTS_320;DLNA.ORG_OP=10;DLNA.ORG_CI=1;DLNA.ORG_FLAGS=01700000000000000000000000000000" sampleFrequency="48000" nrAudioChannels="2" microsoft:codec="{00001610-0000-0010-8000-00AA00389B71}">http://127.0.0.1:10243/WMPNSSv4/3561040673/Nl9lZmYxZjNhNV83YzA3ODRjOS01Njk.adts?formatID=30</res><res duration="0:03:11.608" bitrate="8000" protocolInfo="http-get:*:audio/x-ms-wma:DLNA.ORG_PN=WMABASE;DLNA.ORG_OP=10;DLNA.ORG_CI=1;DLNA.ORG_FLAGS=01700000000000000000000000000000" sampleFrequency="44100" nrAudioChannels="2" microsoft:codec="{00000161-0000-0010-8000-00AA00389B71}">http://127.0.0.1:10243/WMPNSSv4/3561040673/Nl9lZmYxZjNhNV83YzA3ODRjOS01Njk.wma?formatID=118</res><upnp:class>object.item.audioItem.musicTrack</upnp:class><upnp:genre>Dance</upnp:genre><dc:publisher>RMNradio</dc:publisher><upnp:artist role="AlbumArtist">Alexandra Stan</upnp:artist><upnp:artist role="Performer">Alexandra Stan</upnp:artist><upnp:author role="Composer">[Unbekannter Komponist]</upnp:author><upnp:album>Saxobeats</upnp:album><upnp:originalTrackNumber>0</upnp:originalTrackNumber><dc:date>2011-01-02</dc:date><upnp:actor role="Alexandra Stan">Alexandra Stan</upnp:actor><dc:description>www.radio-fx.de</dc:description><upnp:albumArtURI dlna:profileID="JPEG_SM">http://127.0.0.1:10243/WMPNSSv4/3561040673/0_Nl9lZmYxZjNhNV83YzA3ODRjOS01Njk.jpg?albumArt=true</upnp:albumArtURI><upnp:albumArtURI dlna:profileID="JPEG_TN">http://127.0.0.1:10243/WMPNSSv4/3561040673/Nl9lZmYxZjNhNV83YzA3ODRjOS01Njk.jpg?albumArt=true,formatID=32,width=160,height=160</upnp:albumArtURI><desc id="artist" nameSpace="urn:schemas-microsoft-com:WMPNSS-1-0/" xmlns:microsoft="urn:schemas-microsoft-com:WMPNSS-1-0/">&lt;microsoft:artistAlbumArtist&gt;Alexandra Stan&lt;/microsoft:artistAlbumArtist&gt;&lt;microsoft:artistPerformer&gt;Alexandra Stan&lt;/microsoft:artistPerformer&gt;</desc><desc id="author" nameSpace="urn:schemas-microsoft-com:WMPNSS-1-0/" xmlns:microsoft="urn:schemas-microsoft-com:WMPNSS-1-0/">&lt;microsoft:authorComposer&gt;[Unbekannter Komponist]&lt;/microsoft:authorComposer&gt;</desc><desc id="Year" nameSpace="urn:schemas-microsoft-com:WMPNSS-1-0/" xmlns:microsoft="urn:schemas-microsoft-com:WMPNSS-1-0/">&lt;microsoft:year&gt;2011&lt;/microsoft:year&gt;</desc><desc id="folderPath" nameSpace="urn:schemas-microsoft-com:WMPNSS-1-0/" xmlns:microsoft="urn:schemas-microsoft-com:WMPNSS-1-0/">&lt;microsoft:folderPath&gt;Freigegebene Musik\MP3´s - 05 fertig&lt;/microsoft:folderPath&gt;</desc><desc id="fileInfo" nameSpace="urn:schemas-microsoft-com:WMPNSS-1-0/" xmlns:microsoft="urn:schemas-microsoft-com:WMPNSS-1-0/">&lt;microsoft:fileIdentifier&gt;AMGa_id=R  2287667;AMGp_id=P  2354320;AMGt_id=T 24415507&lt;/microsoft:fileIdentifier&gt;</desc></item>
</DIDL-Lite></Result>
    <NumberReturned xmlns:dt="urn:schemas-microsoft-com:datatypes" dt:dt="ui4">1</NumberReturned>
    <TotalMatches xmlns:dt="urn:schemas-microsoft-com:datatypes" dt:dt="ui4">1</TotalMatches>
    <UpdateID xmlns:dt="urn:schemas-microsoft-com:datatypes" dt:dt="ui4">9</UpdateID>
   </m:BrowseResponse>
  </SOAP-ENV:Body>
 </SOAP-ENV:Envelope>';


$nxml = '<?xml version="1.0"?>
 <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
  <SOAP-ENV:Body>
   <m:BrowseResponse xmlns:m="urn:schemas-upnp-org:service:ContentDirectory:1">
    <Result xmlns:dt="urn:schemas-microsoft-com:datatypes" dt:dt="string"><DIDL-Lite xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:upnp="urn:schemas-upnp-org:metadata-1-0/upnp/"
xmlns="urn:schemas-upnp-org:metadata-1-0/DIDL-Lite/"
xmlns:microsoft="urn:schemas-microsoft-com:WMPNSS-1-0/"
xmlns:dlna="urn:schemas-dlna-org:metadata-1-0/"
><item id="6_eff1f3a5_7c0784c9-569" refID="4-569" restricted="1" parentID="6_eff1f3a5_7c0784c9"><dc:title>Mr. Saxobeat</dc:title><dc:creator>Alexandra Stan</dc:creator><res size="3122982" duration="0:03:11.608" bitrate="16000" protocolInfo="http-get:*:audio/mpeg:DLNA.ORG_PN=MP3;DLNA.ORG_OP=01;DLNA.ORG_FLAGS=01700000000000000000000000000000" sampleFrequency="44100" bitsPerSample="16" nrAudioChannels="2" microsoft:codec="{00000055-0000-0010-8000-00AA00389B71}">http://127.0.0.1:10243/WMPNSSv4/3561040673/1_Nl9lZmYxZjNhNV83YzA3ODRjOS01Njk.mp3</res><res duration="0:03:11.608" bitrate="176400" protocolInfo="http-get:*:audio/L16;rate=44100;channels=2:DLNA.ORG_PN=LPCM;DLNA.ORG_OP=10;DLNA.ORG_CI=1;DLNA.ORG_FLAGS=01700000000000000000000000000000" sampleFrequency="44100" bitsPerSample="16" nrAudioChannels="2" microsoft:codec="{00000001-0000-0010-8000-00AA00389B71}">http://127.0.0.1:10243/WMPNSSv4/3561040673/Nl9lZmYxZjNhNV83YzA3ODRjOS01Njk.mp3?formatID=39</res><res duration="0:03:11.608" bitrate="88200" protocolInfo="http-get:*:audio/L16;rate=44100;channels=1:DLNA.ORG_PN=LPCM;DLNA.ORG_OP=10;DLNA.ORG_CI=1;DLNA.ORG_FLAGS=01700000000000000000000000000000" sampleFrequency="44100" bitsPerSample="16" nrAudioChannels="1" microsoft:codec="{00000001-0000-0010-8000-00AA00389B71}">http://127.0.0.1:10243/WMPNSSv4/3561040673/Nl9lZmYxZjNhNV83YzA3ODRjOS01Njk.mp3?formatID=37</res><res duration="0:03:11.608" bitrate="24000" protocolInfo="http-get:*:audio/mp4:DLNA.ORG_PN=AAC_ISO_320;DLNA.ORG_OP=10;DLNA.ORG_CI=1;DLNA.ORG_FLAGS=01700000000000000000000000000000" sampleFrequency="48000" nrAudioChannels="2" microsoft:codec="{00001610-0000-0010-8000-00AA00389B71}">http://127.0.0.1:10243/WMPNSSv4/3561040673/Nl9lZmYxZjNhNV83YzA3ODRjOS01Njk.m4a?formatID=25</res><res duration="0:03:11.608" bitrate="32000" protocolInfo="http-get:*:audio/vnd.dolby.dd-raw:DLNA.ORG_PN=AC3;DLNA.ORG_OP=10;DLNA.ORG_CI=1;DLNA.ORG_FLAGS=01700000000000000000000000000000" sampleFrequency="48000" nrAudioChannels="2" microsoft:codec="{E06D802C-DB46-11CF-B4D1-00805F6CBBEA}">http://127.0.0.1:10243/WMPNSSv4/3561040673/Nl9lZmYxZjNhNV83YzA3ODRjOS01Njk.mp3?formatID=28</res><res duration="0:03:11.608" bitrate="24000" protocolInfo="http-get:*:audio/vnd.dlna.adts:DLNA.ORG_PN=AAC_ADTS_320;DLNA.ORG_OP=10;DLNA.ORG_CI=1;DLNA.ORG_FLAGS=01700000000000000000000000000000" sampleFrequency="48000" nrAudioChannels="2" microsoft:codec="{00001610-0000-0010-8000-00AA00389B71}">http://127.0.0.1:10243/WMPNSSv4/3561040673/Nl9lZmYxZjNhNV83YzA3ODRjOS01Njk.adts?formatID=30</res><res duration="0:03:11.608" bitrate="8000" protocolInfo="http-get:*:audio/x-ms-wma:DLNA.ORG_PN=WMABASE;DLNA.ORG_OP=10;DLNA.ORG_CI=1;DLNA.ORG_FLAGS=01700000000000000000000000000000" sampleFrequency="44100" nrAudioChannels="2" microsoft:codec="{00000161-0000-0010-8000-00AA00389B71}">http://127.0.0.1:10243/WMPNSSv4/3561040673/Nl9lZmYxZjNhNV83YzA3ODRjOS01Njk.wma?formatID=118</res><upnp:class>object.item.audioItem.musicTrack</upnp:class><upnp:genre>Dance</upnp:genre><dc:publisher>RMNradio</dc:publisher><upnp:artist role="AlbumArtist">Alexandra Stan</upnp:artist><upnp:artist role="Performer">Alexandra Stan</upnp:artist><upnp:author role="Composer">[Unbekannter Komponist]</upnp:author><upnp:album>Saxobeats</upnp:album><upnp:originalTrackNumber>0</upnp:originalTrackNumber><dc:date>2011-01-02</dc:date><upnp:actor role="Alexandra Stan">Alexandra Stan</upnp:actor><dc:description>www.radio-fx.de</dc:description><upnp:albumArtURI dlna:profileID="JPEG_SM">http://127.0.0.1:10243/WMPNSSv4/3561040673/0_Nl9lZmYxZjNhNV83YzA3ODRjOS01Njk.jpg?albumArt=true</upnp:albumArtURI><upnp:albumArtURI dlna:profileID="JPEG_TN">http://127.0.0.1:10243/WMPNSSv4/3561040673/Nl9lZmYxZjNhNV83YzA3ODRjOS01Njk.jpg?albumArt=true,formatID=32,width=160,height=160</upnp:albumArtURI><desc id="artist" nameSpace="urn:schemas-microsoft-com:WMPNSS-1-0/" xmlns:microsoft="urn:schemas-microsoft-com:WMPNSS-1-0/">&lt;microsoft:artistAlbumArtist&gt;Alexandra Stan&lt;/microsoft:artistAlbumArtist&gt;&lt;microsoft:artistPerformer&gt;Alexandra Stan&lt;/microsoft:artistPerformer&gt;</desc><desc id="author" nameSpace="urn:schemas-microsoft-com:WMPNSS-1-0/" xmlns:microsoft="urn:schemas-microsoft-com:WMPNSS-1-0/">&lt;microsoft:authorComposer&gt;[Unbekannter Komponist]&lt;/microsoft:authorComposer&gt;</desc><desc id="Year" nameSpace="urn:schemas-microsoft-com:WMPNSS-1-0/" xmlns:microsoft="urn:schemas-microsoft-com:WMPNSS-1-0/">&lt;microsoft:year&gt;2011&lt;/microsoft:year&gt;</desc><desc id="folderPath" nameSpace="urn:schemas-microsoft-com:WMPNSS-1-0/" xmlns:microsoft="urn:schemas-microsoft-com:WMPNSS-1-0/">&lt;microsoft:folderPath&gt;Freigegebene Musik\MP3´s - 05 fertig&lt;/microsoft:folderPath&gt;</desc><desc id="fileInfo" nameSpace="urn:schemas-microsoft-com:WMPNSS-1-0/" xmlns:microsoft="urn:schemas-microsoft-com:WMPNSS-1-0/">&lt;microsoft:fileIdentifier&gt;AMGa_id=R  2287667;AMGp_id=P  2354320;AMGt_id=T 24415507&lt;/microsoft:fileIdentifier&gt;</desc></item>
</DIDL-Lite></Result>
    <NumberReturned xmlns:dt="urn:schemas-microsoft-com:datatypes" dt:dt="ui4">1</NumberReturned>
    <TotalMatches xmlns:dt="urn:schemas-microsoft-com:datatypes" dt:dt="ui4">1</TotalMatches>
    <UpdateID xmlns:dt="urn:schemas-microsoft-com:datatypes" dt:dt="ui4">9</UpdateID>
   </m:BrowseResponse>
  </SOAP-ENV:Body>
 </SOAP-ENV:Envelope>';

$nxml = '<?xml version="1.0" encoding="utf-8"?>
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<s:Body>
<u:BrowseResponse xmlns:u="urn:schemas-upnp-org:service:ContentDirectory:1">
<Result><DIDL-Lite xmlns="urn:schemas-upnp-org:metadata-1-0/DIDL-Lite/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:upnp="urn:schemas-upnp-org:metadata-1-0/upnp/"><container id="0$1" childCount="1" parentID="0" restricted="true"><dc:title>Recently Played</dc:title><upnp:albumArtURI xmlns:dlna="urn:schemas-dlna-org:metadata-1-0/" dlna:profileID="PNG_TN">http://192.168.1.84:5001/get/0$1/thumbnail0000Recently+Played</upnp:albumArtURI><upnp:class>object.container.storageFolder</upnp:class></container><container id="0$2" childCount="1" parentID="0" restricted="true"><dc:title>New Media</dc:title><upnp:albumArtURI xmlns:dlna="urn:schemas-dlna-org:metadata-1-0/" dlna:profileID="PNG_TN">http://192.168.1.84:5001/get/0$2/thumbnail0000New+Media</upnp:albumArtURI><upnp:class>object.container.storageFolder</upnp:class></container><container id="0$3" childCount="37" parentID="0" restricted="true"><dc:title>!(0TV) Various</dc:title><upnp:albumArtURI xmlns:dlna="urn:schemas-dlna-org:metadata-1-0/" dlna:profileID="JPEG_TN">http://192.168.1.84:5001/get/0$3/thumbnail0000%21%280TV%29+Various</upnp:albumArtURI><dc:date>2014-02-14T10:43:31</dc:date><upnp:class>object.container.storageFolder</upnp:class></container><container id="0$4" childCount="1" parentID="0" restricted="true"><dc:title>!(0) Movies</dc:title><upnp:albumArtURI xmlns:dlna="urn:schemas-dlna-org:metadata-1-0/" dlna:profileID="JPEG_TN">http://192.168.1.84:5001/get/0$4/thumbnail0000%21%280%29+Movies</upnp:albumArtURI><dc:date>2014-02-10T08:57:37</dc:date><upnp:class>object.container.storageFolder</upnp:class></container><container id="0$5" childCount="13" parentID="0" restricted="true"><dc:title>DLNAtest</dc:title><upnp:albumArtURI xmlns:dlna="urn:schemas-dlna-org:metadata-1-0/" dlna:profileID="JPEG_TN">http://192.168.1.84:5001/get/0$5/thumbnail0000DLNAtest</upnp:albumArtURI><dc:date>2014-01-31T07:54:33</dc:date><upnp:class>object.container.storageFolder</upnp:class></container><container id="0$6" childCount="7" parentID="0" restricted="true"><dc:title>Web</dc:title><upnp:albumArtURI xmlns:dlna="urn:schemas-dlna-org:metadata-1-0/" dlna:profileID="JPEG_TN">http://192.168.1.84:5001/get/0$6/thumbnail0000Web</upnp:albumArtURI><upnp:class>object.container.storageFolder</upnp:class></container><container id="0$7" childCount="3" parentID="0" restricted="true"><dc:title>#- Cache -#</dc:title><upnp:albumArtURI xmlns:dlna="urn:schemas-dlna-org:metadata-1-0/" dlna:profileID="JPEG_TN">http://192.168.1.84:5001/get/0$7/thumbnail0000%23-+Cache+-%23</upnp:albumArtURI><upnp:class>object.container.storageFolder</upnp:class></container></DIDL-Lite></Result>
<NumberReturned>7</NumberReturned>
<TotalMatches>7</TotalMatches>
<UpdateID>1</UpdateID>
</u:BrowseResponse>
</s:Body>
</s:Envelope>';

$xml = '
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<s:Body>
<u:BrowseResponse xmlns:u="urn:schemas-upnp-org:service:ContentDirectory:1">
<Result>
<DIDL-Lite xmlns="urn:schemas-upnp-org:metadata-1-0/DIDL-Lite/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:upnp="urn:schemas-upnp-org:metadata-1-0/upnp/" xmlns:dlna="urn:schemas-dlna-org:metadata-1-0/">

<container id="co960" parentID="co857" restricted="0" searchable="1">
	<dc:title>ATB Sunset Beach DJ Session</dc:title>
	<dc:creator>Unknown</dc:creator>
	<upnp:artist></upnp:artist>
	<upnp:genre>Unknown</upnp:genre>
	<upnp:class>object.container.storageFolder</upnp:class>
</container>

<container id="co961" parentID="co857" restricted="0" searchable="1">
<dc:title>Future Memories</dc:title>
<dc:creator>Unknown</dc:creator>
<upnp:artist></upnp:artist>
<upnp:genre>Unknown</upnp:genre>
<upnp:class>object.container.storageFolder</upnp:class>
</container>

<item id="d8844-co857" parentID="co857" restricted="0">
<dc:title>01 - Could You Believe (Airplay Mix)</dc:title>
<dc:creator>ATB</dc:creator>
<dc:date>2010-01-01</dc:date>
<upnp:artist role="AlbumArtist">ATB</upnp:artist>
<upnp:artist role="Composer">Jennifer Karr</upnp:artist>
<upnp:artist role="Performer">ATB</upnp:artist>
<upnp:album>ATB Sunset Beach DJ Session</upnp:album>
<upnp:genre>Dance &amp; DJ</upnp:genre>
<upnp:albumArtURI dlna:profileID="JPEG_TN">http://192.168.178.64:26125/aa/221781/740880359/cover.jpg?size=0</upnp:albumArtURI>
<upnp:originalTrackNumber>1</upnp:originalTrackNumber>
<upnp:originalDiscNumber>1</upnp:originalDiscNumber>
<upnp:originalDiscCount>1</upnp:originalDiscCount>
<res duration="0:03:29.000" size="7360435" bitrate="35101" bitsPerSample="16" sampleFrequency="44100" nrAudioChannels="2" protocolInfo="http-get:*:audio/mpeg:DLNA.ORG_PN=MP3;DLNA.ORG_OP=01">http://192.168.178.64:26125/content/c2/b16/f44100/d8844-co857.mp3</res>
<upnp:class>object.item.audioItem.musicTrack</upnp:class>
</item>

<item id="d8846-co857" parentID="co857" restricted="0">
<dc:title>01 - L.A. Nights</dc:title>
<dc:creator>ATB</dc:creator>
<dc:date>2009-01-01</dc:date>
<upnp:artist role="AlbumArtist">ATB</upnp:artist>
<upnp:artist role="Composer">André Tanneberger</upnp:artist>
<upnp:artist role="Performer">ATB</upnp:artist>
<upnp:album>Future Memories</upnp:album>
<upnp:genre>Dance &amp; DJ</upnp:genre>
<upnp:albumArtURI dlna:profileID="JPEG_TN">http://192.168.178.64:26125/aa/51525/2480797350/cover.jpg?size=0</upnp:albumArtURI>
<upnp:originalTrackNumber>1</upnp:originalTrackNumber>
<upnp:originalDiscNumber>1</upnp:originalDiscNumber>
<upnp:originalDiscCount>1</upnp:originalDiscCount>
<res duration="0:04:32.000" size="9074176" bitrate="33275" bitsPerSample="16" sampleFrequency="44100" nrAudioChannels="2" protocolInfo="http-get:*:audio/mpeg:DLNA.ORG_PN=MP3;DLNA.ORG_OP=01">http://192.168.178.64:26125/content/c2/b16/f44100/d8846-co857.mp3</res>
<res duration="0:04:32.000" size="48103792" bitrate="176400" bitsPerSample="16" sampleFrequency="44100" nrAudioChannels="2" protocolInfo="http-get:*:audio/wav:DLNA.ORG_PN=WAV;DLNA.ORG_OP=01">http://192.168.178.64:26125/content/c2/b16/f44100/d8846-co857.forced.wav</res>
<res duration="0:04:32.000" size="48103748" bitrate="176400" bitsPerSample="16" sampleFrequency="44100" nrAudioChannels="2" protocolInfo="http-get:*:audio/L16:DLNA.ORG_PN=LPCM;DLNA.ORG_OP=01;DLNA.ORG_CI=1">http://192.168.178.64:26125/content/c2/b16/f44100/d8846-co857.forced.l16</res>
<res duration="0:04:32.000" size="9074176" bitrate="33275" bitsPerSample="16" sampleFrequency="44100" nrAudioChannels="2" protocolInfo="http-get:*:audio/mpeg:DLNA.ORG_PN=MP3;DLNA.ORG_OP=01">http://192.168.178.64:26125/content/c2/b16/f44100/d8846-co857.mp3</res>
<upnp:class>object.item.audioItem.musicTrack</upnp:class>
</item>

<item id="d8845-co857" parentID="co857" restricted="0">
<dc:title>02 - Right Back (Original Mix)</dc:title>
<dc:creator>ATB</dc:creator><dc:date>2010-01-01</dc:date>
<upnp:artist role="AlbumArtist">ATB</upnp:artist>
<upnp:artist role="Composer">Yuri Kane</upnp:artist>
<upnp:artist role="Performer">Yuri Kane</upnp:artist>
<upnp:album>ATB Sunset Beach DJ Session</upnp:album>
<upnp:genre>Dance &amp; DJ</upnp:genre>
<upnp:albumArtURI dlna:profileID="JPEG_TN">http://192.168.178.64:26125/aa/221781/740880359/cover.jpg?size=0</upnp:albumArtURI>
<upnp:originalTrackNumber>2</upnp:originalTrackNumber>
<upnp:originalDiscNumber>1</upnp:originalDiscNumber>
<upnp:originalDiscCount>1</upnp:originalDiscCount>
<res duration="0:05:56.000" size="11797385" bitrate="33070" bitsPerSample="16" sampleFrequency="44100" nrAudioChannels="2" protocolInfo="http-get:*:audio/mpeg:DLNA.ORG_PN=MP3;DLNA.ORG_OP=01">http://192.168.178.64:26125/content/c2/b16/f44100/d8845-co857.mp3</res>
<res duration="0:05:56.000" size="62927920" bitrate="176400" bitsPerSample="16" sampleFrequency="44100" nrAudioChannels="2" protocolInfo="http-get:*:audio/wav:DLNA.ORG_PN=WAV;DLNA.ORG_OP=01">http://192.168.178.64:26125/content/c2/b16/f44100/d8845-co857.forced.wav</res>
<res duration="0:05:56.000" size="62927876" bitrate="176400" bitsPerSample="16" sampleFrequency="44100" nrAudioChannels="2" protocolInfo="http-get:*:audio/L16:DLNA.ORG_PN=LPCM;DLNA.ORG_OP=01;DLNA.ORG_CI=1">http://192.168.178.64:26125/content/c2/b16/f44100/d8845-co857.forced.l16</res>
<res duration="0:05:56.000" size="11797385" bitrate="33070" bitsPerSample="16" sampleFrequency="44100" nrAudioChannels="2" protocolInfo="http-get:*:audio/mpeg:DLNA.ORG_PN=MP3;DLNA.ORG_OP=01">http://192.168.178.64:26125/content/c2/b16/f44100/d8845-co857.mp3</res>
<upnp:class>object.item.audioItem.musicTrack</upnp:class>
</item>

<item id="d8847-co857" parentID="co857" restricted="0">
<dc:title>02 - What About Us</dc:title><dc:creator>ATB</dc:creator><dc:date>2009-01-01</dc:date><upnp:artist role="AlbumArtist">ATB</upnp:artist><upnp:artist role="Composer">Rudi Dittmann</upnp:artist><upnp:artist role="Performer">ATB</upnp:artist><upnp:album>Future Memories</upnp:album><upnp:genre>Dance &amp; DJ</upnp:genre><upnp:albumArtURI dlna:profileID="JPEG_TN">http://192.168.178.64:26125/aa/51525/2480797350/cover.jpg?size=0</upnp:albumArtURI><upnp:originalTrackNumber>2</upnp:originalTrackNumber><upnp:originalDiscNumber>1</upnp:originalDiscNumber><upnp:originalDiscCount>1</upnp:originalDiscCount><res duration="0:05:35.000" size="11756320" bitrate="35074" bitsPerSample="16" sampleFrequency="44100" nrAudioChannels="2" protocolInfo="http-get:*:audio/mpeg:DLNA.ORG_PN=MP3;DLNA.ORG_OP=01">http://192.168.178.64:26125/content/c2/b16/f44100/d8847-co857.mp3</res><res duration="0:05:35.000" size="59126676" bitrate="176400" bitsPerSample="16" sampleFrequency="44100" nrAudioChannels="2" protocolInfo="http-get:*:audio/wav:DLNA.ORG_PN=WAV;DLNA.ORG_OP=01">http://192.168.178.64:26125/content/c2/b16/f44100/d8847-co857.forced.wav</res><res duration="0:05:35.000" size="59126632" bitrate="176400" bitsPerSample="16" sampleFrequency="44100" nrAudioChannels="2" protocolInfo="http-get:*:audio/L16:DLNA.ORG_PN=LPCM;DLNA.ORG_OP=01;DLNA.ORG_CI=1">http://192.168.178.64:26125/content/c2/b16/f44100/d8847-co857.forced.l16</res><res duration="0:05:35.000" size="11756320" bitrate="35074" bitsPerSample="16" sampleFrequency="44100" nrAudioChannels="2" protocolInfo="http-get:*:audio/mpeg:DLNA.ORG_PN=MP3;DLNA.ORG_OP=01">http://192.168.178.64:26125/content/c2/b16/f44100/d8847-co857.mp3</res><upnp:class>object.item.audioItem.musicTrack</upnp:class></item>

</DIDL-Lite>
</Result>
<NumberReturned>7</NumberReturned>
<TotalMatches>7</TotalMatches>
<UpdateID>1</UpdateID>
</u:BrowseResponse>
</s:Body>
</s:Envelope>';


//DIDL umwandeln
$DIDL = (xml2array($xml));
//print_r($DIDL);


//Array $Liste erstellen
$liste = BrowseList($DIDL);
print_r($liste);



//Functions---------------------------------------------------------------------

function xml2array($contents, $get_attributes=1, $priority = 'tag') {
    if(!$contents) return array();

    if(!function_exists('xml_parser_create')) {
        //print "'xml_parser_create()' function not found!";
        return array();
    }

    $contents = str_replace(array("<", ">", """, "&", "%3a", "%2f", "%25"), array("<", ">", "\"", "&", ":", "/", "%"), $contents);
    //Get the XML parser of PHP - PHP must have this module for the parser to work
    $parser = xml_parser_create('');
    xml_parser_set_option($parser, XML_OPTION_TARGET_ENCODING, "UTF-8");
    xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);
    xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1);
    xml_parse_into_struct($parser, trim($contents), $xml_values);
    xml_parser_free($parser);

    if(!$xml_values) return;//Hmm...

    //Initializations
    $xml_array = array();
    $parents = array();
    $opened_tags = array();
    $arr = array();

    $current = &$xml_array; //Refference

    //Go through the tags.
    $repeated_tag_index = array();//Multiple tags with same name will be turned into an array
    foreach($xml_values as $data) {
        unset($attributes,$value);//Remove existing values, or there will be trouble

        //This command will extract these variables into the foreach scope
        // tag(string), type(string), level(int), attributes(array).
        extract($data);//We could use the array by itself, but this cooler.

        $result = array();
        $attributes_data = array();

        if(isset($value)) {
            if($priority == 'tag') $result = $value;
            else $result['value'] = $value; //Put the value in a assoc array if we are in the 'Attribute' mode
        }

        //Set the attributes too.
        if(isset($attributes) and $get_attributes) {
            foreach($attributes as $attr => $val) {
                if($priority == 'tag') $attributes_data[$attr] = $val;
                else $result['attr'][$attr] = $val; //Set all the attributes in a array called 'attr'
            }
        }

        //See tag status and do the needed.
        if($type == "open") {//The starting of the tag '<tag>'
            $parent[$level-1] = &$current;
            if(!is_array($current) or (!in_array($tag, array_keys($current)))) { //Insert New tag
                $current[$tag] = $result;
                if($attributes_data) $current[$tag. '_attr'] = $attributes_data;
                $repeated_tag_index[$tag.'_'.$level] = 1;

                $current = &$current[$tag];

            } else { //There was another element with the same tag name

                if(isset($current[$tag][0])) {//If there is a 0th element it is already an array
                    $current[$tag][$repeated_tag_index[$tag.'_'.$level]] = $result;
                } else {//This section will make the value an array if multiple tags with the same name appear together
                    $current[$tag] = array($current[$tag],$result);//This will combine the existing item and the new item together to make an array

                    if(isset($current[$tag.'_attr'])) { //The attribute of the last(0th) tag must be moved as well
                        $current[$tag]['0_attr'] = $current[$tag.'_attr'];
                        unset($current[$tag.'_attr']);
                    }
                }
                if($attributes_data) $current[$tag][$repeated_tag_index[$tag.'_'.$level] . '_attr'] = $attributes_data;
                $repeated_tag_index[$tag.'_'.$level]++;
                $last_item_index = $repeated_tag_index[$tag.'_'.$level]-1;
                $current = &$current[$tag][$last_item_index];
            }

        } elseif($type == "complete") { //Tags that ends in 1 line '<tag/>'

            // turn empty array to empty string
            if (is_array($result) && empty($result)) {
                $result = '';
            }

            //See if the key is already taken.
            if(!isset($current[$tag])) { //New Key
                $current[$tag] = $result;
                $repeated_tag_index[$tag.'_'.$level] = 1;
                if($priority == 'tag' and $attributes_data) $current[$tag. '_attr'] = $attributes_data;

            } else { //If taken, put all things inside a list(array)

                if(isset($current[$tag][0]) and is_array($current[$tag])) {//If it is already an array...

                    // ...push the new element into that array.
                    $current[$tag][$repeated_tag_index[$tag.'_'.$level]] = $result;

                    if($priority == 'tag' and $get_attributes and $attributes_data) {
                        $current[$tag][$repeated_tag_index[$tag.'_'.$level] . '_attr'] = $attributes_data;
                    }
                    $repeated_tag_index[$tag.'_'.$level]++;

                } else { //If it is not an array...
                    $current[$tag] = array($current[$tag],$result); //...Make it an array using using the existing value and the new value
                    $repeated_tag_index[$tag.'_'.$level] = 1;
                    if($priority == 'tag' and $get_attributes) {
                        if(isset($current[$tag.'_attr'])) { //The attribute of the last(0th) tag must be moved as well

                            $current[$tag]['0_attr'] = $current[$tag.'_attr'];
                            unset($current[$tag.'_attr']);
                        }

                        if($attributes_data) {
                            $current[$tag][$repeated_tag_index[$tag.'_'.$level] . '_attr'] = $attributes_data;
                        }
                    }
                    $repeated_tag_index[$tag.'_'.$level]++; //0 and 1 index is already taken
                }
            }

        } elseif($type == 'close') { //End of tag '</tag>'
            $current = &$parent[$level-1];
        }
    }

    return($xml_array);
}


function array_search_key($array,$search, $first_key_only = 1 )
{
        $key = preg_grep('/'.$search.'/', array_keys($array));
        reset($key);
        $first_key = key($key);
        if (isset($first_key)){
            if($first_key_only == 1)
            return($key[$first_key]);
            
            return($key);
        }

    return false;

}

function array_check($array,$key)
{
    if (is_array ($array))
    {
      return (isset($array[$key]) || array_key_exists($key,$array));  
    }
    return (false);
}


function BrowseList($array)
{
    if(!$array) return array();

    //zum testen
    $MetaData="blablabla";

    
    //Suche der Result im Array
    //sollte noch verbessert werden 
    $key = array_search_key($array, "Envelope$");
    $key2 = array_search_key($array[$key], "Body$");
    $key3 = array_search_key($array[$key][$key2], "BrowseResponse$");
    $key4 = array_search_key($array[$key][$key2][$key3], "Result$");    
    $DIDL = $array[$key][$key2][$key3][$key4]["DIDL-Lite"];
    $liste = array();
    $i = 0;

        if(array_check($DIDL,'container'))
        {

        $keys = array_search_key($DIDL['container'],"[0-9]$",0);
            $count = count($keys);
            if ($count==1){
                $i=0;
                $liste[$i]['typ']                       = 'container';
                $liste[$i]['metadata']                  = $MetaData;

                if(isset($DIDL['container_attr']['id']))
                $liste[$i]['id']                        = $DIDL['container_attr']['id'];
                if(isset($DIDL['container_attr']['refID']))
                $liste[$i]['refid']                     = $DIDL['container_attr']['refID'];
                if(isset($DIDL['container_attr']['parentID']))
                $liste[$i]['parentid']                  = $DIDL['container_attr']['parentID'];
                if(isset($DIDL['container_attr']['restricted']))
                $liste[$i]['restricted']                = $DIDL['container_attr']['restricted'];

                $key = array_search_key($DIDL['container'],"artist$");
                if($key)
                $liste[$i]['artist']                    = $DIDL['container'][$key];
                $key = array_search_key($DIDL['container'],"album$");
                if($key)
                $liste[$i]['album']                     = $DIDL['container'][$key];
                $key = array_search_key($DIDL['container'],"title$");
                if($key)
                $liste[$i]['title']                     = $DIDL['container'][$key]; 
            }
            else  
            {      
                for ($i=0; $i < $count; $i++)
                {
                    $liste[$i]['typ']                       = 'container';
                    $liste[$i]['metadata']                  = $MetaData;
    
                    if(isset($DIDL['container'][$i."_attr"]['id']))
                    $liste[$i]['id']                        = $DIDL['container'][$i."_attr"]['id'];
                    if(isset($DIDL['container'][$i."_attr"]['refID']))
                    $liste[$i]['refid']                     = $DIDL['container'][$i."_attr"]['refID'];
                    if(isset($DIDL['container'][$i."_attr"]['parentID']))
                    $liste[$i]['parentid']                  = $DIDL['container'][$i."_attr"]['parentID'];
                    if(isset($DIDL['container'][$i."_attr"]['restricted']))
                    $liste[$i]['restricted']                = $DIDL['container'][$i."_attr"]['restricted'];
    
                    $key = array_search_key($DIDL['container'][$i],"artist$");
                    if($key)
                    $liste[$i]['artist']                    = $DIDL['container'][$i][$key];
                    $key = array_search_key($DIDL['container'][$i],"album$");
                    if($key)
                    $liste[$i]['album']                     = $DIDL['container'][$i][$key];
                    $key = array_search_key($DIDL['container'][$i],"title$");
                    if($key)
                    $liste[$i]['title']                     = $DIDL['container'][$i][$key];
                }
            }
        }

        if(array_check($DIDL,'item'))
        {
            $keys = array_search_key($DIDL['item'],"[0-9]$",0);
            $count = (count($keys));
            $n = $i;
            
            if ($count==1){
                $i=0;
                $liste[$n+$i]['typ']                       = 'item';
                $liste[$n+$i]['metadata']                  = $MetaData;
    
                if(isset($DIDL['item_attr']['id']))
                $liste[$n+$i]['id']                        = $DIDL['item_attr']['id'];
                if(isset($DIDL['item_attr']['refID']))
                $liste[$n+$i]['refid']                     = $DIDL['item_attr']['refID'];
                if(isset($DIDL['item_attr']['parentID']))
                $liste[$n+$i]['parentid']                  = $DIDL['item_attr']['parentID'];
                if(isset($DIDL['item_attr']['restricted']))
                $liste[$n+$i]['restricted']                = $DIDL['item_attr']['restricted'];
    
                $key = array_search_key($DIDL['item'],"artist$");
                if($key){
                    if(array_check($DIDL['item'][$key],'0'))
                    $liste[$n+$i]['artist']                    = $DIDL['item'][$key]['0'];
                    else
                    $liste[$n+$i]['artist']                    = $DIDL['item'][$key];
                }
                    
                $key = array_search_key($DIDL['item'],"album$");
                if($key)
                $liste[$n+$i]['album']                     = $DIDL['item'][$key];
                $key = array_search_key($DIDL['item'],"title$");
                if($key)
                $liste[$n+$i]['title']                     = $DIDL['item'][$key];
    
    
	             if(array_check($DIDL['item']['res'],'0')){
                    //kann noch verbessert werden, da mehrere Recourcen zur Verfügung stehen
	             	$liste[$n+$i]['resource']                  = $DIDL['item']['res']['0'];
                	if(isset($DIDL['item']['res']['0_attr']['duration']))
                	$liste[$n+$i]['duration']                  = $DIDL['item']['res']['0_attr']['duration'];
                	if(isset($DIDL['item']['res']['0_attr']['size']))
                	$liste[$n+$i]['size']                      = $DIDL['item']['res']['0_attr']['size'];
                	if(isset($DIDL['item']['res']['0_attr']['bitrate']))
                	$liste[$n+$i]['bitrate']                   = $DIDL['item']['res']['0_attr']['bitrate'];
			     }
				 else {
    	             	if(array_check($DIDL['item'],'res')){
             	          $liste[$n+$i]['resource']                  = $DIDL['item']['res'];
    	               	  if(isset($DIDL['item']['res_attr']['duration']))
    	               	  $liste[$n+$i]['duration']                  = $DIDL['item']['res_attr']['duration'];
    	               	  if(isset($DIDL['item']['res_attr']['size']))
    	               	  $liste[$n+$i]['size']                      = $DIDL['item']['res_attr']['size'];
    	               	  if(isset($DIDL['item']['res_attr']['bitrate']))
    	               	  $liste[$n+$i]['bitrate']                   = $DIDL['item']['res_attr']['bitrate'];
    				      }
				 }
                
                
                $key = array_search_key($DIDL['item'],"albumArtURI$");
                if($key)
                $liste[$n+$i]['albumArtURI']               = $DIDL['item'][$key];
    
                $key = array_search_key($DIDL['item'],"genre$");
                if($key)
                $liste[$n+$i]['genre']                     = $DIDL['item'][$key];
    
                $key = array_search_key($DIDL['item'],"date$");
                if($key)
                $liste[$n+$i]['date']                      = $DIDL['item'][$key];
    
                $key = array_search_key($DIDL['item'],"originalTrackNumber$");
                if($key)
                $liste[$n+$i]['originalTrackNumber']       = $DIDL['item'][$key];
    
                $key = array_search_key($DIDL['item'],"class$");
                if($key)
                $liste[$n+$i]['class']                     = $DIDL['item'][$key];
                
            }
            else
            {
                for ($i=0; $i < $count; $i++)
                {
                    $liste[$n+$i]['typ']                       = 'item';
                    $liste[$n+$i]['metadata']                  = $MetaData;
    
                    if(isset($DIDL['item'][$i.'_attr']['id']))
                    $liste[$n+$i]['id']                        = $DIDL['item'][$i.'_attr']['id'];
                    if(isset($DIDL['item'][$i.'_attr']['refID']))
                    $liste[$n+$i]['refid']                     = $DIDL['item'][$i.'_attr']['refID'];
                    if(isset($DIDL['item'][$i.'_attr']['parentID']))
                    $liste[$n+$i]['parentid']                  = $DIDL['item'][$i.'_attr']['parentID'];
                    if(isset($DIDL['item'][$i.'_attr']['restricted']))
                    $liste[$n+$i]['restricted']                = $DIDL['item'][$i.'_attr']['restricted'];
    
                    $key = array_search_key($DIDL['item'][$i],"artist$");
                        if($key){
                        if(array_check($DIDL['item'][$i][$key],'0'))
                        $liste[$n+$i]['artist']                    = $DIDL['item'][$i][$key]['0'];
                        else
                        $liste[$n+$i]['artist']                    = $DIDL['item'][$i][$key];
                    }
                    $key = array_search_key($DIDL['item'][$i],"album$");
                    if($key)
                    $liste[$n+$i]['album']                     = $DIDL['item'][$i][$key];
                    $key = array_search_key($DIDL['item'][$i],"title$");
                    if($key)
                    $liste[$n+$i]['title']                     = $DIDL['item'][$i][$key];
    
    	             if(array_check($DIDL['item'][$i]['res'],'0')){
                        //kann noch verbessert werden, da mehrere Recourcen zur Verfügung stehen
    	             	$liste[$n+$i]['resource']                  = $DIDL['item'][$i]['res']['0'];
                    	if(isset($DIDL['item'][$i]['res']['0_attr']['duration']))
                    	$liste[$n+$i]['duration']                  = $DIDL['item'][$i]['res']['0_attr']['duration'];
                    	if(isset($DIDL['item'][$i]['res']['0_attr']['size']))
                    	$liste[$n+$i]['size']                      = $DIDL['item'][$i]['res']['0_attr']['size'];
                    	if(isset($DIDL['item'][$i]['res']['0_attr']['bitrate']))
                    	$liste[$n+$i]['bitrate']                   = $DIDL['item'][$i]['res']['0_attr']['bitrate'];
    			     }
    				 else {
        	             	if(array_check($DIDL['item'][$i],'res')){
                 	          $liste[$n+$i]['resource']                  = $DIDL['item'][$i]['res'];
        	               	  if(isset($DIDL['item'][$i]['res_attr']['duration']))
        	               	  $liste[$n+$i]['duration']                  = $DIDL['item'][$i]['res_attr']['duration'];
        	               	  if(isset($DIDL['item'][$i]['res_attr']['size']))
        	               	  $liste[$n+$i]['size']                      = $DIDL['item'][$i]['res_attr']['size'];
        	               	  if(isset($DIDL['item'][$i]['res_attr']['bitrate']))
        	               	  $liste[$n+$i]['bitrate']                   = $DIDL['item'][$i]['res_attr']['bitrate'];
        				      }
    				 }
    
                    $key = array_search_key($DIDL['item'][$i],"albumArtURI$");
                    if($key)
                    $liste[$n+$i]['albumArtURI']               = $DIDL['item'][$i][$key];
    
                    $key = array_search_key($DIDL['item'][$i],"genre$");
                    if($key)
                    $liste[$n+$i]['genre']                     = $DIDL['item'][$i][$key];
    
                    $key = array_search_key($DIDL['item'][$i],"date$");
                    if($key)
                    $liste[$n+$i]['date']                      = $DIDL['item'][$i][$key];
    
                    $key = array_search_key($DIDL['item'][$i],"originalTrackNumber$");
                    if($key)
                    $liste[$n+$i]['originalTrackNumber']       = $DIDL['item'][$i][$key];
    
                    $key = array_search_key($DIDL['item'][$i],"class$");
                    if($key)
                    $liste[$n+$i]['class']                     = $DIDL['item'][$i][$key];
                }
                
            }
        }
         return ($liste);
}

?>



Hallo mnb,

$MetaData ist streng genommen die gesamte DIDL-Lite eines Titels. D.h. z.B.

<DIDL-Lite xmlns="urn:schemas-upnp-org:metadata-1-0/DIDL-Lite/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:upnp="urn:schemas-upnp-org:metadata-1-0/upnp/" xmlns:dlna="urn:schemas-dlna-org:metadata-1-0/"><item id="0$1$13$1057$1058$16434R4219914" refID="0$1$8I4219914" parentID="0$1$13$1057$1058$16434" upnp:restricted="1"><dc:title>Waves (Robin Schulz Edit)</dc:title><dc:date>2014-03-16</dc:date><upnp:genre>Hip-Hop</upnp:genre><upnp:album>Waves</upnp:album><dc:creator>Mr. Probz</dc:creator><upnp:albumArtURI dlna:profileID="JPEG_TN">http://192.168.178.10:9000/disk/DLNA-PNJPEG_TN-OP01-CI1-FLAGS00d00000/defaultalbumart/a_u_d_i_o.jpg/O0$1$8I4219914.jpg?scale=160x160</upnp:albumArtURI><upnp:artist>Mr. Probz</upnp:artist><pv:extension>mp3</pv:extension><upnp:albumArtist>Trivium</upnp:albumArtist><pv:modificationTime>1404039004</pv:modificationTime><pv:addedTime>1404047327</pv:addedTime><pv:lastUpdated>1404039004</pv:lastUpdated><pv:album_crosslink>0$1$12$16625</pv:album_crosslink><pv:artist_crosslink>0$1$11$16612</pv:artist_crosslink><pv:genre_crosslink>0$1$10$1312</pv:genre_crosslink><upnp:author role="Composer">Trivium</upnp:author><upnp:artist role="Composer">Trivium</upnp:artist><pv:bookmark>uuid:55076f6e-6b79-4d65-64eb-00089bdc05d9,-L3NoYXJlL011bHRpbWVkaWEvQXVkaW8vTVAzL05ldS9Nci4gUHJvYnogLSBXYXZlcyAoUm9iaW4gU2NodWx6IEVkaXQpLm1wMw==</pv:bookmark><upnp:res duration="0:03:00" size="2943205" bitrate="128" protocolInfo="http-get:*:audio/mpeg:DLNA.ORG_PN=MP3;DLNA.ORG_OP=01;DLNA.ORG_FLAGS=01700000000000000000000000000000">http://192.168.178.10:9000/disk/DLNA-PNMP3-OP01-FLAGS01700000/O0$1$8I4219914.mp3</upnp:res><upnp:class>object.item.audioItem.musicTrack</upnp:class></item></DIDL-Lite>

Diese muß bei manchen Devices auch für den Titel übergeben werden (z.B. mein LG-TV will es sonst nicht). Die Sony Netzwerklautsprecher sind da ganz anspruchslos.
Das steckt z.B. in /Multimedia/Core/UPNP_Play_Server und /Multimedia/Core/UPNP_Play_direct_Server.

//Play--------------------------------------------------------------------------

$file = $res;

SetAVTransportURI($ControlURL, $DeviceIP, $DevicePort, $file, $metadata);
Play_AV($ControlURL, $DeviceIP, $DevicePort);

Ich habe angefangen ein paar Fehler abzufangen, den SSDP-Request (das Suchen nach Servern und Devices) zu verbessern und auch mehr als 8 Server bzw. Devices anzuzeigen.

Raketenschnecke hat mir freundlicherweise eine neue Version des Project-Exporters zukommen lassen (Danke nochmal :smiley: ) - Also hier mal die aktuelle Build:

Multimedia 2014-07-27.zip (673 KB)

Viele Grüße

André

Hallo mnb,

der Universal Media Server ließ mich nicht in Ruhe und so habe ich mal mit dem Multicastsocket herumgespielt, den ich ursprünglich im Einsatz hatte, jedoch wegen fehlender Portierbarkeit verließ.
Genaugenommen ist das ein Multicastsocket (239.255.255.250) mit angehangener Registervariable und Auswertescript. Dieser findet den Universal Media Server. Ergo muss in der function mSearch($ST), welche in UPNP_Discovery_Functions.ips.php steckt, noch ein Bug sein.

Response:

HTTP/1.1 200 OK
CACHE-CONTROL: max-age=1200
DATE: Thu, 31 Jul 2014 18:04:26 GMT
LOCATION: http://192.168.178.64:5002/description/fetch
SERVER: Windows_8-amd64-6.2, UPnP/1.0, UMS/3.6.4
ST: urn:schemas-upnp-org:device:MediaServer:1
EXT: 
USN: uuid:389d60c3-75ef-44a2-aa11-b237a570bd6b::urn:schemas-upnp-org:device:MediaServer:1
Content-Length: 0

Den Port hatte ich zur Wiedererkennung auf 5002 geändert.

Alternativ versuche ich den alten Socket in der neuen Struktur mal gangbar zu machen und beschreibe bei Erfolg die Erstellung.

Viele Grüße

André

Moin DigiHouse,

ich werde sobald wie möglich den Abschnitt für die Metadaten posten.
Wird nur etwas dauern bis ich wieder Zeit dafür habe.

Und ich habe dazu noch eine Frage die crosslink Werte: Wo kommen die her/ wie stellen sich die zusammen?
Oder sind die einfach nicht immer vorhanden?
Edit:


<pv:album_crosslink>0$1$12$16625</pv:album_crosslink>
<pv:artist_crosslink>0$1$11$16612</pv:artist_crosslink>
<pv:genre_crosslink>0$1$10$1312</pv:genre_crosslink>

Wegen dem UMS hatte ich mich auch schon gewundert, da er in deiner alten Version gefunden wurde.

MFG MNB

Hi mnb,

Was meinst Du mit Crosslink-Werte?

VG André

Hallo Andrè,

habe auch mal versucht es zu installieren, aber beim ausführen von

  1. UPNP_Initialize ausführen (versteckt in Config) und ggf. Devices/Server nochmal im WF aktualisieren. Die Devices und Server sollten automatisch erkannt werden!!! Das war ursprünglich ein casus knacktus, da ich alles händisch konfigurieren musste

erhalte ich diese Fehlermeldung:

Fatal error:  Call to undefined function socket_create() in [Multimedia\Core\UPNP_Discovery_Functions.ips.php] on line 42
Abort Processing during Fatal-Error: Call to undefined function socket_create()
   Error in Script C:\IP-Symcon_2_0\scripts\UPNP_Discovery_Functions.ips.php on Line 42


Hast Du da eine Idee ?

@hbraun

gehe mal bitte nur wie in Post 37 beschrieben vor. Das Initialisierungsscript ist offenbar noch übersehener Datenmüll.

Viele Grüße André

Habe ich gemacht, jetzt hört es aber nicht auf zu suchen :frowning:

Das Script UPNP_SSDP_Request wird als Fehlerhaft makiert.

wenn ich es von Hand starte erhalte ich folgende Fehlermeldung:

Fatal error:  Call to undefined function socket_create() in [Multimedia\Core\UPNP_Discovery_Functions.ips.php] on line 42
Abort Processing during Fatal-Error: Call to undefined function socket_create()
   Error in Script C:\IP-Symcon_2_0\scripts\UPNP_Discovery_Functions.ips.php on Line 42

Die angemeckerte Zeile ist diese:

$sock = socket_create( AF_INET, SOCK_DGRAM, getprotobyname('udp') );

Ok. Habe ich noch nicht gehabt, da Php eigentlich Socket_create kennen sollte. Sehe ich mir mal genauer an.
VG André

Hallo hbraun

Habe nochmal nachgedacht und würde darauf tippen, das bei Dir die Socket Extensions von Php abgeschaltet sind (vgl. Googl#).
Gruß André

Ich habe gerade gesehen das im ext Verzeichnis gar keine php_sockets.dll drin ist.
Wo bekomme ich die passende her?

Hmmm. Kann es sein, dass mal ein IPS Update schieflief? Bei mir ist das bei PHP alles onboard. Aber Achtung: bevor Du jetzt ein Update machst solltest Du eine Sicherheitskopie Deines jetzigen IPS machen um zurückwechseln zu können.
Gruß André

Gesendet von meinem C6833 mit Tapatalk

Update hat geklappt. Haben jetzt aber Besuch bekommen, muss dann morgen weiter testen.

Hallo Andrè,
scheint zu klappen. Habe aber noch ein paar Fragen :smiley:

Da meine möglichen Devices in einem anderen Netzwerk hängen werden die nicht angezeigt, kann man das irgendwie lösen? Die beiden Netzwerkkarten sind im gleichen Rechner nur unterschiedlicher IP-Kreise (192.168.1.* und 192.168.2.*?.

Welche Geräte kannst Du ansonsten für die Wiedergabe empfehlen?

SSPD kann ich nicht speichern kommt eine Fehlermeldung. Wofür muss man das speichern?

Wie kann ich bei dem Subsonic Server das/ ein Bildchen bekommen?

server.jpg

Beim Subsonic werden mir nur die Videos angezeigt, bei den Musik-Ordnern bleibt es bei der Suche.