summaryrefslogtreecommitdiff
path: root/src/librygel-server/rygel-subtitle.vala
blob: 7b2ce5ea3f57a0ed4ceed6b4b788fb73182818f1 (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
/*
 * Copyright (C) 2008 Zeeshan Ali <zeenix@gmail.com>.
 * Copyright (C) 2010 Andreas Henriksson <andreas@fatal.se>
 *
 * Authors: Andreas Henriksson <andreas@fatal.se>
 *          Zeeshan Ali (Khattak) <zeeshanak@gnome.org>
 *
 * This file is part of Rygel.
 *
 * Rygel is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * Rygel is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 */

using GUPnP;

/**
 * Represents a subtitle for a video.
 */
public class Rygel.Subtitle {
    public string uri;
    public string mime_type;
    public string caption_type;
    public string file_extension;

    public int64 size = -1;   // Size in bytes

    public Subtitle (string mime_type = "text/srt",
                     string caption_type = "srt",
                     string file_extension = "srt") {
        this.mime_type = mime_type;
        this.caption_type = caption_type;
        this.file_extension = file_extension;
    }

    internal void add_didl_node (DIDLLiteItem didl_item) {
        Xml.Node *item_node = didl_item.xml_node;
        Xml.Node *root_node = item_node->doc->get_root_element ();

        weak Xml.Ns sec_ns = root_node->new_ns ("http://www.sec.co.kr/", "sec");
        // sec_ns apparently already existed. Search for the namespace node
        if (sec_ns == null) {
            weak Xml.Ns it = root_node->ns_def;
            while (it != null) {
                if (it.prefix == "sec") {
                    sec_ns = it;

                    break;
                }
                it = it.next;
            }
        }

        Xml.Node *sec_node = item_node->new_child (sec_ns,
                                                   "CaptionInfoEx",
                                                   this.uri);

        sec_node->new_ns_prop (sec_ns, "type", this.caption_type);
    }

    internal virtual MediaResource get_resource (string protocol, int index) {
        var name = "%s_subtitle_%2d".printf (protocol, index);

        var res = new MediaResource (name);

        res.size = this.size;
        res.mime_type = this.mime_type;
        res.protocol = protocol;

        // Note: These represent best-case. The MediaServer/HTTPServer can
        // dial these back
        res.dlna_flags |= DLNAFlags.INTERACTIVE_TRANSFER_MODE |
                          DLNAFlags.BACKGROUND_TRANSFER_MODE |
                          DLNAFlags.CONNECTION_STALL |
                          DLNAFlags.DLNA_V15;
        res.dlna_operation = DLNAOperation.RANGE;
        res.dlna_conversion = DLNAConversion.TRANSCODED;
        res.extension = this.file_extension;

        res.uri = this.uri;

        return res;
    }
}