lms plugin: do not skip files with absent mimetypes
[profile/ivi/rygel.git] / src / plugins / lms / rygel-lms-all-videos.vala
1 /*
2  * Copyright (C) 2013 Intel Corporation.
3  *
4  * Author: Jussi Kukkonen <jussi.kukkonen@intel.com>
5  *
6  * This file is part of Rygel.
7  *
8  * Rygel is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU Lesser General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * Rygel is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public License
19  * along with this program; if not, write to the Free Software Foundation,
20  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21  */
22
23 using Rygel;
24 using Sqlite;
25
26 public class Rygel.LMS.AllVideos : Rygel.LMS.CategoryContainer {
27     private static const string SQL_ALL =
28         "SELECT videos.id, title, artist, length, path, dtime, size, dlna_profile, dlna_mime " +
29         "FROM videos, files " +
30         "WHERE videos.id = files.id " +
31         "LIMIT ? OFFSET ?;";
32
33    private static const string SQL_COUNT =
34         "SELECT count(videos.id) " +
35         "FROM videos, files " +
36         "WHERE videos.id = files.id;";
37
38     private static const string SQL_FIND_OBJECT =
39         "SELECT videos.id, title, artist, length, path, dtime, size, dlna_profile, dlna_mime " +
40         "FROM videos, files " +
41         "WHERE files.id = ? AND videos.id = files.id;";
42
43     protected override MediaObject? object_from_statement (Statement statement) {
44         var id = statement.column_int(0);
45         var mime_type = statement.column_text(8);
46         var path = statement.column_text(4);
47         var file = File.new_for_path(path);
48
49         /* TODO: Temporary code to extract the MIME TYPE.  LMS does not seem
50            to compute the mime type of videos.  Don't know why. */
51
52 /*        if (mime_type == null || mime_type.length == 0) {
53             try {
54                 FileInfo info = file.query_info(FileAttribute.STANDARD_CONTENT_TYPE,
55                                                 FileQueryInfoFlags.NONE, null);
56                 mime_type = info.get_content_type();
57             } catch {}
58         }
59 */
60
61         if (mime_type == null || mime_type.length == 0) {
62             /* TODO is this correct? */
63             debug ("Video item %d (%s) has no MIME type",
64                    id,
65                    path);
66             }
67
68         var title = statement.column_text(1);
69         var video = new VideoItem(this.build_child_id (id), this, title);
70         video.creator = statement.column_text(2);
71         video.duration = statement.column_int(3);
72         TimeVal tv = { (long) statement.column_int(5), (long) 0 };
73         video.date = tv.to_iso8601 ();
74         video.size = statement.column_int(6);
75         video.dlna_profile = statement.column_text(7);
76         video.mime_type = mime_type;
77         video.add_uri (file.get_uri ());
78
79         return video;
80     }
81
82     public AllVideos (string id, MediaContainer parent, string title, LMS.Database lms_db){
83         base (id,
84               parent,
85               title,
86               lms_db,
87               AllVideos.SQL_ALL,
88               AllVideos.SQL_FIND_OBJECT,
89               AllVideos.SQL_COUNT);
90     }
91 }