2
// AppleDeviceTrackInfo.cs
5
// Alan McGovern <amcgovern@novell.com>
7
// Copyright (c) 2010 Moonlight Team
9
// Permission is hereby granted, free of charge, to any person obtaining a copy
10
// of this software and associated documentation files (the "Software"), to deal
11
// in the Software without restriction, including without limitation the rights
12
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13
// copies of the Software, and to permit persons to whom the Software is
14
// furnished to do so, subject to the following conditions:
16
// The above copyright notice and this permission notice shall be included in
17
// all copies or substantial portions of the Software.
19
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
30
using Banshee.Streaming;
31
using Banshee.Collection;
32
using Banshee.Collection.Database;
36
namespace Banshee.Dap.AppleDevice
38
public class AppleDeviceTrackInfo : DatabaseTrackInfo
40
internal GPod.Track IpodTrack {
44
private string mimetype;
45
private string description; // Only used for podcasts.
47
public AppleDeviceTrackInfo (GPod.Track track)
51
CanSaveToDatabase = true;
54
public AppleDeviceTrackInfo (TrackInfo track)
56
CanSaveToDatabase = true;
58
if (track is AppleDeviceTrackInfo) {
59
IpodTrack = ((AppleDeviceTrackInfo)track).IpodTrack;
66
public void UpdateInfo (TrackInfo track)
68
if (track is AppleDeviceTrackInfo) {
69
throw new ArgumentException ("Shouldn't update an AppleDeviceTrackInfo from an AppleDeviceTrackInfo");
72
IsCompilation = track.IsCompilation ;
73
AlbumArtist = track.AlbumArtist;
74
AlbumTitle = track.AlbumTitle;
75
ArtistName = track.ArtistName;
76
BitRate = track.BitRate;
77
SampleRate = track.SampleRate;
79
Comment = track.Comment;
80
Composer = track.Composer;
81
Conductor = track.Conductor;
82
Copyright = track.Copyright;
83
DateAdded = track.DateAdded;
84
DiscCount = track.DiscCount;
85
DiscNumber = track.DiscNumber;
86
Duration = track.Duration;
87
FileSize = track.FileSize;
89
Grouping = track.Grouping;
90
LastPlayed = track.LastPlayed;
91
LastSkipped = track.LastSkipped;
92
PlayCount = track.PlayCount;
93
Rating = track.Rating;
94
ReleaseDate = track.ReleaseDate;
95
SkipCount = track.SkipCount;
96
TrackCount = track.TrackCount;
97
TrackNumber = track.TrackNumber;
98
TrackTitle = track.TrackTitle;
100
MediaAttributes = track.MediaAttributes;
102
ArtistNameSort = track.ArtistNameSort;
103
AlbumTitleSort = track.AlbumTitleSort;
104
AlbumArtistSort = track.AlbumArtistSort;
105
TrackTitleSort = track.TrackTitleSort;
107
var podcast_info = track.ExternalObject as IPodcastInfo;
108
if (podcast_info != null) {
109
description = podcast_info.Description;
110
ReleaseDate = podcast_info.ReleaseDate;
113
mimetype = track.MimeType;
116
private void LoadFromIpodTrack ()
118
var track = IpodTrack;
120
Uri = new SafeUri (System.IO.Path.Combine (track.ITDB.Mountpoint, track.IpodPath.Replace (":", System.IO.Path.DirectorySeparatorChar.ToString ()).Substring (1)));
121
} catch (Exception ex) {
126
ExternalId = (long) track.DBID;
128
IsCompilation = track.Compilation;
129
AlbumArtist = track.AlbumArtist;
130
AlbumTitle = String.IsNullOrEmpty (track.Album) ? null : track.Album;
131
ArtistName = String.IsNullOrEmpty (track.Artist) ? null : track.Artist;
132
BitRate = track.Bitrate;
133
SampleRate = track.Samplerate;
134
Bpm = (int)track.BPM;
135
Comment = track.Comment;
136
Composer = track.Composer;
137
DateAdded = track.TimeAdded;
138
DiscCount = track.CDs;
139
DiscNumber = track.CDNumber;
140
Duration = TimeSpan.FromMilliseconds (track.TrackLength);
141
FileSize = track.Size;
142
Genre = String.IsNullOrEmpty (track.Genre) ? null : track.Genre;
143
Grouping = track.Grouping;
144
LastPlayed = track.TimePlayed;
145
PlayCount = (int) track.PlayCount;
146
TrackCount = track.Tracks;
147
TrackNumber = track.TrackNumber;
148
TrackTitle = String.IsNullOrEmpty (track.Title) ? null : track.Title;
150
description = track.Description;
151
ReleaseDate = track.TimeReleased;
152
ArtistNameSort = track.SortArtist;
153
AlbumTitleSort = track.SortAlbum;
154
AlbumArtistSort = track.SortAlbumArtist;
155
TrackTitleSort = track.SortTitle;
157
rating = track.Rating > 5 ? 0 : (int) track.Rating;
159
if (track.DRMUserID > 0) {
160
PlaybackError = StreamPlaybackError.Drm;
163
MediaAttributes = TrackMediaAttributes.AudioStream;
164
switch (track.MediaType) {
165
case GPod.MediaType.Audio:
166
MediaAttributes |= TrackMediaAttributes.Music;
168
// This seems to cause audio files to show up in Banshee in the Videos section
169
/*case GPod.MediaType.AudioVideo:
170
MediaAttributes |= TrackMediaAttributes.VideoStream;
172
case GPod.MediaType.MusicVideo:
173
MediaAttributes |= TrackMediaAttributes.Music | TrackMediaAttributes.VideoStream;
175
case GPod.MediaType.Movie:
176
MediaAttributes |= TrackMediaAttributes.VideoStream | TrackMediaAttributes.Movie;
178
case GPod.MediaType.TVShow:
179
MediaAttributes |= TrackMediaAttributes.VideoStream | TrackMediaAttributes.TvShow;
181
case GPod.MediaType.Podcast:
182
MediaAttributes |= TrackMediaAttributes.Podcast;
183
// FIXME: persist URL on the track (track.PodcastUrl)
185
case GPod.MediaType.Audiobook:
186
MediaAttributes |= TrackMediaAttributes.AudioBook;
188
case GPod.MediaType.MusicTVShow:
189
MediaAttributes |= TrackMediaAttributes.Music | TrackMediaAttributes.VideoStream | TrackMediaAttributes.TvShow;
193
// If it's just AudioStream, add Music to it as well so it'll show up in Music
194
if (MediaAttributes == TrackMediaAttributes.AudioStream) {
195
MediaAttributes |= TrackMediaAttributes.Music;
199
public void CommitToIpod (GPod.ITDB database)
201
bool addTrack = IpodTrack == null;
202
if (IpodTrack == null) {
203
IpodTrack = new GPod.Track ();
206
var track = IpodTrack;
207
track.Compilation = IsCompilation;
208
track.AlbumArtist = AlbumArtist;
209
track.Bitrate = BitRate;
210
track.Samplerate= (ushort)SampleRate;
211
track.BPM = (short)Bpm;
212
track.Comment = Comment;
213
track.Composer = Composer;
214
track.TimeAdded = DateTime.Now;
215
track.CDs = DiscCount;
216
track.CDNumber = DiscNumber;
217
track.TrackLength = (int) Duration.TotalMilliseconds;
218
track.Size = (int)FileSize;
219
track.Grouping = Grouping;
221
track.TimePlayed = LastPlayed;
223
Hyena.Log.InformationFormat ("Couldn't set TimePlayed to '{0}'", LastPlayed);
225
track.PlayCount = (uint) PlayCount;
226
track.Tracks = TrackCount;
227
track.TrackNumber = TrackNumber;
230
track.TimeReleased = ReleaseDate;
232
Hyena.Log.InformationFormat ("Couldn't set TimeReleased to '{0}'", ReleaseDate);
234
track.Album = AlbumTitle;
235
track.Artist = ArtistName;
236
track.Title = TrackTitle;
239
track.SortArtist = ArtistNameSort;
240
track.SortAlbum = AlbumTitleSort;
241
track.SortAlbumArtist = AlbumArtistSort;
242
track.SortTitle = TrackTitleSort;
244
track.Rating = ((Rating >= 1) && (Rating <= 5)) ? (uint)Rating : 0;
246
if (HasAttribute (TrackMediaAttributes.Podcast)) {
247
track.Description = description;
248
track.RememberPlaybackPosition = true;
249
track.SkipWhenShuffling = true;
250
track.Flag4 = (byte)1;
251
track.MarkUnplayed = (track.PlayCount == 0);
254
track.MediaType = GPod.MediaType.Audio;
255
if (HasAttribute (TrackMediaAttributes.VideoStream)) {
256
if (HasAttribute (TrackMediaAttributes.Podcast)) {
257
track.MediaType = GPod.MediaType.Podcast | GPod.MediaType.Movie;
258
} else if (HasAttribute (TrackMediaAttributes.Music)) {
259
if (HasAttribute (TrackMediaAttributes.TvShow)) {
260
track.MediaType = GPod.MediaType.MusicTVShow;
262
track.MediaType = GPod.MediaType.MusicVideo;
264
} else if (HasAttribute (TrackMediaAttributes.Movie)) {
265
track.MediaType = GPod.MediaType.Movie;
266
} else if (HasAttribute (TrackMediaAttributes.TvShow)) {
267
track.MediaType = GPod.MediaType.TVShow;
269
// I dont' think AudioVideo should be used here; upon loading the tracks
270
// into Banshee, audio files often have AudioVideo (aka MediaType == 0) too.
271
//track.MediaType = GPod.MediaType.AudioVideo;
272
track.MediaType = GPod.MediaType.Movie;
275
if (HasAttribute (TrackMediaAttributes.Podcast)) {
276
track.MediaType = GPod.MediaType.Podcast;
277
} else if (HasAttribute (TrackMediaAttributes.AudioBook)) {
278
track.MediaType = GPod.MediaType.Audiobook;
279
} else if (HasAttribute (TrackMediaAttributes.Music)) {
280
track.MediaType = GPod.MediaType.Audio;
282
track.MediaType = GPod.MediaType.Audio;
287
track.Filetype = mimetype;
289
database.Tracks.Add (IpodTrack);
290
database.MasterPlaylist.Tracks.Add (IpodTrack);
292
if (HasAttribute (TrackMediaAttributes.Podcast) && database.Device.SupportsPodcast) {
293
database.PodcastsPlaylist.Tracks.Add (IpodTrack);
296
database.CopyTrackToIPod (track, Uri.LocalPath);
297
Uri = new SafeUri (GPod.ITDB.GetLocalPath (database.Device, track));
298
ExternalId = (long) IpodTrack.DBID;
301
if (CoverArtSpec.CoverExists (ArtworkId)) {
302
string path = CoverArtSpec.GetPath (ArtworkId);
303
if (!track.ThumbnailsSet (path)) {
304
Log.Error (String.Format ("Could not set cover art for {0}.", path));
307
track.ThumbnailsRemoveAll ();