aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Model/Dto/MediaSourceInfo.cs
blob: 068443238bb99e4ae26ebab3cf3f9a55780aebff (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Extensions;
using MediaBrowser.Model.MediaInfo;
using System.Collections.Generic;
using System.Runtime.Serialization;

namespace MediaBrowser.Model.Dto
{
    public class MediaSourceInfo
    {
        public MediaProtocol Protocol { get; set; }
        public string Id { get; set; }

        public string Path { get; set; }

        public MediaSourceType Type { get; set; }

        public string Container { get; set; }
        public long? Size { get; set; }

        public string Name { get; set; }

        public long? RunTimeTicks { get; set; }
        public bool ReadAtNativeFramerate { get; set; }

        public VideoType? VideoType { get; set; }

        public IsoType? IsoType { get; set; }

        public Video3DFormat? Video3DFormat { get; set; }

        public List<MediaStream> MediaStreams { get; set; }
        public List<string> PlayableStreamFileNames { get; set; }

        public List<string> Formats { get; set; }

        public int? Bitrate { get; set; }

        public TransportStreamTimestamp? Timestamp { get; set; }
        public Dictionary<string, string> RequiredHttpHeaders { get; set; }

        public MediaSourceInfo()
        {
            Formats = new List<string>();
            MediaStreams = new List<MediaStream>();
            RequiredHttpHeaders = new Dictionary<string, string>();
            PlayableStreamFileNames = new List<string>();
        }

        public int? DefaultAudioStreamIndex { get; set; }
        public int? DefaultSubtitleStreamIndex { get; set; }

        [IgnoreDataMember]
        public MediaStream DefaultAudioStream
        {
            get
            {
                if (DefaultAudioStreamIndex.HasValue)
                {
                    var val = DefaultAudioStreamIndex.Value;

                    foreach (MediaStream i in MediaStreams)
                    {
                        if (i.Type == MediaStreamType.Audio && i.Index == val)
                        {
                            return i;
                        }
                    }
                }

                foreach (MediaStream i in MediaStreams)
                {
                    if (i.Type == MediaStreamType.Audio && i.IsDefault)
                    {
                        return i;
                    }
                }

                foreach (MediaStream i in MediaStreams)
                {
                    if (i.Type == MediaStreamType.Audio)
                    {
                        return i;
                    }
                }

                return null;
            }
        }

        [IgnoreDataMember]
        public MediaStream VideoStream
        {
            get
            {
                foreach (MediaStream i in MediaStreams)
                {
                    if (i.Type == MediaStreamType.Video && StringHelper.IndexOfIgnoreCase((i.Codec ?? string.Empty), "jpeg") == -1)
                    {
                        return i;
                    }
                }

                return null;
            }
        }

        public MediaStream GetMediaStream(MediaStreamType type, int index)
        {
            foreach (MediaStream i in MediaStreams)
            {
                if (i.Type == type && i.Index == index)
                {
                    return i;
                }
            }

            return null;
        }
    }
}