-
Notifications
You must be signed in to change notification settings - Fork 0
/
tagread.vala
141 lines (109 loc) · 4.06 KB
/
tagread.vala
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
/*
* Riker - a MusicBrainz-enhanced audio player
* Copyright © 2011 Calvin Walton
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of version 2 of the GNU General Public
* License as published by the Free Software Foundation.
*
* This program 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 General Public License for more details.
*/
namespace Riker {
class TagRead {
public static int main(string[] args) {
Gst.init(ref args);
#if ENABLE_UNINSTALLED
stderr.printf("This is an UNINSTALLED build. Do not install it.\n");
stderr.printf("Using files from source directory: %s\n", Config.BUILD_SRCDIR);
#endif
var store = new Store();
try {
store.open();
} catch (StoreError e) {
if (e is StoreError.CORRUPT_DB) {
stderr.printf("%s\n", e.message);
stderr.printf("To resolve this, try deleting the database file so it can be re-created.\n");
} else {
stderr.printf("%s\n", e.message);
}
return 1;
}
if (args.length < 2) {
stderr.printf("Usage: %s file:///path/to/file\n", args[0]);
return 1;
}
GLib.File filearg = GLib.File.new_for_commandline_arg(args[1]);
var uri = filearg.get_uri();
// This is the information that will be stored per-file.
string? recording_mbid = null;
string? release_mbid = null;
uint track_position = 0;
uint medium_position = 0;
string? codec = null;
uint bitrate = 0;
uint duration = 0;
var pipe = new Gst.Pipeline("pipeline");
dynamic Gst.Element dec = Gst.ElementFactory.make("uridecodebin", null);
dec.uri = uri;
pipe.add(dec);
Gst.Element sink = Gst.ElementFactory.make("fakesink", null);
pipe.add(sink);
dec.pad_added.connect((pad) => {
var sinkpad = sink.get_static_pad("sink");
if (!sinkpad.is_linked()) {
if (pad.link(sinkpad) != Gst.PadLinkReturn.OK) {
error("Failed to link pads!");
}
}
});
pipe.set_state(Gst.State.PAUSED);
while (true) {
var msg = pipe.get_bus().timed_pop_filtered(Gst.CLOCK_TIME_NONE, Gst.MessageType.ASYNC_DONE | Gst.MessageType.TAG | Gst.MessageType.ERROR);
if (msg.type != Gst.MessageType.TAG) {
break;
}
Gst.TagList tags;
msg.parse_tag(out tags);
if (tags.get_tag_size(Gst.TAG_MUSICBRAINZ_TRACKID) > 0)
tags.get_string(Gst.TAG_MUSICBRAINZ_TRACKID, out recording_mbid);
if (tags.get_tag_size(Gst.TAG_MUSICBRAINZ_ALBUMID) > 0)
tags.get_string(Gst.TAG_MUSICBRAINZ_ALBUMID, out release_mbid);
if (tags.get_tag_size(Gst.TAG_TRACK_NUMBER) > 0)
tags.get_uint(Gst.TAG_TRACK_NUMBER, out track_position);
if (tags.get_tag_size(Gst.TAG_ALBUM_VOLUME_NUMBER) > 0)
tags.get_uint(Gst.TAG_ALBUM_VOLUME_NUMBER, out medium_position);
if (tags.get_tag_size(Gst.TAG_AUDIO_CODEC) > 0)
tags.get_string(Gst.TAG_AUDIO_CODEC, out codec);
if (tags.get_tag_size(Gst.TAG_BITRATE) > 0)
tags.get_uint(Gst.TAG_BITRATE, out bitrate);
}
var query = new Gst.Query.duration(Gst.Format.TIME);
var res = pipe.query(query);
if (res) {
int64 duration_ns;
query.parse_duration(null, out duration_ns);
duration = (uint) (duration_ns / 1000000);
}
/*File file = new File.from_data(recording_mbid, release_mbid, track_position, medium_position, codec, bitrate, duration);*/
print("recording_mbid: %s\n", recording_mbid);
print("release_mbid: %s\n", release_mbid);
print("track_position: %u\n", track_position);
print("medium_position: %u\n", medium_position);
print("codec: %s\n", codec);
print("bitrate: %u\n", bitrate);
print("duration: %u\n", duration);
pipe.set_state(Gst.State.NULL);
print("Performing a MusicBrainz query...\n");
Musicbrainz.Query mb4_query = new Musicbrainz.Query("Riker/0.1 ( http://www.kepstin.ca/projects/riker )");
Musicbrainz.Metadata m = mb4_query.query("release", release_mbid, null, inc: "media recordings");
Musicbrainz.Release r = m.release;
if (r != null) {
print("Release title: %s\n", r.title);
}
return 0;
}
}
}