Пример #1
0
        private void AddGeneralProperties(BaseItem item, XmlElement element, Filter filter)
        {
            AddCommonFields(item, element, filter);

            var audio = item as Audio;

            if (audio != null)
            {
                foreach (var artist in audio.Artists)
                {
                    AddValue(element, "upnp", "artist", artist, NS_UPNP);
                }

                if (!string.IsNullOrEmpty(audio.Album))
                {
                    AddValue(element, "upnp", "album", audio.Album, NS_UPNP);
                }

                foreach (var artist in audio.AlbumArtists)
                {
                    AddAlbumArtist(element, artist);
                }
            }

            var album = item as MusicAlbum;

            if (album != null)
            {
                foreach (var artist in album.AlbumArtists)
                {
                    AddAlbumArtist(element, artist);
                    AddValue(element, "upnp", "artist", artist, NS_UPNP);
                }
                foreach (var artist in album.Artists)
                {
                    AddValue(element, "upnp", "artist", artist, NS_UPNP);
                }
            }

            var musicVideo = item as MusicVideo;

            if (musicVideo != null)
            {
                if (!string.IsNullOrEmpty(musicVideo.Artist))
                {
                    AddValue(element, "upnp", "artist", musicVideo.Artist, NS_UPNP);
                    AddAlbumArtist(element, musicVideo.Artist);
                }

                if (!string.IsNullOrEmpty(musicVideo.Album))
                {
                    AddValue(element, "upnp", "album", musicVideo.Album, NS_UPNP);
                }
            }

            if (item.IndexNumber.HasValue)
            {
                AddValue(element, "upnp", "originalTrackNumber", item.IndexNumber.Value.ToString(_usCulture), NS_UPNP);

                if (item is Episode)
                {
                    AddValue(element, "upnp", "episodeNumber", item.IndexNumber.Value.ToString(_usCulture), NS_UPNP);
                }
            }
        }
Пример #2
0
        public XmlElement GetItemElement(XmlDocument doc, BaseItem item, string deviceId, Filter filter, StreamInfo streamInfo = null)
        {
            var element = doc.CreateElement(string.Empty, "item", NS_DIDL);

            element.SetAttribute("restricted", "1");
            element.SetAttribute("id", item.Id.ToString("N"));

            if (item.Parent != null)
            {
                element.SetAttribute("parentID", item.Parent.Id.ToString("N"));
            }

            //AddBookmarkInfo(item, user, element);

            AddGeneralProperties(item, element, filter);

            // refID?
            // storeAttribute(itemNode, object, ClassProperties.REF_ID, false);

            var hasMediaSources = item as IHasMediaSources;

            if (hasMediaSources != null)
            {
                if (string.Equals(item.MediaType, MediaType.Audio, StringComparison.OrdinalIgnoreCase))
                {
                    AddAudioResource(element, hasMediaSources, deviceId, filter, streamInfo);
                }
                else if (string.Equals(item.MediaType, MediaType.Video, StringComparison.OrdinalIgnoreCase))
                {
                    AddVideoResource(element, hasMediaSources, deviceId, filter, streamInfo);
                }
            }

            AddCover(item, element);

            return(element);
        }
Пример #3
0
        //private void AddBookmarkInfo(BaseItem item, User user, XmlElement element)
        //{
        //    var userdata = _userDataManager.GetUserData(user.Id, item.GetUserDataKey());

        //    if (userdata.PlaybackPositionTicks > 0)
        //    {
        //        var dcmInfo = element.OwnerDocument.CreateElement("sec", "dcmInfo", NS_SEC);
        //        dcmInfo.InnerText = string.Format("BM={0}", Convert.ToInt32(TimeSpan.FromTicks(userdata.PlaybackPositionTicks).TotalSeconds).ToString(_usCulture));
        //        element.AppendChild(dcmInfo);
        //    }
        //}

        /// <summary>
        /// Adds fields used by both items and folders
        /// </summary>
        /// <param name="item">The item.</param>
        /// <param name="element">The element.</param>
        /// <param name="filter">The filter.</param>
        private void AddCommonFields(BaseItem item, XmlElement element, Filter filter)
        {
            // Don't filter on dc:title because not all devices will include it in the filter
            // MediaMonkey for example won't display content without a title
            //if (filter.Contains("dc:title"))
            {
                AddValue(element, "dc", "title", item.Name, NS_DC);
            }

            element.AppendChild(CreateObjectClass(element.OwnerDocument, item));

            if (filter.Contains("dc:date"))
            {
                if (item.PremiereDate.HasValue)
                {
                    AddValue(element, "dc", "date", item.PremiereDate.Value.ToString("o"), NS_DC);
                }
            }

            if (filter.Contains("upnp:genre"))
            {
                foreach (var genre in item.Genres)
                {
                    AddValue(element, "upnp", "genre", genre, NS_UPNP);
                }
            }

            foreach (var studio in item.Studios)
            {
                AddValue(element, "upnp", "publisher", studio, NS_UPNP);
            }

            if (filter.Contains("dc:description"))
            {
                var desc = item.Overview;

                var hasShortOverview = item as IHasShortOverview;
                if (hasShortOverview != null && !string.IsNullOrEmpty(hasShortOverview.ShortOverview))
                {
                    desc = hasShortOverview.ShortOverview;
                }

                if (!string.IsNullOrWhiteSpace(desc))
                {
                    AddValue(element, "dc", "description", desc, NS_DC);
                }
            }
            if (filter.Contains("upnp:longDescription"))
            {
                if (!string.IsNullOrWhiteSpace(item.Overview))
                {
                    AddValue(element, "upnp", "longDescription", item.Overview, NS_UPNP);
                }
            }

            if (!string.IsNullOrEmpty(item.OfficialRating))
            {
                if (filter.Contains("dc:rating"))
                {
                    AddValue(element, "dc", "rating", item.OfficialRating, NS_DC);
                }
                if (filter.Contains("upnp:rating"))
                {
                    AddValue(element, "upnp", "rating", item.OfficialRating, NS_UPNP);
                }
            }

            AddPeople(item, element);
        }
Пример #4
0
        public XmlElement GetFolderElement(XmlDocument doc, Folder folder, int childCount, Filter filter, string requestedId = null)
        {
            var container = doc.CreateElement(string.Empty, "container", NS_DIDL);

            container.SetAttribute("restricted", "0");
            container.SetAttribute("searchable", "1");
            container.SetAttribute("childCount", childCount.ToString(_usCulture));

            if (string.Equals(requestedId, "0"))
            {
                container.SetAttribute("id", "0");
                container.SetAttribute("parentID", "-1");
            }
            else
            {
                container.SetAttribute("id", folder.Id.ToString("N"));

                var parent = folder.Parent;
                if (parent == null)
                {
                    container.SetAttribute("parentID", "0");
                }
                else
                {
                    container.SetAttribute("parentID", parent.Id.ToString("N"));
                }
            }

            AddCommonFields(folder, container, filter);

            AddCover(folder, container);

            return(container);
        }
Пример #5
0
        private void AddAudioResource(XmlElement container, IHasMediaSources audio, string deviceId, Filter filter, StreamInfo streamInfo = null)
        {
            var res = container.OwnerDocument.CreateElement(string.Empty, "res", NS_DIDL);

            if (streamInfo == null)
            {
                var sources = _user == null?audio.GetMediaSources(true).ToList() : audio.GetMediaSources(true, _user).ToList();

                streamInfo = new StreamBuilder().BuildAudioItem(new AudioOptions
                {
                    ItemId       = audio.Id.ToString("N"),
                    MediaSources = sources,
                    Profile      = _profile,
                    DeviceId     = deviceId
                });
            }

            var url = streamInfo.ToDlnaUrl(_serverAddress);

            res.InnerText = url;

            var mediaSource = streamInfo.MediaSource;

            if (mediaSource.RunTimeTicks.HasValue)
            {
                res.SetAttribute("duration", TimeSpan.FromTicks(mediaSource.RunTimeTicks.Value).ToString("c", _usCulture));
            }

            if (filter.Contains("res@size"))
            {
                if (streamInfo.IsDirectStream || streamInfo.EstimateContentLength)
                {
                    var size = streamInfo.TargetSize;

                    if (size.HasValue)
                    {
                        res.SetAttribute("size", size.Value.ToString(_usCulture));
                    }
                }
            }

            var targetAudioBitrate = streamInfo.TargetAudioBitrate;
            var targetSampleRate   = streamInfo.TargetAudioSampleRate;
            var targetChannels     = streamInfo.TargetAudioChannels;

            if (targetChannels.HasValue)
            {
                res.SetAttribute("nrAudioChannels", targetChannels.Value.ToString(_usCulture));
            }

            if (targetSampleRate.HasValue)
            {
                res.SetAttribute("sampleFrequency", targetSampleRate.Value.ToString(_usCulture));
            }

            if (targetAudioBitrate.HasValue)
            {
                res.SetAttribute("bitrate", targetAudioBitrate.Value.ToString(_usCulture));
            }

            var mediaProfile = _profile.GetAudioMediaProfile(streamInfo.Container,
                                                             streamInfo.AudioCodec,
                                                             targetChannels,
                                                             targetAudioBitrate);

            var filename = url.Substring(0, url.IndexOf('?'));

            var mimeType = mediaProfile == null || string.IsNullOrEmpty(mediaProfile.MimeType)
                ? MimeTypes.GetMimeType(filename)
                : mediaProfile.MimeType;

            var contentFeatures = new ContentFeatureBuilder(_profile).BuildAudioHeader(streamInfo.Container,
                                                                                       streamInfo.TargetAudioCodec,
                                                                                       targetAudioBitrate,
                                                                                       targetSampleRate,
                                                                                       targetChannels,
                                                                                       streamInfo.IsDirectStream,
                                                                                       streamInfo.RunTimeTicks,
                                                                                       streamInfo.TranscodeSeekInfo);

            res.SetAttribute("protocolInfo", String.Format(
                                 "http-get:*:{0}:{1}",
                                 mimeType,
                                 contentFeatures
                                 ));

            container.AppendChild(res);
        }
Пример #6
0
        private void AddVideoResource(XmlElement container, IHasMediaSources video, string deviceId, Filter filter, string contentFeatures, StreamInfo streamInfo)
        {
            var res = container.OwnerDocument.CreateElement(string.Empty, "res", NS_DIDL);

            var url = streamInfo.ToDlnaUrl(_serverAddress);

            res.InnerText = url;

            var mediaSource = streamInfo.MediaSource;

            if (mediaSource.RunTimeTicks.HasValue)
            {
                res.SetAttribute("duration", TimeSpan.FromTicks(mediaSource.RunTimeTicks.Value).ToString("c", _usCulture));
            }

            if (filter.Contains("res@size"))
            {
                if (streamInfo.IsDirectStream || streamInfo.EstimateContentLength)
                {
                    var size = streamInfo.TargetSize;

                    if (size.HasValue)
                    {
                        res.SetAttribute("size", size.Value.ToString(_usCulture));
                    }
                }
            }

            var totalBitrate     = streamInfo.TargetTotalBitrate;
            var targetSampleRate = streamInfo.TargetAudioSampleRate;
            var targetChannels   = streamInfo.TargetAudioChannels;

            var targetWidth  = streamInfo.TargetWidth;
            var targetHeight = streamInfo.TargetHeight;

            if (targetChannels.HasValue)
            {
                res.SetAttribute("nrAudioChannels", targetChannels.Value.ToString(_usCulture));
            }

            if (filter.Contains("res@resolution"))
            {
                if (targetWidth.HasValue && targetHeight.HasValue)
                {
                    res.SetAttribute("resolution", string.Format("{0}x{1}", targetWidth.Value, targetHeight.Value));
                }
            }

            if (targetSampleRate.HasValue)
            {
                res.SetAttribute("sampleFrequency", targetSampleRate.Value.ToString(_usCulture));
            }

            if (totalBitrate.HasValue)
            {
                res.SetAttribute("bitrate", totalBitrate.Value.ToString(_usCulture));
            }

            var mediaProfile = _profile.GetVideoMediaProfile(streamInfo.Container,
                                                             streamInfo.AudioCodec,
                                                             streamInfo.VideoCodec,
                                                             streamInfo.TargetAudioBitrate,
                                                             targetChannels,
                                                             targetWidth,
                                                             targetHeight,
                                                             streamInfo.TargetVideoBitDepth,
                                                             streamInfo.TargetVideoBitrate,
                                                             streamInfo.TargetVideoProfile,
                                                             streamInfo.TargetVideoLevel,
                                                             streamInfo.TargetFramerate,
                                                             streamInfo.TargetPacketLength,
                                                             streamInfo.TargetTimestamp,
                                                             streamInfo.IsTargetAnamorphic,
                                                             streamInfo.TargetRefFrames);

            var filename = url.Substring(0, url.IndexOf('?'));

            var mimeType = mediaProfile == null || string.IsNullOrEmpty(mediaProfile.MimeType)
               ? MimeTypes.GetMimeType(filename)
               : mediaProfile.MimeType;

            res.SetAttribute("protocolInfo", String.Format(
                                 "http-get:*:{0}:{1}",
                                 mimeType,
                                 contentFeatures
                                 ));

            container.AppendChild(res);
        }
Пример #7
0
        private void AddVideoResource(XmlElement container, IHasMediaSources video, string deviceId, Filter filter, StreamInfo streamInfo = null)
        {
            if (streamInfo == null)
            {
                var sources = _user == null?video.GetMediaSources(true).ToList() : video.GetMediaSources(true, _user).ToList();

                streamInfo = new StreamBuilder().BuildVideoItem(new VideoOptions
                {
                    ItemId       = video.Id.ToString("N"),
                    MediaSources = sources,
                    Profile      = _profile,
                    DeviceId     = deviceId,
                    MaxBitrate   = _profile.MaxStreamingBitrate
                });
            }

            var targetWidth  = streamInfo.TargetWidth;
            var targetHeight = streamInfo.TargetHeight;

            var contentFeatureList = new ContentFeatureBuilder(_profile).BuildVideoHeader(streamInfo.Container,
                                                                                          streamInfo.VideoCodec,
                                                                                          streamInfo.AudioCodec,
                                                                                          targetWidth,
                                                                                          targetHeight,
                                                                                          streamInfo.TargetVideoBitDepth,
                                                                                          streamInfo.TargetVideoBitrate,
                                                                                          streamInfo.TargetAudioChannels,
                                                                                          streamInfo.TargetAudioBitrate,
                                                                                          streamInfo.TargetTimestamp,
                                                                                          streamInfo.IsDirectStream,
                                                                                          streamInfo.RunTimeTicks,
                                                                                          streamInfo.TargetVideoProfile,
                                                                                          streamInfo.TargetVideoLevel,
                                                                                          streamInfo.TargetFramerate,
                                                                                          streamInfo.TargetPacketLength,
                                                                                          streamInfo.TranscodeSeekInfo,
                                                                                          streamInfo.IsTargetAnamorphic,
                                                                                          streamInfo.TargetRefFrames);

            foreach (var contentFeature in contentFeatureList)
            {
                AddVideoResource(container, video, deviceId, filter, contentFeature, streamInfo);
            }

            foreach (var subtitle in streamInfo.GetExternalSubtitles(_serverAddress))
            {
                AddSubtitleElement(container, subtitle);
            }
        }