/usr/share/doc/libgpod-doc/examples/test-cp.cc is in libgpod-doc 0.8.3-6ubuntu2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 142 143 144 145 146 147 148 149 150 151 | /*
* Copyright (C) 2006, 2009 Christophe Fergeau
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
* deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <typeinfo>
#include <unistd.h>
#include <glib/gstdio.h>
#include <id3v2tag.h>
#include <mpegfile.h>
#include "itdb.h"
static Itdb_Track *
track_from_file (const char *filename)
{
TagLib::MPEG::File file(filename);
TagLib::Tag *tag;
Itdb_Track *track;
struct stat st;
tag = file.tag();
if (tag == NULL) {
g_print ("Couldn't read tag\n");
return NULL;
}
/* if (typeid (*tag) != typeid (TagLib::ID3v2::Tag)) {
g_print ("Unknown tag type\n");
return NULL;
}*/
/* FIXME: what happens if we try to open a non-MP3 file? */
#ifdef VERBOSE
g_print ("%s:\n", filename);
g_print ("\t%s\n", tag->artist().toCString(true));
g_print ("\t%s\n", tag->album().toCString(true));
g_print ("\t%s\n", tag->title().toCString(true));
g_print ("\t%s\n", tag->genre().toCString(true));
g_print ("\t%d\n", tag->year());
g_print ("\t%d\n", tag->track());
g_print ("\n");
#endif
track = itdb_track_new ();
track->title = g_strdup (tag->title().toCString(true));
track->album = g_strdup (tag->album().toCString(true));
track->artist = g_strdup (tag->artist().toCString(true));
track->genre = g_strdup (tag->genre().toCString(true));
track->comment = g_strdup (tag->comment().toCString(true));
track->filetype = g_strdup ("MP3-file");
if (g_stat (filename, &st) == 0) {
track->size = st.st_size;
}
track->tracklen = file.audioProperties()->length() * 1000;
track->track_nr = tag->track();
track->bitrate = file.audioProperties()->bitrate();
track->samplerate = file.audioProperties()->sampleRate();
track->year = tag->year();
return track;
}
static gboolean
copy_file (Itdb_iTunesDB *db, const char *filename, GError **error)
{
Itdb_Track *track;
gboolean copy_success;
track = track_from_file (filename);
itdb_track_add (db, track, -1);
itdb_playlist_add_track (itdb_playlist_mpl(db), track, -1);
copy_success = itdb_cp_track_to_ipod (track, filename, error);
if (!copy_success) {
itdb_track_free (track);
}
return copy_success;
}
int main (int argc, char **argv)
{
Itdb_iTunesDB *db;
GError *error;
if (argc != 3) {
char *basename = g_path_get_basename(argv[0]);
g_print ("Usage:\n");
g_print ("%s <filename> <mountpoint> \n", basename);
g_free (basename);
exit (1);
}
db = itdb_parse (argv[2], NULL);
if (db == NULL) {
exit (1);
}
if (db == NULL) {
g_print ("Error creating iPod database\n");
exit (1);
}
error = NULL;
if (!copy_file (db, argv[1], &error)) {
g_print ("Error copying music files\n");
if (error && error->message) {
g_print("%s\n", error->message);
g_error_free (error);
}
exit (1);
}
itdb_write (db, &error);
if (error) {
g_print ("Error writing iPod database\n");
if (error->message) {
g_print("%s\n", error->message);
}
g_error_free (error);
exit (1);
}
itdb_free (db);
return 0;
}
|