comparison src/mtp_up/mtp.c @ 2160:5ba49a9c053c

fixed uploads, using URI's with libmtp is bad, mmm'kay !
author Cristi Magherusan <majeru@atheme-project.org>
date Fri, 09 Nov 2007 00:08:06 +0200
parents cf20f1bd2f1e
children f629e0c90f18
comparison
equal deleted inserted replaced
2159:19725f003ddf 2160:5ba49a9c053c
121 } 121 }
122 122
123 LIBMTP_track_t *track_metadata(Tuple *from_tuple) 123 LIBMTP_track_t *track_metadata(Tuple *from_tuple)
124 { 124 {
125 LIBMTP_track_t *tr; 125 LIBMTP_track_t *tr;
126 gchar *filename, *from_path; 126 gchar *filename, *uri_path;
127 VFSFile *f; 127 VFSFile *f;
128 uint64_t filesize; 128 uint64_t filesize;
129 uint32_t parent_id = 0; 129 uint32_t parent_id = 0;
130 struct stat sb; 130 struct stat sb;
131 131
132 from_path = g_strdup_printf("%s/%s", aud_tuple_get_string(from_tuple, FIELD_FILE_PATH, NULL), aud_tuple_get_string(from_tuple, FIELD_FILE_NAME, NULL)); 132 uri_path = g_strdup_printf("%s/%s", aud_tuple_get_string(from_tuple, FIELD_FILE_PATH, NULL), aud_tuple_get_string(from_tuple, FIELD_FILE_NAME, NULL));
133 gchar *tmp; 133 gchar *tmp = g_strescape(uri_path,NULL);
134 tmp = g_strescape(from_path,NULL);
135 filename=g_filename_from_uri(tmp,NULL,NULL); 134 filename=g_filename_from_uri(tmp,NULL,NULL);
135 g_free(tmp);
136 /* dealing the stream upload (invalidating)*/ 136 /* dealing the stream upload (invalidating)*/
137 if(filename) 137 if(filename)
138 { 138 {
139 f = aud_vfs_fopen(from_path,"r"); 139 f = aud_vfs_fopen(uri_path,"r");
140 g_free(uri_path);
140 if(aud_vfs_is_streaming(f)) 141 if(aud_vfs_is_streaming(f))
141 { 142 {
142 aud_vfs_fclose(f); 143 aud_vfs_fclose(f);
144 g_free(filename);
143 return NULL; 145 return NULL;
144 } 146 }
145 } 147 }
146 148 else
147 if ( stat(from_path, &sb) == -1 ) 149 {
148 { 150 g_print("Warning! the filename is NULL, exiting");
149 #if DEBUG 151 return NULL;
150 g_print("ERROR! encountered while stat()'ing \"%s\"\n",from_path); 152
151 #endif 153 }
154
155 if ( stat(filename, &sb) == -1 )
156 {
157 #if DEBUG
158 g_print("ERROR! encountered while stat()'ing \"%s\"\n",filename);
159 #endif
160 g_free(filename);
152 return NULL; 161 return NULL;
153 } 162 }
154 filesize = (uint64_t) sb.st_size; 163 filesize = (uint64_t) sb.st_size;
155 parent_id = mtp_device->default_music_folder; 164 parent_id = mtp_device->default_music_folder;
156 165
160 tr->artist = g_strdup((gchar*) aud_tuple_get_string(from_tuple, FIELD_ARTIST, NULL)); 169 tr->artist = g_strdup((gchar*) aud_tuple_get_string(from_tuple, FIELD_ARTIST, NULL));
161 tr->album = g_strdup((gchar*)aud_tuple_get_string(from_tuple, FIELD_ALBUM, NULL)); 170 tr->album = g_strdup((gchar*)aud_tuple_get_string(from_tuple, FIELD_ALBUM, NULL));
162 tr->filesize = filesize; 171 tr->filesize = filesize;
163 tr->filename = g_strdup(aud_tuple_get_string(from_tuple, FIELD_FILE_NAME, NULL)); 172 tr->filename = g_strdup(aud_tuple_get_string(from_tuple, FIELD_FILE_NAME, NULL));
164 tr->duration = (uint32_t)aud_tuple_get_int(from_tuple, FIELD_LENGTH, NULL); 173 tr->duration = (uint32_t)aud_tuple_get_int(from_tuple, FIELD_LENGTH, NULL);
165 tr->filetype = find_filetype (from_path); 174 tr->filetype = find_filetype (filename);
166 tr->genre = g_strdup((gchar*)aud_tuple_get_string(from_tuple, FIELD_GENRE, NULL)); 175 tr->genre = g_strdup((gchar*)aud_tuple_get_string(from_tuple, FIELD_GENRE, NULL));
167 tr->date = g_strdup_printf("%d",aud_tuple_get_int(from_tuple, FIELD_YEAR, NULL)); 176 tr->date = g_strdup_printf("%d",aud_tuple_get_int(from_tuple, FIELD_YEAR, NULL));
168 g_free(filename); 177 g_free(filename);
169 g_free(from_path);
170 g_free(tmp);
171 return tr; 178 return tr;
172 } 179 }
173 180
174 gint upload_file(Tuple *from_tuple) 181 gint upload_file(Tuple *from_tuple)
175 { 182 {
176 int ret; 183 int ret;
177 gchar *comp, *from_path = NULL; 184 gchar *tmp, *from_path = NULL, *filename;
178 uint32_t parent_id = 0; 185 uint32_t parent_id = 0;
179 LIBMTP_track_t *gentrack; 186 LIBMTP_track_t *gentrack;
180 gentrack = track_metadata(from_tuple); 187 gentrack = track_metadata(from_tuple);
181 from_path = g_strdup_printf("%s/%s", aud_tuple_get_string(from_tuple, FIELD_FILE_PATH, NULL), aud_tuple_get_string(from_tuple, FIELD_FILE_NAME, NULL)); 188 from_path = g_strdup_printf("%s/%s", aud_tuple_get_string(from_tuple, FIELD_FILE_PATH, NULL), aud_tuple_get_string(from_tuple, FIELD_FILE_NAME, NULL));
182 if(gentrack == NULL) return 1; 189 if(gentrack == NULL) return 1;
183 comp = g_strescape(from_path,NULL); 190 tmp = g_strescape(from_path,NULL);
191 filename=g_filename_from_uri(tmp,NULL,NULL);
192
184 g_free(from_path); 193 g_free(from_path);
194 g_free(tmp);
185 parent_id = mtp_device->default_music_folder; 195 parent_id = mtp_device->default_music_folder;
186 196
187 #if DEBUG 197 #if DEBUG
188 g_print("Uploading track '%s'\n",comp); 198 g_print("Uploading track '%s'\n",filename);
189 #endif 199 #endif
190 ret = LIBMTP_Send_Track_From_File(mtp_device, comp , gentrack, NULL , NULL, parent_id); 200 ret = LIBMTP_Send_Track_From_File(mtp_device, filename , gentrack, NULL , NULL, parent_id);
191 LIBMTP_destroy_track_t(gentrack); 201 LIBMTP_destroy_track_t(gentrack);
192 g_free(comp);
193 if (ret == 0) 202 if (ret == 0)
194 g_print("Track upload finished!\n"); 203 g_print("Track upload finished!\n");
195 else 204 else
196 { 205 {
197 g_print("An error has occured while uploading '%s'...\nUpload failed!!!\n\n",comp); 206 g_print("An error has occured while uploading '%s'...\nUpload failed!!!\n\n",filename);
198 mtp_initialised = FALSE; 207 mtp_initialised = FALSE;
208 g_free(filename);
199 return 1; 209 return 1;
200 } 210 }
201 211 g_free(filename);
202 return 0; 212 return 0;
203 } 213 }
204 214
205 215
206 gpointer upload(gpointer arg) 216 gpointer upload(gpointer arg)