771
781
/* Copy "new" info read from file to an old Track structure. */
772
static void copy_new_info (Track *from, Track *to)
782
/* Return value: TRUE: at least one item was changed. FALSE: track was
784
static gboolean copy_new_info (Track *from, Track *to)
774
786
ExtraTrackData *efrom, *eto;
788
gboolean changed = FALSE;
776
g_return_if_fail (from);
777
g_return_if_fail (to);
790
g_return_val_if_fail (from, FALSE);
791
g_return_val_if_fail (to, FALSE);
778
792
efrom = from->userdata;
779
793
eto = to->userdata;
780
g_return_if_fail (efrom);
781
g_return_if_fail (eto);
784
to->title = g_strdup (from->title);
787
to->artist = g_strdup (from->artist);
790
to->album = g_strdup (from->album);
793
to->genre = g_strdup (from->genre);
795
g_free (to->composer);
796
to->composer = g_strdup (from->composer);
798
g_free (to->comment);
799
to->comment = g_strdup (from->comment);
801
g_free (to->filetype);
802
to->filetype = g_strdup (from->filetype);
804
g_free (to->description);
805
to->description = g_strdup (from->description);
807
g_free (to->podcasturl);
808
to->podcasturl = g_strdup (from->podcasturl);
810
g_free (to->podcastrss);
811
to->podcastrss = g_strdup (from->podcastrss);
813
g_free (to->subtitle);
814
to->subtitle = g_strdup (from->subtitle);
816
g_free (eto->thumb_path_utf8);
817
eto->thumb_path_utf8 = g_strdup (efrom->thumb_path_utf8);
819
g_free (eto->thumb_path_locale);
820
eto->thumb_path_locale = g_strdup (efrom->thumb_path_locale);
822
g_free (eto->pc_path_utf8);
823
eto->pc_path_utf8 = g_strdup (efrom->pc_path_utf8);
825
g_free (eto->pc_path_locale);
826
eto->pc_path_locale = g_strdup (efrom->pc_path_locale);
828
g_free (eto->charset);
829
eto->charset = g_strdup (efrom->charset);
831
g_free (eto->year_str);
832
eto->year_str = g_strdup_printf ("%d", to->year);
794
g_return_val_if_fail (efrom, FALSE);
795
g_return_val_if_fail (eto, FALSE);
797
for (item=0; item<T_ITEM_NUM; ++item)
821
case T_SORT_ALBUMARTIST:
822
case T_SORT_COMPOSER:
834
case T_TIME_MODIFIED:
835
case T_TIME_RELEASED:
843
changed |= track_copy_item (from, to, item);
846
/* not implemented from tags */
849
case T_REMEMBER_PLAYBACK_POSITION:
850
case T_SKIP_WHEN_SHUFFLING:
862
g_return_val_if_reached (FALSE);
866
if ((eto->charset == NULL) || (strcmp (efrom->charset, eto->charset) != 0))
868
g_free (eto->charset);
869
eto->charset = g_strdup (efrom->charset);
834
873
itdb_artwork_free (to->artwork);
835
874
to->artwork = itdb_artwork_duplicate (from->artwork);
836
to->artwork_size = from->artwork_size;
837
to->artwork_count = from->artwork_count;
838
to->has_artwork = from->has_artwork;
840
to->size = from->size;
841
to->tracklen = from->tracklen;
842
to->cd_nr = from->cd_nr;
844
to->track_nr = from->track_nr;
845
to->tracks = from->tracks;
846
to->bitrate = from->bitrate;
847
to->samplerate = from->samplerate;
848
to->soundcheck = from->soundcheck;
849
eto->mtime = efrom->mtime;
850
to->time_added = from->time_added;
851
to->time_modified = from->time_modified;
852
to->year = from->year;
853
to->compilation = from->compilation;
854
to->unk208 = from->unk208;
855
to->lyrics_flag = from->lyrics_flag;
856
to->movie_flag = from->movie_flag;
875
if ((to->artwork_size != from->artwork_size) ||
876
(to->artwork_count != from->artwork_count) ||
877
(to->has_artwork != from->has_artwork))
878
{ /* FIXME -- artwork might have changed nevertheless */
880
to->artwork_size = from->artwork_size;
881
to->artwork_count = from->artwork_count;
882
to->has_artwork = from->has_artwork;
885
if ((to->lyrics_flag != from->lyrics_flag) ||
886
(to->movie_flag != from->movie_flag))
889
to->lyrics_flag = from->lyrics_flag;
890
to->movie_flag = from->movie_flag;
893
if ((to->pregap != from->pregap) ||
894
(to->postgap != from->postgap) ||
895
(to->samplecount != from->samplecount) ||
896
(to->gapless_data != from->gapless_data) ||
897
(to->gapless_track_flag != from->gapless_track_flag))
900
to->pregap = from->pregap;
901
to->postgap = from->postgap;
902
to->samplecount = from->samplecount;
903
to->gapless_data = from->gapless_data;
904
to->gapless_track_flag = from->gapless_track_flag;
859
910
/* Updates mserv data (rating only) of @track using filename @name to
1001
1052
const gchar **extp = imageext;
1002
1053
while (*extp && !filename_local)
1005
ffname = g_strconcat (fname, *extp, NULL);
1055
gchar *ffname = g_strconcat (fname, *extp, NULL);
1056
filename_utf8 = g_build_filename (dirname, ffname, NULL);
1058
filename_local = charset_from_utf8 (filename_utf8);
1059
g_free (filename_utf8);
1060
if (!g_file_test (filename_local, G_FILE_TEST_EXISTS))
1062
g_free (filename_local);
1063
filename_local = NULL;
1068
while (*extp && !filename_local)
1069
{ /* try uppercase version of extension */
1070
gchar *upper_ext = g_ascii_strup (*extp, -1);
1071
gchar *ffname = g_strconcat (fname, upper_ext, NULL);
1006
1073
filename_utf8 = g_build_filename (dirname, ffname, NULL);
1007
1074
g_free (ffname);
1008
1075
filename_local = charset_from_utf8 (filename_utf8);
1070
1137
case FILE_TYPE_MP3:
1071
1138
nti = mp3_get_file_info (name);
1072
/* Set unk208 to audio */
1073
if (nti) nti->unk208 = 0x00000001;
1139
/* Set mediatype to audio */
1140
if (nti) nti->mediatype = ITDB_MEDIATYPE_AUDIO;
1075
1142
case FILE_TYPE_M4A:
1076
1143
case FILE_TYPE_M4P:
1144
nti = mp4_get_file_info (name);
1145
/* Set mediatype to audio */
1148
nti->mediatype = ITDB_MEDIATYPE_AUDIO;
1077
1151
case FILE_TYPE_M4B:
1078
1152
nti = mp4_get_file_info (name);
1079
/* Set unk208 to audio */
1153
/* Set mediatype to audiobook */
1082
nti->unk208 = 0x00000001;
1156
nti->mediatype = ITDB_MEDIATYPE_AUDIOBOOK;
1085
1159
case FILE_TYPE_WAV:
1086
1160
nti = wav_get_file_info (name);
1087
/* Set unk208 to audio */
1161
/* Set mediatype to audio */
1090
nti->unk208 = 0x00000001;
1164
nti->mediatype = ITDB_MEDIATYPE_AUDIO;
1168
nti = ogg_get_file_info (name);
1169
/* Set mediatype to audio */
1172
nti->mediatype = ITDB_MEDIATYPE_AUDIO;
1175
case FILE_TYPE_FLAC:
1176
nti = flac_get_file_info (name);
1177
/* Set mediatype to audio */
1180
nti->mediatype = ITDB_MEDIATYPE_AUDIO;
1093
1183
case FILE_TYPE_M4V:
1094
1184
case FILE_TYPE_MP4:
1095
1185
/* I don't know if .m4v and .mp4 can simply be handled like
1096
1186
this. Let's see if someone complains. */
1097
1187
nti = mp4_get_file_info (name);
1098
1188
if (!nti) video_get_file_info (name);
1099
/* Set unk208 to video */
1189
/* Set mediatype to video */
1102
nti->unk208 = 0x00000002;
1192
nti->mediatype = ITDB_MEDIATYPE_MOVIE;
1103
1193
nti->movie_flag = 0x01;
1165
1255
/* Set modification date to the files modified date */
1166
nti->time_modified = itdb_time_host_to_mac(enti->mtime);
1167
/* Set added date to *now* */
1168
nti->time_added = itdb_time_get_mac_time ();
1256
nti->time_modified = enti->mtime;
1257
/* Set added date to *now* (unless orig_track is present) */
1260
nti->time_added = orig_track->time_added;
1264
nti->time_added = time (NULL);
1170
1267
/* Make sure all strings are initialized -- that way we don't
1171
1268
have to worry about it when we are handling the
1172
1269
strings. Also, validate_entries() will fill in the utf16
1173
1270
strings if that hasn't already been done. */
1174
/* exception: md5_hash, charset and hostname: these may be
1271
/* exception: sha1_hash, charset and hostname: these may be
1177
1274
gp_track_validate_entries (nti);
1539
1634
g_return_if_fail (itdb);
1540
1635
g_return_if_fail (track);
1541
etr = track->userdata;
1542
g_return_if_fail (etr);
1636
oetr = track->userdata;
1637
g_return_if_fail (oetr);
1543
1638
/* remember size of track on iPod */
1544
1639
if (track->transferred) oldsize = track->size;
1545
1640
else oldsize = 0;
1547
1642
/* remember if charset was set */
1548
if (etr->charset) charset_set = TRUE;
1643
if (oetr->charset) charset_set = TRUE;
1549
1644
else charset_set = FALSE;
1551
1646
if (!prefs_get_int("update_charset") && charset_set)
1552
1647
{ /* we should use the initial charset for the update */
1553
1648
prefs_charset = prefs_get_string("charset");
1554
1649
/* use the charset used when first importing the track */
1555
prefs_set_string("charset", etr->charset);
1650
prefs_set_string("charset", oetr->charset);
1558
1653
trackpath = get_file_name_from_source (track, SOURCE_PREFER_LOCAL);
1561
if (!(etr->pc_path_locale && *etr->pc_path_locale))
1656
if (!(oetr->pc_path_locale && *oetr->pc_path_locale))
1562
1657
{ /* no path available */
1598
1693
if (trackpath && get_track_info_from_file (trackpath, track))
1599
{ /* update successfull */
1600
/* remove track from md5 hash and reinsert it
1694
{ /* update successful */
1695
ExtraTrackData *netr = track->userdata;
1697
/* remove track from sha1 hash and reinsert it
1601
1698
(hash value may have changed!) */
1602
gchar *name_on_ipod;
1603
gchar *oldhash = etr->md5_hash;
1699
gchar *oldhash = oetr->sha1_hash;
1605
md5_track_remove (track);
1701
sha1_track_remove (track);
1606
1702
/* need to remove the old value manually! */
1607
etr->md5_hash = NULL;
1608
oldtrack = md5_track_exists_insert (itdb, track);
1703
oetr->sha1_hash = NULL;
1704
oldtrack = sha1_track_exists_insert (itdb, track);
1609
1705
if (oldtrack) { /* track exists, remove old track
1610
1706
and register the new version */
1611
md5_track_remove (oldtrack);
1707
sha1_track_remove (oldtrack);
1612
1708
gp_duplicate_remove (track, oldtrack);
1613
md5_track_exists_insert (itdb, track);
1709
sha1_track_exists_insert (itdb, track);
1615
/* track may have to be copied to iPod on next export */
1616
/* since it will copied under the same name as before, we
1617
don't have to manually remove it */
1618
name_on_ipod = get_file_name_from_source (track, SOURCE_IPOD);
1619
if (name_on_ipod && (strcmp (name_on_ipod, trackpath) != 0))
1620
{ /* trackpath is not on the iPod */
1621
if (oldhash && etr->md5_hash)
1622
{ /* do we really have to copy the track again? */
1623
if (strcmp (oldhash, etr->md5_hash) != 0)
1625
track->transferred = FALSE;
1626
data_changed (itdb);
1712
if (itdb->usertype & GP_ITDB_TYPE_IPOD)
1713
{ /* track may have to be copied to iPod on next export */
1714
gchar *name_on_ipod;
1715
gboolean transfer_again = FALSE;
1717
name_on_ipod = get_file_name_from_source (track, SOURCE_IPOD);
1718
if (name_on_ipod && (strcmp (name_on_ipod, trackpath) != 0))
1719
{ /* trackpath is not on the iPod */
1720
if (oldhash && oetr->sha1_hash)
1721
{ /* do we really have to copy the track again? */
1722
if (strcmp (oldhash, oetr->sha1_hash) != 0)
1724
transfer_again = TRUE;
1728
{ /* no hash available -- copy! */
1729
transfer_again = TRUE;
1630
{ /* no hash available -- copy! */
1734
data_changed (itdb);
1738
{ /* We need to copy the track back to the iPod. That's done
1739
marking a copy of the original track for deletion and
1740
then adding the original track to the
1741
conversion/transfer list */
1742
Track *new_track = gp_track_new ();
1743
ExtraTrackData *new_etr = new_track->userdata;
1744
g_return_if_fail (new_etr);
1746
new_track->size = oldsize;
1747
new_track->ipod_path = track->ipod_path;
1748
track->ipod_path = g_strdup ("");
1631
1749
track->transferred = FALSE;
1632
data_changed (itdb);
1751
/* cancel conversion/transfer of track */
1752
file_convert_cancel_track (track);
1753
/* mark the track for deletion on the ipod */
1754
mark_track_for_deletion (itdb, new_track);
1755
/* reschedule conversion/transfer of track */
1756
file_convert_add_track (track);
1758
netr->tchanged = TRUE;
1761
g_free (name_on_ipod);
1764
/* notify display model */
1767
pm_track_changed (track);
1637
1768
data_changed (itdb);
1769
netr->tchanged = FALSE;
1639
g_free (name_on_ipod);
1641
/* set old size if track has to be transferred (for free space
1643
if (!track->transferred) etr->oldsize = oldsize;
1644
/* notify display model */
1645
pm_track_changed (track);
1646
1771
display_updated (track, NULL);
1647
1772
g_free (oldhash);
1649
1774
else if (trackpath)
1650
1775
{ /* update not successful -- log this track for later display */
1651
display_non_updated (track, _("update failed (format no supported?)"));
1776
display_non_updated (track, _("update failed (format not supported?)"));
1654
1779
if (!prefs_get_int("update_charset") && charset_set)
1982
2121
g_free (ipod_fullpath);
1984
/* remove track from md5 hash and reinsert it (hash value has changed!) */
1985
md5_track_remove (track);
1986
C_FREE (etr->md5_hash); /* need to remove the old value manually! */
1987
oldtrack = md5_track_exists_insert (itdb, track);
2123
/* remove track from sha1 hash and reinsert it (hash value has changed!) */
2124
sha1_track_remove (track);
2125
C_FREE (etr->sha1_hash); /* need to remove the old value manually! */
2126
oldtrack = sha1_track_exists_insert (itdb, track);
1988
2127
if (oldtrack) { /* track exists, remove and register the new version */
1989
md5_track_remove (oldtrack);
2128
sha1_track_remove (oldtrack);
1990
2129
gp_duplicate_remove (track, oldtrack);
1991
md5_track_exists_insert (itdb, track);
2130
sha1_track_exists_insert (itdb, track);
1994
2133
if (!prefs_get_int("write_charset") && track_charset_set)