Mercurial > audlegacy
annotate src/audtool/handlers_playlist.c @ 4780:6284337e04fd
g_basename is deprecated, replace with g_path_get_basename.
author | Tony Vroon <chainsaw@gentoo.org> |
---|---|
date | Fri, 26 Sep 2008 21:38:00 +0100 |
parents | 3ce92d3cd0e1 |
children |
rev | line source |
---|---|
2927
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
1 /* |
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
2 * Audtool2 |
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
3 * Copyright (c) 2007 Audacious development team |
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
4 * |
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
5 * Redistribution and use in source and binary forms, with or without |
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
6 * modification, are permitted provided that the following conditions are |
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
7 * met: |
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
8 * |
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
9 * 1. Redistributions of source code must retain the above copyright notice, |
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
10 * this list of conditions and the following disclaimer. |
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
11 * |
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
12 * 2. Redistributions in binary form must reproduce the above copyright |
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
13 * notice, this list of conditions and the following disclaimer in the |
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
14 * documentation and/or other materials provided with the distribution. |
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
15 * |
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
16 * 3. The name of the author may not be used to endorse or promote products |
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
17 * derived from this software without specific prior written permission. |
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
18 * |
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
20 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
21 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
22 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, |
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
23 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
25 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
27 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING |
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
28 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
29 * POSSIBILITY OF SUCH DAMAGE. |
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
30 */ |
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
31 |
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
32 #include <stdlib.h> |
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
33 #include <string.h> |
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
34 #include <glib.h> |
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
35 #include <mowgli.h> |
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
36 #include <locale.h> |
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
37 #include "libaudclient/audctrl.h" |
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
38 #include "audtool.h" |
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
39 |
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
40 void playlist_reverse(gint argc, gchar **argv) |
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
41 { |
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
42 audacious_remote_playlist_prev(dbus_proxy); |
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
43 } |
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
44 |
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
45 void playlist_advance(gint argc, gchar **argv) |
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
46 { |
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
47 audacious_remote_playlist_next(dbus_proxy); |
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
48 } |
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
49 |
4611
895297e46ee3
Cure some 'repetitive code syndromes' from audtool.
Matti Hamalainen <ccr@tnsp.org>
parents:
4609
diff
changeset
|
50 |
895297e46ee3
Cure some 'repetitive code syndromes' from audtool.
Matti Hamalainen <ccr@tnsp.org>
parents:
4609
diff
changeset
|
51 gint check_args_playlist_pos(gint argc, gchar **argv) |
895297e46ee3
Cure some 'repetitive code syndromes' from audtool.
Matti Hamalainen <ccr@tnsp.org>
parents:
4609
diff
changeset
|
52 { |
895297e46ee3
Cure some 'repetitive code syndromes' from audtool.
Matti Hamalainen <ccr@tnsp.org>
parents:
4609
diff
changeset
|
53 gint playpos; |
895297e46ee3
Cure some 'repetitive code syndromes' from audtool.
Matti Hamalainen <ccr@tnsp.org>
parents:
4609
diff
changeset
|
54 |
895297e46ee3
Cure some 'repetitive code syndromes' from audtool.
Matti Hamalainen <ccr@tnsp.org>
parents:
4609
diff
changeset
|
55 if (argc < 2) |
895297e46ee3
Cure some 'repetitive code syndromes' from audtool.
Matti Hamalainen <ccr@tnsp.org>
parents:
4609
diff
changeset
|
56 { |
895297e46ee3
Cure some 'repetitive code syndromes' from audtool.
Matti Hamalainen <ccr@tnsp.org>
parents:
4609
diff
changeset
|
57 audtool_whine_args(argv[0], "<position>"); |
895297e46ee3
Cure some 'repetitive code syndromes' from audtool.
Matti Hamalainen <ccr@tnsp.org>
parents:
4609
diff
changeset
|
58 exit(1); |
895297e46ee3
Cure some 'repetitive code syndromes' from audtool.
Matti Hamalainen <ccr@tnsp.org>
parents:
4609
diff
changeset
|
59 } |
895297e46ee3
Cure some 'repetitive code syndromes' from audtool.
Matti Hamalainen <ccr@tnsp.org>
parents:
4609
diff
changeset
|
60 |
895297e46ee3
Cure some 'repetitive code syndromes' from audtool.
Matti Hamalainen <ccr@tnsp.org>
parents:
4609
diff
changeset
|
61 playpos = atoi(argv[1]); |
895297e46ee3
Cure some 'repetitive code syndromes' from audtool.
Matti Hamalainen <ccr@tnsp.org>
parents:
4609
diff
changeset
|
62 |
895297e46ee3
Cure some 'repetitive code syndromes' from audtool.
Matti Hamalainen <ccr@tnsp.org>
parents:
4609
diff
changeset
|
63 if (playpos < 1 || playpos > audacious_remote_get_playlist_length(dbus_proxy)) |
895297e46ee3
Cure some 'repetitive code syndromes' from audtool.
Matti Hamalainen <ccr@tnsp.org>
parents:
4609
diff
changeset
|
64 { |
895297e46ee3
Cure some 'repetitive code syndromes' from audtool.
Matti Hamalainen <ccr@tnsp.org>
parents:
4609
diff
changeset
|
65 audtool_whine("invalid playlist position %d ('%s')\n", playpos, argv[1]); |
895297e46ee3
Cure some 'repetitive code syndromes' from audtool.
Matti Hamalainen <ccr@tnsp.org>
parents:
4609
diff
changeset
|
66 exit(2); |
895297e46ee3
Cure some 'repetitive code syndromes' from audtool.
Matti Hamalainen <ccr@tnsp.org>
parents:
4609
diff
changeset
|
67 } |
895297e46ee3
Cure some 'repetitive code syndromes' from audtool.
Matti Hamalainen <ccr@tnsp.org>
parents:
4609
diff
changeset
|
68 |
895297e46ee3
Cure some 'repetitive code syndromes' from audtool.
Matti Hamalainen <ccr@tnsp.org>
parents:
4609
diff
changeset
|
69 return playpos; |
895297e46ee3
Cure some 'repetitive code syndromes' from audtool.
Matti Hamalainen <ccr@tnsp.org>
parents:
4609
diff
changeset
|
70 } |
895297e46ee3
Cure some 'repetitive code syndromes' from audtool.
Matti Hamalainen <ccr@tnsp.org>
parents:
4609
diff
changeset
|
71 |
895297e46ee3
Cure some 'repetitive code syndromes' from audtool.
Matti Hamalainen <ccr@tnsp.org>
parents:
4609
diff
changeset
|
72 |
895297e46ee3
Cure some 'repetitive code syndromes' from audtool.
Matti Hamalainen <ccr@tnsp.org>
parents:
4609
diff
changeset
|
73 static gchar * construct_uri(gchar *string) |
4074 | 74 { |
75 gchar *filename = g_strdup(string); | |
76 gchar *tmp, *path; | |
77 gchar *uri = NULL; | |
78 | |
79 // case 1: filename is raw full path or uri | |
80 if (filename[0] == '/' || strstr(filename, "://")) { | |
81 uri = g_filename_to_uri(filename, NULL, NULL); | |
82 if(!uri) { | |
83 uri = g_strdup(filename); | |
84 } | |
85 g_free(filename); | |
86 } | |
87 // case 2: filename is not raw full path nor uri. | |
88 // make full path with pwd. (using g_build_filename) | |
89 else { | |
90 path = g_get_current_dir(); | |
91 tmp = g_build_filename(path, filename, NULL); | |
92 g_free(path); g_free(filename); | |
93 uri = g_filename_to_uri(tmp, NULL, NULL); | |
94 g_free(tmp); | |
95 } | |
96 | |
97 return uri; | |
98 } | |
99 | |
2927
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
100 void playlist_add_url_string(gint argc, gchar **argv) |
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
101 { |
4074 | 102 gchar *uri; |
103 | |
2927
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
104 if (argc < 2) |
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
105 { |
4611
895297e46ee3
Cure some 'repetitive code syndromes' from audtool.
Matti Hamalainen <ccr@tnsp.org>
parents:
4609
diff
changeset
|
106 audtool_whine_args(argv[0], "<url>"); |
3873
f3341c2d6b9e
audacious remote functions:
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
2939
diff
changeset
|
107 exit(1); |
2927
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
108 } |
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
109 |
4074 | 110 uri = construct_uri(argv[1]); |
111 if (uri) { | |
112 audacious_remote_playlist_add_url_string(dbus_proxy, uri); | |
113 } | |
114 g_free(uri); | |
2927
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
115 } |
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
116 |
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
117 void playlist_delete(gint argc, gchar **argv) |
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
118 { |
4611
895297e46ee3
Cure some 'repetitive code syndromes' from audtool.
Matti Hamalainen <ccr@tnsp.org>
parents:
4609
diff
changeset
|
119 gint playpos = check_args_playlist_pos(argc, argv); |
2927
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
120 audacious_remote_playlist_delete(dbus_proxy, playpos - 1); |
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
121 } |
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
122 |
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
123 void playlist_length(gint argc, gchar **argv) |
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
124 { |
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
125 gint i; |
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
126 |
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
127 i = audacious_remote_get_playlist_length(dbus_proxy); |
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
128 |
2934
c32036aa4b4d
Transition to audtool_report()/audtool_whine().
William Pitcock <nenolod@atheme.org>
parents:
2927
diff
changeset
|
129 audtool_report("%d", i); |
2927
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
130 } |
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
131 |
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
132 void playlist_song(gint argc, gchar **argv) |
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
133 { |
4611
895297e46ee3
Cure some 'repetitive code syndromes' from audtool.
Matti Hamalainen <ccr@tnsp.org>
parents:
4609
diff
changeset
|
134 gint playpos = check_args_playlist_pos(argc, argv); |
2927
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
135 gchar *song; |
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
136 |
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
137 song = audacious_remote_get_playlist_title(dbus_proxy, playpos - 1); |
2934
c32036aa4b4d
Transition to audtool_report()/audtool_whine().
William Pitcock <nenolod@atheme.org>
parents:
2927
diff
changeset
|
138 audtool_report("%s", song); |
2927
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
139 } |
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
140 |
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
141 |
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
142 void playlist_song_length(gint argc, gchar **argv) |
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
143 { |
4611
895297e46ee3
Cure some 'repetitive code syndromes' from audtool.
Matti Hamalainen <ccr@tnsp.org>
parents:
4609
diff
changeset
|
144 gint playpos = check_args_playlist_pos(argc, argv); |
895297e46ee3
Cure some 'repetitive code syndromes' from audtool.
Matti Hamalainen <ccr@tnsp.org>
parents:
4609
diff
changeset
|
145 gint frames, length; |
2927
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
146 |
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
147 frames = audacious_remote_get_playlist_time(dbus_proxy, playpos - 1); |
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
148 length = frames / 1000; |
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
149 |
2934
c32036aa4b4d
Transition to audtool_report()/audtool_whine().
William Pitcock <nenolod@atheme.org>
parents:
2927
diff
changeset
|
150 audtool_report("%d:%.2d", length / 60, length % 60); |
2927
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
151 } |
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
152 |
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
153 void playlist_song_length_seconds(gint argc, gchar **argv) |
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
154 { |
4611
895297e46ee3
Cure some 'repetitive code syndromes' from audtool.
Matti Hamalainen <ccr@tnsp.org>
parents:
4609
diff
changeset
|
155 gint playpos = check_args_playlist_pos(argc, argv); |
895297e46ee3
Cure some 'repetitive code syndromes' from audtool.
Matti Hamalainen <ccr@tnsp.org>
parents:
4609
diff
changeset
|
156 gint frames, length; |
2927
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
157 |
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
158 frames = audacious_remote_get_playlist_time(dbus_proxy, playpos - 1); |
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
159 length = frames / 1000; |
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
160 |
2934
c32036aa4b4d
Transition to audtool_report()/audtool_whine().
William Pitcock <nenolod@atheme.org>
parents:
2927
diff
changeset
|
161 audtool_report("%d", length); |
2927
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
162 } |
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
163 |
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
164 void playlist_song_length_frames(gint argc, gchar **argv) |
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
165 { |
4611
895297e46ee3
Cure some 'repetitive code syndromes' from audtool.
Matti Hamalainen <ccr@tnsp.org>
parents:
4609
diff
changeset
|
166 gint playpos = check_args_playlist_pos(argc, argv); |
895297e46ee3
Cure some 'repetitive code syndromes' from audtool.
Matti Hamalainen <ccr@tnsp.org>
parents:
4609
diff
changeset
|
167 gint frames; |
2927
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
168 |
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
169 frames = audacious_remote_get_playlist_time(dbus_proxy, playpos - 1); |
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
170 |
2934
c32036aa4b4d
Transition to audtool_report()/audtool_whine().
William Pitcock <nenolod@atheme.org>
parents:
2927
diff
changeset
|
171 audtool_report("%d", frames); |
2927
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
172 } |
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
173 |
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
174 void playlist_display(gint argc, gchar **argv) |
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
175 { |
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
176 gint i, ii, frames, length, total; |
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
177 gchar *songname; |
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
178 gchar *fmt = NULL, *p; |
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
179 gint column; |
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
180 |
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
181 i = audacious_remote_get_playlist_length(dbus_proxy); |
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
182 |
2934
c32036aa4b4d
Transition to audtool_report()/audtool_whine().
William Pitcock <nenolod@atheme.org>
parents:
2927
diff
changeset
|
183 audtool_report("%d track%s.", i, i != 1 ? "s" : ""); |
2927
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
184 |
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
185 total = 0; |
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
186 |
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
187 for (ii = 0; ii < i; ii++) |
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
188 { |
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
189 songname = audacious_remote_get_playlist_title(dbus_proxy, ii); |
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
190 frames = audacious_remote_get_playlist_time(dbus_proxy, ii); |
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
191 length = frames / 1000; |
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
192 total += length; |
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
193 |
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
194 /* adjust width for multi byte characters */ |
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
195 column = 60; |
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
196 if(songname){ |
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
197 p = songname; |
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
198 while(*p){ |
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
199 gint stride; |
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
200 stride = g_utf8_next_char(p) - p; |
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
201 if(g_unichar_iswide(g_utf8_get_char(p)) |
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
202 || g_unichar_iswide_cjk(g_utf8_get_char(p)) |
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
203 ){ |
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
204 column += (stride - 2); |
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
205 } |
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
206 else { |
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
207 column += (stride - 1); |
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
208 } |
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
209 p = g_utf8_next_char(p); |
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
210 } |
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
211 |
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
212 } |
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
213 |
2934
c32036aa4b4d
Transition to audtool_report()/audtool_whine().
William Pitcock <nenolod@atheme.org>
parents:
2927
diff
changeset
|
214 fmt = g_strdup_printf("%%4d | %%-%ds | %%d:%%.2d", column); |
c32036aa4b4d
Transition to audtool_report()/audtool_whine().
William Pitcock <nenolod@atheme.org>
parents:
2927
diff
changeset
|
215 audtool_report(fmt, ii + 1, songname, length / 60, length % 60); |
2927
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
216 g_free(fmt); |
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
217 } |
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
218 |
2934
c32036aa4b4d
Transition to audtool_report()/audtool_whine().
William Pitcock <nenolod@atheme.org>
parents:
2927
diff
changeset
|
219 audtool_report("Total length: %d:%.2d", total / 60, total % 60); |
2927
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
220 } |
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
221 |
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
222 void playlist_position(gint argc, gchar **argv) |
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
223 { |
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
224 gint i; |
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
225 |
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
226 i = audacious_remote_get_playlist_pos(dbus_proxy); |
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
227 |
2934
c32036aa4b4d
Transition to audtool_report()/audtool_whine().
William Pitcock <nenolod@atheme.org>
parents:
2927
diff
changeset
|
228 audtool_report("%d", i + 1); |
2927
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
229 } |
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
230 |
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
231 void playlist_song_filename(gint argc, gchar **argv) |
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
232 { |
4611
895297e46ee3
Cure some 'repetitive code syndromes' from audtool.
Matti Hamalainen <ccr@tnsp.org>
parents:
4609
diff
changeset
|
233 gint playpos = check_args_playlist_pos(argc, argv); |
2927
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
234 |
4611
895297e46ee3
Cure some 'repetitive code syndromes' from audtool.
Matti Hamalainen <ccr@tnsp.org>
parents:
4609
diff
changeset
|
235 audtool_report("%s", audacious_remote_get_playlist_file(dbus_proxy, playpos - 1)); |
2927
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
236 } |
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
237 |
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
238 void playlist_jump(gint argc, gchar **argv) |
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
239 { |
4611
895297e46ee3
Cure some 'repetitive code syndromes' from audtool.
Matti Hamalainen <ccr@tnsp.org>
parents:
4609
diff
changeset
|
240 gint playpos = check_args_playlist_pos(argc, argv); |
2927
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
241 |
4611
895297e46ee3
Cure some 'repetitive code syndromes' from audtool.
Matti Hamalainen <ccr@tnsp.org>
parents:
4609
diff
changeset
|
242 audacious_remote_set_playlist_pos(dbus_proxy, playpos - 1); |
2927
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
243 } |
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
244 |
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
245 void playlist_clear(gint argc, gchar **argv) |
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
246 { |
3917 | 247 audacious_remote_stop(dbus_proxy); |
2927
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
248 audacious_remote_playlist_clear(dbus_proxy); |
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
249 } |
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
250 |
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
251 void playlist_repeat_status(gint argc, gchar **argv) |
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
252 { |
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
253 if (audacious_remote_is_repeat(dbus_proxy)) |
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
254 { |
2934
c32036aa4b4d
Transition to audtool_report()/audtool_whine().
William Pitcock <nenolod@atheme.org>
parents:
2927
diff
changeset
|
255 audtool_report("on"); |
2927
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
256 } |
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
257 else |
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
258 { |
2934
c32036aa4b4d
Transition to audtool_report()/audtool_whine().
William Pitcock <nenolod@atheme.org>
parents:
2927
diff
changeset
|
259 audtool_report("off"); |
2927
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
260 } |
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
261 } |
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
262 |
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
263 void playlist_repeat_toggle(gint argc, gchar **argv) |
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
264 { |
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
265 audacious_remote_toggle_repeat(dbus_proxy); |
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
266 } |
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
267 |
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
268 void playlist_shuffle_status(gint argc, gchar **argv) |
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
269 { |
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
270 if (audacious_remote_is_shuffle(dbus_proxy)) |
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
271 { |
2934
c32036aa4b4d
Transition to audtool_report()/audtool_whine().
William Pitcock <nenolod@atheme.org>
parents:
2927
diff
changeset
|
272 audtool_report("on"); |
2927
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
273 } |
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
274 else |
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
275 { |
2934
c32036aa4b4d
Transition to audtool_report()/audtool_whine().
William Pitcock <nenolod@atheme.org>
parents:
2927
diff
changeset
|
276 audtool_report("off"); |
2927
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
277 } |
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
278 } |
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
279 |
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
280 void playlist_shuffle_toggle(gint argc, gchar **argv) |
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
281 { |
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
282 audacious_remote_toggle_shuffle(dbus_proxy); |
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
283 } |
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
284 |
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
285 void playlist_tuple_field_data(gint argc, gchar **argv) |
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
286 { |
4611
895297e46ee3
Cure some 'repetitive code syndromes' from audtool.
Matti Hamalainen <ccr@tnsp.org>
parents:
4609
diff
changeset
|
287 gint i; |
3902
1792ab581321
fix improper rendering of data
William Pitcock <nenolod@atheme.org>
parents:
3873
diff
changeset
|
288 gchar *data; |
2927
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
289 |
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
290 if (argc < 3) |
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
291 { |
4611
895297e46ee3
Cure some 'repetitive code syndromes' from audtool.
Matti Hamalainen <ccr@tnsp.org>
parents:
4609
diff
changeset
|
292 audtool_whine_args(argv[0], "<fieldname> <position>"); |
4615
3ce92d3cd0e1
Use audacious_remote_get_tuple_fields() to get available standard tuple
Matti Hamalainen <ccr@tnsp.org>
parents:
4612
diff
changeset
|
293 audtool_whine_tuple_fields(); |
3873
f3341c2d6b9e
audacious remote functions:
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
2939
diff
changeset
|
294 exit(1); |
2927
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
295 } |
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
296 |
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
297 i = atoi(argv[2]); |
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
298 |
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
299 if (i < 1 || i > audacious_remote_get_playlist_length(dbus_proxy)) |
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
300 { |
4611
895297e46ee3
Cure some 'repetitive code syndromes' from audtool.
Matti Hamalainen <ccr@tnsp.org>
parents:
4609
diff
changeset
|
301 audtool_whine("invalid playlist position %d\n", i); |
3873
f3341c2d6b9e
audacious remote functions:
Yoshiki Yazawa <yaz@cc.rim.or.jp>
parents:
2939
diff
changeset
|
302 exit(1); |
2927
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
303 } |
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
304 |
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
305 if (!(data = audacious_get_tuple_field_data(dbus_proxy, argv[1], i - 1))) |
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
306 { |
3902
1792ab581321
fix improper rendering of data
William Pitcock <nenolod@atheme.org>
parents:
3873
diff
changeset
|
307 return; |
2927
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
308 } |
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
309 |
3902
1792ab581321
fix improper rendering of data
William Pitcock <nenolod@atheme.org>
parents:
3873
diff
changeset
|
310 audtool_report("%s", data); |
2927
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
311 |
3902
1792ab581321
fix improper rendering of data
William Pitcock <nenolod@atheme.org>
parents:
3873
diff
changeset
|
312 g_free(data); |
2927
dbba106b417f
Split out playlist functions.
William Pitcock <nenolod@atheme.org>
parents:
diff
changeset
|
313 } |
4074 | 314 |
315 void playlist_ins_url_string(gint argc, gchar **argv) | |
316 { | |
317 gint pos = -1; | |
318 gchar *uri; | |
319 | |
320 if (argc < 3) | |
321 { | |
4611
895297e46ee3
Cure some 'repetitive code syndromes' from audtool.
Matti Hamalainen <ccr@tnsp.org>
parents:
4609
diff
changeset
|
322 audtool_whine_args(argv[0], "<url> <position>"); |
4074 | 323 exit(1); |
324 } | |
325 | |
326 pos = atoi(argv[2]) - 1; | |
327 if(pos >= 0) { | |
328 uri = construct_uri(argv[1]); | |
329 if (uri) { | |
330 audacious_remote_playlist_ins_url_string(dbus_proxy, uri, pos); | |
331 } | |
332 g_free(uri); | |
333 } | |
334 } | |
335 | |
336 void playlist_enqueue_to_temp(gint argc, gchar **argv) | |
337 { | |
338 gchar *uri; | |
339 | |
340 if (argc < 2) | |
341 { | |
4611
895297e46ee3
Cure some 'repetitive code syndromes' from audtool.
Matti Hamalainen <ccr@tnsp.org>
parents:
4609
diff
changeset
|
342 audtool_whine_args(argv[0], "<url>"); |
4074 | 343 exit(1); |
344 } | |
345 | |
346 uri = construct_uri(argv[1]); | |
347 if (uri) { | |
348 audacious_remote_playlist_enqueue_to_temp(dbus_proxy, uri); | |
349 } | |
350 g_free(uri); | |
351 } |