~ubuntu-branches/ubuntu/trusty/mediascanner2/trusty

« back to all changes in this revision

Viewing changes to src/utils/scannermain.cc

  • Committer: Package Import Robot
  • Author(s): Ubuntu daily release
  • Date: 2014-01-10 14:18:01 UTC
  • Revision ID: package-import@ubuntu.com-20140110141801-h341imp6iz14lp5y
Tags: upstream-0.99+14.04.20140110
ImportĀ upstreamĀ versionĀ 0.99+14.04.20140110

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2013 Canonical, Ltd.
 
3
 *
 
4
 * Authors:
 
5
 *    Jussi Pakkanen <jussi.pakkanen@canonical.com>
 
6
 *
 
7
 * This library is free software; you can redistribute it and/or modify it under
 
8
 * the terms of version 3 of the GNU General Public License as published
 
9
 * by the Free Software Foundation.
 
10
 *
 
11
 * This library is distributed in the hope that it will be useful, but WITHOUT
 
12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 
13
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
 
14
 * details.
 
15
 *
 
16
 * You should have received a copy of the GNU General Public License
 
17
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
18
 */
 
19
 
 
20
#include "Scanner.hh"
 
21
#include "MediaFile.hh"
 
22
#include "MediaStore.hh"
 
23
 
 
24
#include <cstdlib>
 
25
#include <cstdio>
 
26
 
 
27
using namespace std;
 
28
 
 
29
static int do_query(vector<string> &files, string &query) {
 
30
    MediaStore s;
 
31
    for(auto &fname : files) {
 
32
        s.insert(MediaFile(fname));
 
33
    }
 
34
    vector<MediaFile> matches = s.query(query);
 
35
    printf("Got %ld matches.\n", (long)matches.size());
 
36
    for(auto &m : matches) {
 
37
        printf(" %s\n", m.getFileName().c_str());
 
38
    }
 
39
    return 0;
 
40
}
 
41
 
 
42
int main(int argc, char **argv) {
 
43
    if(argc != 2) {
 
44
        printf("%s <query term>\n", argv[0]);
 
45
        return 1;
 
46
    }
 
47
    Scanner s;
 
48
    string root = getenv("HOME");
 
49
    string query = argv[1];
 
50
    root += "/Music";
 
51
    vector<string> files = s.scanFiles(root, AudioMedia);
 
52
    printf("Found %ld files.\n", (long)files.size());
 
53
    return do_query(files, query);
 
54
}