No issues found
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
2 *
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * The Rhythmbox authors hereby grant permission for non-GPL compatible
9 * GStreamer plugins to be used and distributed together with GStreamer
10 * and Rhythmbox. This permission is above and beyond the permissions granted
11 * by the GPL license by which Rhythmbox is covered. If you modify this code
12 * you may extend this exception to your version of the code, but you are not
13 * obligated to do so. If you do not wish to do so, delete this exception
14 * statement from your version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
24 *
25 */
26
27
28 #include "config.h"
29
30 #include <locale.h>
31 #include <glib.h>
32 #include <glib-object.h>
33 #include <glib/gi18n.h>
34
35 #include "rb-podcast-search.h"
36
37 #include <string.h>
38
39 static gboolean debug = FALSE;
40 static int done = 0;
41
42 void rb_debug_realf (const char *func,
43 const char *file,
44 int line,
45 gboolean newline,
46 const char *format, ...) G_GNUC_PRINTF (5, 6);
47
48 /* For the benefit of the podcast parsing code */
49 void
50 rb_debug_realf (const char *func,
51 const char *file,
52 int line,
53 gboolean newline,
54 const char *format, ...)
55 {
56 va_list args;
57 char buffer[1025];
58
59 if (debug == FALSE)
60 return;
61
62 va_start (args, format);
63 g_vsnprintf (buffer, 1024, format, args);
64 va_end (args);
65
66 g_printerr (newline ? "%s:%d [%s] %s\n" : "%s:%d [%s] %s",
67 file, line, func, buffer);
68 }
69
70 static void
71 result_cb (RBPodcastSearch *search, RBPodcastChannel *data)
72 {
73 char datebuf[1025];
74 GDate date;
75
76 g_date_set_time_t (&date, data->pub_date);
77 g_date_strftime (datebuf, 1024, "%F %T", &date);
78
79 g_print ("Result from %s\n", G_OBJECT_TYPE_NAME (search));
80
81 g_print ("Podcast title: %s\n", data->title);
82 g_print ("Description: %s\n", data->description);
83 g_print ("Author: %s\n", data->author);
84 g_print ("Date: %s\n", datebuf);
85
86 if (data->num_posts > 0) {
87 g_print ("Number of episodes: %d\n", data->num_posts);
88 g_print ("\n");
89 } else {
90 GList *l;
91 g_print ("Number of episodes: %d\n", g_list_length (data->posts));
92 g_print ("\n");
93 for (l = data->posts; l != NULL; l = l->next) {
94 RBPodcastItem *item = l->data;
95
96 g_date_set_time_t (&date, item->pub_date);
97 g_date_strftime (datebuf, 1024, "%F %T", &date);
98
99 g_print ("\tItem title: %s\n", item->title);
100 g_print ("\tURL: %s\n", item->url);
101 g_print ("\tAuthor: %s\n", item->author);
102 g_print ("\tDate: %s\n", datebuf);
103 g_print ("\tDescription: %s\n", item->description);
104 g_print ("\n");
105 }
106 }
107 }
108
109 static void
110 finished_cb (RBPodcastSearch *search, GMainLoop *loop)
111 {
112 g_print ("Search %s finished\n", G_OBJECT_TYPE_NAME (search));
113 done++;
114 if (done == 2) {
115 g_main_loop_quit (loop);
116 }
117 }
118
119 int main (int argc, char **argv)
120 {
121 GMainLoop *loop;
122 RBPodcastSearch *itunes;
123 RBPodcastSearch *miroguide;
124 char *text;
125
126 g_type_init ();
127 setlocale (LC_ALL, "");
128 bindtextdomain (GETTEXT_PACKAGE, GNOMELOCALEDIR);
129 bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
130
131 text = argv[1];
132 if (argv[2] != NULL && strcmp (argv[2], "--debug") == 0) {
133 debug = TRUE;
134 }
135
136 loop = g_main_loop_new (NULL, FALSE);
137
138 itunes = RB_PODCAST_SEARCH (g_object_new (rb_podcast_search_itunes_get_type (), NULL));
139 miroguide = RB_PODCAST_SEARCH (g_object_new (rb_podcast_search_miroguide_get_type (), NULL));
140
141 g_signal_connect (itunes, "result", G_CALLBACK (result_cb), NULL);
142 g_signal_connect (miroguide, "result", G_CALLBACK (result_cb), NULL);
143 g_signal_connect (itunes, "finished", G_CALLBACK (finished_cb), loop);
144 g_signal_connect (miroguide, "finished", G_CALLBACK (finished_cb), loop);
145
146 rb_podcast_search_start (itunes, text, 10);
147 rb_podcast_search_start (miroguide, text, 10);
148
149 g_main_loop_run (loop);
150
151 return 0;
152 }