Ejemplo n.º 1
0
        protected override void BuildInternal(object directoryPropertyObject)
        {
            if (!_hasCompleted)
            {
                if (directoryPropertyObject is IDirectoryContainer)
                {
                    _xml.WriteStartElement("container");
                }
                else if (directoryPropertyObject is IDirectoryItem)
                {
                    _xml.WriteStartElement("item");
                }
                else
                {
                    throw new ArgumentException("directoryPropertyObject isn't either an IDirectoryContainer or IDirectoryItem");
                }

                if (directoryPropertyObject is MediaLibraryVideoItem)
                {
                    try
                    {
                        MediaLibraryVideoItem res      = (MediaLibraryVideoItem)directoryPropertyObject;
                        IDirectoryResource    subRes   = null;
                        IDirectoryResource    movieRes = null;
                        foreach (var embeddedRes in res.Resources)
                        {
                            if (embeddedRes is MediaLibrarySubtitleResource)
                            {
                                subRes = embeddedRes;
                            }
                            else if (embeddedRes is MediaLibraryResource)
                            {
                                movieRes = embeddedRes;
                            }
                        }
                        if (subRes != null && movieRes != null)
                        {
                            movieRes.PacketVideoSubtitleType = "SRT";
                            movieRes.PacketVideoSubtitleUri  = subRes.Uri;
                        }
                    }
                    catch (Exception ex)
                    {
                        Logger.Warn("DlnaMediaServer: Cannot resolve resource elements for injection of subtitles information:\n {0}", ex.Message);
                    }
                }

                ObjectRenderer.Render(_filter, directoryPropertyObject, _xml);
                _xml.WriteEndElement();
            }
        }
        protected override void BuildInternal(object directoryPropertyObject)
        {
            if (!_hasCompleted)
            {
                if (directoryPropertyObject is IDirectoryContainer)
                {
                    _xml.WriteStartElement("container");
                }
                else if (directoryPropertyObject is IDirectoryItem)
                {
                    _xml.WriteStartElement("item");
                }
                else
                {
                    throw new ArgumentException("directoryPropertyObject isn't either an IDirectoryContainer or IDirectoryItem");
                }
                ObjectRenderer.Render(_filter, directoryPropertyObject, _xml);
                if (directoryPropertyObject is BasicContainer)
                {
                    if ((directoryPropertyObject as BasicContainer).Id == "A") //Audio
                    {
                        _xml.WriteStartElement("av:mediaClass");
                        _xml.WriteValue("M");
                        _xml.WriteEndElement();
                    }
                    else if ((directoryPropertyObject as BasicContainer).Id == "I") //Image
                    {
                        _xml.WriteStartElement("av:mediaClass");
                        _xml.WriteValue("P");
                        _xml.WriteEndElement();
                    }
                    else if ((directoryPropertyObject as BasicContainer).Id == "V") //Video
                    {
                        _xml.WriteStartElement("av:mediaClass");
                        _xml.WriteValue("V");
                        _xml.WriteEndElement();
                    }
                }

                _xml.WriteEndElement();
            }
        }
Ejemplo n.º 3
0
 protected void BuildInternal(object directoryPropertyObject)
 {
     if (!_hasCompleted)
     {
         if (directoryPropertyObject is IDirectoryContainer)
         {
             _xml.WriteStartElement("container");
         }
         else if (directoryPropertyObject is IDirectoryItem)
         {
             _xml.WriteStartElement("item");
         }
         else
         {
             throw new ArgumentException(
                       "directoryPropertyObject isn't either an IDirectoryContainer or IDirectoryItem");
         }
         ObjectRenderer.Render(_filter, directoryPropertyObject, _xml);
         _xml.WriteEndElement();
     }
 }
Ejemplo n.º 4
0
        protected override void BuildInternal(object directoryPropertyObject)
        {
            if (!_hasCompleted)
            {
                if (directoryPropertyObject is IDirectoryContainer)
                {
                    _xml.WriteStartElement("container");
                }
                else if (directoryPropertyObject is IDirectoryItem)
                {
                    _xml.WriteStartElement("item");
                }
                else
                {
                    throw new ArgumentException(
                              "directoryPropertyObject isn't either an IDirectoryContainer or IDirectoryItem");
                }

                ObjectRenderer.Render(_filter, directoryPropertyObject, _xml);

                if (directoryPropertyObject is MediaLibraryVideoItem)
                {
                    try
                    {
                        MediaLibraryVideoItem res = (MediaLibraryVideoItem)directoryPropertyObject;
                        foreach (var embeddedRes in res.Resources)
                        {
                            if (embeddedRes is MediaLibrarySubtitleResource)
                            {
                                _xml.WriteStartElement("sec", "CaptionInfoEx", null);
                                _xml.WriteAttributeString("sec", "type", null, ((MediaLibrarySubtitleResource)embeddedRes).SubtitleType);
                                _xml.WriteValue(embeddedRes.Uri);
                                _xml.WriteEndElement();
                                break;
                            }
                        }

                        var  dlnaItem         = res.Client.GetDlnaItem(res.MediaItemId);
                        long creationDateSecs = 0;
                        if (dlnaItem?.MediaItemAddedDate != null)
                        {
                            creationDateSecs = Convert.ToInt64((dlnaItem.MediaItemAddedDate.Value - new DateTime(1970, 1, 1)).TotalSeconds);
                        }
                        string dcm = "CREATIONDATE=" + creationDateSecs;
                        if (dlnaItem?.MediaItemWidth != null)
                        {
                            dcm += ",WIDTH=" + Convert.ToString(dlnaItem.MediaItemWidth.Value);
                        }
                        if (dlnaItem?.MediaItemHeight != null)
                        {
                            dcm += ",HEIGHT=" + Convert.ToString(dlnaItem.MediaItemHeight.Value);
                        }
                        if (dlnaItem?.MediaItemRecordingDate != null)
                        {
                            dcm += ",YEAR=" + dlnaItem.MediaItemRecordingDate.Value.Year;
                        }

                        //TODO: Support resumed playback of videos?
                        //dcm += string.Format(",BM={0}", numberOfSecondsToResumeFrom)

                        _xml.WriteStartElement("sec", "dcmInfo", null);
                        _xml.WriteValue(dcm);
                        _xml.WriteEndElement();
                    }
                    catch (Exception ex)
                    {
                        Logger.Warn("DlnaMediaServer: Cannot resolve resource elements for injection of information:\n {0}", ex.Message);
                    }
                }
                else if (directoryPropertyObject is MediaLibraryImageItem)
                {
                    try
                    {
                        MediaLibraryImageItem res = (MediaLibraryImageItem)directoryPropertyObject;
                        var dlnaItem = res.Client.GetDlnaItem(res.MediaItemId);
                        if (dlnaItem?.MediaItemImageMake != null)
                        {
                            _xml.WriteStartElement("sec", "manufacturer", null);
                            _xml.WriteValue(dlnaItem.MediaItemImageMake);
                            _xml.WriteEndElement();
                        }
                        if (dlnaItem?.MediaItemImageModel != null)
                        {
                            _xml.WriteStartElement("sec", "model", null);
                            _xml.WriteValue(dlnaItem.MediaItemImageModel);
                            _xml.WriteEndElement();
                        }
                        if (dlnaItem?.MediaItemImageFNumber != null)
                        {
                            _xml.WriteStartElement("sec", "fvalue", null);
                            _xml.WriteValue(dlnaItem.MediaItemImageFNumber);
                            _xml.WriteEndElement();
                        }
                        if (dlnaItem?.MediaItemImageIsoSpeed != null)
                        {
                            _xml.WriteStartElement("sec", "iso", null);
                            _xml.WriteValue(dlnaItem.MediaItemImageIsoSpeed);
                            _xml.WriteEndElement();
                        }
                        if (dlnaItem?.MediaItemImageExposureTime != null)
                        {
                            _xml.WriteStartElement("sec", "exposureTime", null);
                            _xml.WriteValue(dlnaItem.MediaItemImageExposureTime);
                            _xml.WriteEndElement();
                        }

                        long creationDateSecs = 0;
                        if (dlnaItem?.MediaItemAddedDate != null)
                        {
                            creationDateSecs = Convert.ToInt64((dlnaItem.MediaItemAddedDate.Value - new DateTime(1970, 1, 1)).TotalSeconds);
                        }
                        string dcm = "CREATIONDATE=" + creationDateSecs;
                        if (dlnaItem?.MediaItemWidth != null)
                        {
                            dcm += ",WIDTH=" + Convert.ToString(dlnaItem.MediaItemWidth.Value);
                        }
                        if (dlnaItem?.MediaItemHeight != null)
                        {
                            dcm += ",HEIGHT=" + Convert.ToString(dlnaItem.MediaItemHeight.Value);
                        }
                        if (dlnaItem?.MediaItemImageOrientation != null)
                        {
                            dcm += ",ORT=" + Convert.ToString(dlnaItem.MediaItemImageOrientation.Value);
                        }
                        if (dlnaItem?.MediaItemRecordingDate != null)
                        {
                            dcm += ",YEAR=" + dlnaItem.MediaItemRecordingDate.Value.Year;
                        }

                        _xml.WriteStartElement("sec", "dcmInfo", null);
                        _xml.WriteValue(dcm);
                        _xml.WriteEndElement();
                    }
                    catch (Exception ex)
                    {
                        Logger.Warn("DlnaMediaServer: Cannot resolve resource elements for injection of information:\n {0}", ex.Message);
                    }
                }
                _xml.WriteEndElement();
            }
        }
Ejemplo n.º 5
0
        public static void Render(PropertyFilter filter, object obj, XmlWriter xml)
        {
            var or = new ObjectRenderer(obj);

            or.Render(filter, xml);
        }