private void button4_Click(object sender, EventArgs e) { iTunes = new iTunesAppClass(); mainLibrary = iTunes.LibraryPlaylist; tracks = mainLibrary.Tracks; IITFileOrCDTrack track = tracks[ActiveWorkingTrack.Position.Value] as IITFileOrCDTrack; if (track != null) { if (track.Artist != this.iTunesArtist.Text) { track.Artist = this.iTunesArtist.Text; } if (track.Name != this.iTunesSongName.Text) { track.Name = this.iTunesSongName.Text; } if (track.Album != this.iTunesAlbum.Text) { track.Album = this.iTunesAlbum.Text; } if (track.AlbumArtist != this.iTunesAlbumArtist.Text) { track.AlbumArtist = this.iTunesAlbumArtist.Text; } if (track.SortArtist != this.iTunesSortArtist.Text) { track.SortArtist = this.iTunesSortArtist.Text; } if (track.SortName != this.iTunesSortName.Text) { track.SortName = this.iTunesSortName.Text; } if (track.SortAlbumArtist != this.iTunesSortAlbumArtist.Text) { track.SortAlbumArtist = this.iTunesSortAlbumArtist.Text; } if (track.TrackNumber.ToString() != this.iTunesTrackNumber.Text) { track.TrackNumber = int.Parse(this.iTunesTrackNumber.Text); } if (track.Year.ToString() != this.iTunesYear.Text) { track.Year = int.Parse(this.iTunesYear.Text); } if (track.Comment != this.iTunesComment.Text) { track.Comment = this.iTunesComment.Text; } } }
private void button16_Click(object sender, EventArgs e) { iTunes = new iTunesAppClass(); mainLibrary = iTunes.LibraryPlaylist; tracks = mainLibrary.Tracks; var count = tracks.Count; var sb = new StringBuilder(); for (int i = 1; i < tracks.Count + 1; i++) { IITFileOrCDTrack track = tracks[i] as IITFileOrCDTrack; if (track != null) { if (track.Location != null) { if (track.Location.StartsWith(FileRoot)) { if (!string.IsNullOrWhiteSpace(track.Description)) { track.Description = ""; sb.AppendLine(track.Location); } } } } } textBox1.Text = sb.ToString(); }
static void Main(string[] args) { myLib = myTunes.LibraryPlaylist; startTime = lastChecked = DateTime.Now; FileSystemWatcher fsw = new FileSystemWatcher(@"G:\transfers"); //Set up FileSystemWatcher fsw.IncludeSubdirectories = true; fsw.Changed += new FileSystemEventHandler(fswChanged); fsw.EnableRaisingEvents = true; System.Timers.Timer myTime = new System.Timers.Timer(10000); myTime.Elapsed += CheckQueue; myTime.Enabled = true; string consoleInput = Console.ReadLine(); while (consoleInput != "quit") { if (consoleInput.ToLower() == "clear") { Console.Clear(); } else if (consoleInput.ToLower() == "stats") { Console.WriteLine(""); Console.WriteLine("-------Stats-------"); Console.WriteLine("Uptime: " + (DateTime.Now - startTime)); Console.WriteLine("Tracks Added: " + tracksAdded); } consoleInput = Console.ReadLine(); } }
private IITFileOrCDTrack GetITTFileOrCDTrackFromWorkingTrack(WorkingTrack wt) { iTunes = new iTunesAppClass(); mainLibrary = iTunes.LibraryPlaylist; tracks = mainLibrary.Tracks; IITFileOrCDTrack track = tracks[wt.Position.Value] as IITFileOrCDTrack; return(track); }
public static void iTunesExport(string FilePath) { iTunesAppClass iTunes = new iTunesAppClass(); //iTunesApp iTunes = new iTunesApp(); IITLibraryPlaylist Tracks = iTunes.LibraryPlaylist; var AddVideo = Tracks.AddFile(FilePath); do { } while (AddVideo.InProgress == true); Marshal.FinalReleaseComObject(iTunes); }
public SimilarArtistController(SimilarArtistView view) { model = new LastFMModel(); itunes = new iTunesAppClass(); libraryPlaylist = itunes.LibraryPlaylist; similarArtists = new Queue<string>(); artistTrackCount = new Dictionary<string, int>(); artistTracks = new Dictionary<string, Queue<string>>(); missingTracks = new List<string>(); playlistSize = 0; this.view = view; }
public bool Load() { try { _mainLibrary = _appClass.LibraryPlaylist; _tracks = _mainLibrary.Tracks; CurrentTrackIndex = 0; return true; } catch (Exception exception) { //TODO: Log exception throw exception; } }
private void iTunesParse() { iTunes = new iTunesAppClass(); mainLibrary = iTunes.LibraryPlaylist; tracks = mainLibrary.Tracks; IITFileOrCDTrack track; numTracks = tracks.Count; totalTracks = tracks.Count; OverallTotal += tracks.Count; //files = new Dictionary<string, int>(); TreeNode root = new TreeNode("iTunes"); TreeNode node = root; while (numTracks != 0) { OverallPosition++; track = tracks[numTracks] as IITFileOrCDTrack; //track.UpdateInfoFromFile(); if (track != null) { if (track.Location != null) { if (track.Location.StartsWith(FileRoot)) { //files.Add(track.Location, numTracks); if (!collection.ContainsKey(track.Location.ToLower())) { collection.Add(track.Location.ToLower(), WorkingTrackFromIITFileOrCDTrack(track, numTracks)); } } } } backgroundWorker1.ReportProgress((OverallPosition / OverallTotal) * 100); numTracks--; } }
public static IITTrack[] GetCommentedTracks(this IITLibraryPlaylist self) { ArgumentValidator.Validate(self); var ret = new List <IITTrack>(); //モックオブジェクトのGetEnumerator が実行されるように foreach を使用して要素を取得する foreach (IITTrack track in self.Tracks) { ret.Add(track); } return(ret .Where(x => x.Comment != null) .Where(x => string.IsNullOrEmpty(x.Comment.Trim()) == false) .ToArray()); }
public void RenameX() { iTunesAppClass itunes = new iTunesAppClass(); IITLibraryPlaylist playlist = itunes.LibraryPlaylist; IITTrackCollection tracks = playlist.Tracks; foreach (IITTrack track in tracks) { if ((track != null) && (track.Album != null) && track.Album.Equals("Sheer Heart Attack") && track.Artist.Equals("Queen")) { // 07 - Lenny Kravitz - Mr. Cab Driver (1989) string[] parts = track.Name.Split('-'); if (parts.Length == 2) { Console.WriteLine("... " + track.Name); int trackNumber = Int32.Parse(parts[0].Trim()); string name = parts[1].Trim(); track.Comment = track.Name; if (trackNumber > 0) { track.TrackNumber = trackNumber; } if (!String.IsNullOrEmpty(name)) { track.Name = name; } } //int index = track.Name.IndexOf('('); //if (index > 0) //{ // track.Name = track.Name.Substring(0, index - 1).Trim(); //} } } }
public void RenameTop500() { iTunesAppClass itunes = new iTunesAppClass(); IITLibraryPlaylist playlist = itunes.LibraryPlaylist; IITTrackCollection tracks = playlist.Tracks; foreach (IITTrack track in tracks) { if ((track != null) && (track.Album != null) && track.Album.Equals("Top 500 Rock")) { // 003 - Derek and the Dominos - Layla string[] parts = track.Name.Split('-'); if (parts.Length == 3) { Console.WriteLine("... " + track.Name); int trackNumber = Int32.Parse(parts[0].Trim()); string artist = parts[1].Trim(); string name = parts[2].Trim(); track.Comment = track.Name; if (trackNumber > 0) { track.TrackNumber = trackNumber; } if (!String.IsNullOrEmpty(artist)) { track.Artist = artist; } if (!String.IsNullOrEmpty(name)) { track.Name = name; } } } } }
private void button12_Click(object sender, EventArgs e) { iTunes = new iTunesAppClass(); mainLibrary = iTunes.LibraryPlaylist; tracks = mainLibrary.Tracks; var count = tracks.Count; var sb = new StringBuilder(); for (int i = 1; i < tracks.Count + 1; i++) { IITFileOrCDTrack track = tracks[i] as IITFileOrCDTrack; if (track != null) { if (track.Location != null) { if (track.Location.StartsWith(FileRoot)) { sb.AppendFormat("{0}\t{1}\t{2}\t{3}\t{4}", track.Artist, track.Album, track.Name, track.Location, track.Rating); sb.Append(Environment.NewLine); } } } } textBox1.Text = sb.ToString(); //foreach (WorkingTrack wt in collection.Values) //{ // if (wt.isIniTunes) // { // sb.AppendFormat("{0}\t{1}\t{2}\t{3}\t{4}", wt.iTunesArtist, wt.iTunesAlbum, wt.iTunesName, wt.iTunesLocation, wt.iTunesRating); // sb.Append(Environment.NewLine); // } //} File.WriteAllText("ratings.txt", sb.ToString()); System.Diagnostics.Process.Start("ratings.txt"); }
private void SetPlayCount(IDictionary <string, int> playcountByArtist, string playlistName) { iTunesApp itunes = new iTunesApp(); IITLibraryPlaylist mainLibrary = itunes.LibraryPlaylist; IITPlaylist playlist = itunes.LibrarySource.Playlists.GetPlaylist(playlistName); IITTrackCollection tracks = playlist.Tracks; for (int currTrackIndex = 1; currTrackIndex <= tracks.Count; currTrackIndex++) { IITTrack fileTrack = tracks[currTrackIndex]; if (playcountByArtist.ContainsKey(fileTrack.Artist)) { fileTrack.PlayedCount = playcountByArtist[fileTrack.Artist]; } else { Console.WriteLine("Skipped: {0} - {1}", fileTrack.Artist, fileTrack.Name); } } }
private void AllProps(iTunesAppClass itunes) { bool acmpEnabled = itunes.AppCommandMessageProcessingEnabled; IITEncoder encoder = itunes.CurrentEncoder; IITEQPreset eqPreset = itunes.CurrentEQPreset; IITPlaylist playlist = itunes.CurrentPlaylist; string streamTitle = itunes.CurrentStreamTitle; string streamURL = itunes.CurrentStreamURL; IITTrack track = itunes.CurrentTrack; IITVisual visual = itunes.CurrentVisual; IITEncoderCollection encoders = itunes.Encoders; bool eqEnabled = itunes.EQEnabled; IITEQPresetCollection eqPresets = itunes.EQPresets; // this always seems to raise a COM exception, whether playing or stopped... //IITWindow eqWindow = itunes.EQWindow; bool fgOnDialog = itunes.ForceToForegroundOnDialog; bool fsVisuals = itunes.FullScreenVisuals; IITLibraryPlaylist libPlaylist = itunes.LibraryPlaylist; IITSource libSource = itunes.LibrarySource; string libXmlPath = itunes.LibraryXMLPath; bool mute = itunes.Mute; // this will raise a COM exception when iTunes first started //int position = itunes.PlayerPosition; ITPlayerState state = itunes.PlayerState; IITTrackCollection selectedTracks = itunes.SelectedTracks; int volume = itunes.SoundVolume; bool volEnabled = itunes.SoundVolumeControlEnabled; IITSourceCollection sources = itunes.Sources; string version = itunes.Version; IITVisualCollection visuals = itunes.Visuals; bool visualsEnabled = itunes.VisualsEnabled; ITVisualSize visualSize = itunes.VisualSize; IITWindowCollection windows = itunes.Windows; }
public void Run(string playlistName) { iTunesApp itunes = new iTunesApp(); IITLibraryPlaylist mainLibrary = itunes.LibraryPlaylist; IITPlaylist playlist = itunes.LibrarySource.Playlists.GetPlaylist(playlistName); IITTrackCollection tracks = playlist.Tracks; string csvFilePath = GetFullCsvFilePath(playlistName); if (CheckIfUserWantsToAbort(csvFilePath)) { return; } using (StreamWriter csvFile = new StreamWriter(csvFilePath)) { for (int currTrackIndex = 1; currTrackIndex <= tracks.Count; currTrackIndex++) { IITTrack fileTrack = tracks[currTrackIndex]; Console.WriteLine("{0},{1},{2},{3}", fileTrack.Artist, fileTrack.TrackNumber, fileTrack.Name, fileTrack.PlayedCount); csvFile.WriteLine("\"{0}\",{1},\"{2}\",{3}", fileTrack.Artist, fileTrack.TrackNumber, fileTrack.Name, fileTrack.PlayedCount); } } }
private void timerUIUpdater_Tick(object sender, EventArgs e) { if (!_inStarButton) { lblTrackName.Focus(); } IITTrack track = null; try { track = _itunes.CurrentTrack as IITTrack; } catch { try { NewITunesAppClass(); } catch { return; } } if (track == null) { return; } try { switch (_timerOp) { case TimerOperation.LookForDuplicates: _timerOp = TimerOperation.CheckForNewTrack; iTunesApp itunes = new iTunesApp(); IITLibraryPlaylist library = itunes.LibraryPlaylist; int i = library.Tracks.Count; var curname = track.Name.ToLower(); var curartist = track.Artist.ToLower(); var curfile = track.Kind == ITTrackKind.ITTrackKindFile ? ((dynamic)track).Location : ""; foreach (IITTrack t in library.Tracks) { var tname = t.Name.ToLower(); var tartist = t.Artist.ToLower(); var tfile = t.Kind == ITTrackKind.ITTrackKindFile ? ((dynamic)t).Location : ""; if ((tname == curname || tname.Contains(curname) || curname.Contains(tname)) && (tartist == curartist || tartist.Contains(curartist) || curartist.Contains(tartist)) && curfile != tfile) { var dupform = new DuplicateTrack(BackgroundImage, track, t); dupform.ShowDialog(); } } break; default: // Get the location and size of the iTunes window. var processes = Process.GetProcessesByName("iTunes"); if (processes.Length == 0) { return; } var process = processes[0]; var title = process.MainWindowTitle; if (title.ToUpper() != "MINIPLAYER") { Visible = false; return; } Visible = true; var winhandle = process.MainWindowHandle; var rect = new Rectangle(); GetWindowRect(winhandle, ref rect); Point location = rect.Location; Size size = new Size(rect.Width - rect.X, rect.Height - rect.Y); Location = new Point(location.X, location.Y + size.Height); // Set the size of my window to sit underneath the iTunes window. Size = new Size(size.Width, Size.Height); // Adjust the font size as needed to get the track name to fit properly. float stringwidth; using (var gfx = lblTrackName.CreateGraphics()) { stringwidth = gfx.MeasureString(lblTrackName.Text, lblTrackName.Font).Width; } if (stringwidth + lblTrackName.Left > Width) { lblTrackName.Font = new Font(lblTrackName.Font.FontFamily, lblTrackName.Font.Size - 0.1F); } else if (lblTrackName.Font.Size < 21.75 && stringwidth + lblTrackName.Left + 5 < Width) { lblTrackName.Font = new Font(lblTrackName.Font.FontFamily, lblTrackName.Font.Size + 0.1F); } // Get the currently playing track. if (!string.IsNullOrEmpty(_curTrackPath) && string.Compare(_curTrackPath, track.Artist + "/" + track.Album + "/" + track.Name, StringComparison.OrdinalIgnoreCase) == 0) { return; } //**** //**** If we get here, there was a track change since the last timer event. //**** _timerOp = TimerOperation.LookForDuplicates; // Set the current track path. _curTrackPath = track.Artist + "/" + track.Album + "/" + track.Name; // Update the track info lblTrackName.Text = track.Name; lblArtist.Text = track.Artist; lblAlbum.Text = track.Album; lblTrackName.Visible = lblArtist.Visible = lblAlbum.Visible = true; SetStars(track.Rating, lblTrackName.ForeColor); _curRating = track.Rating; // Get the artwork. IITArtworkCollection artcollection = track.Artwork; if (artcollection == null || artcollection.Count < 1) { return; } IITArtwork art = artcollection[1]; // Save the artwork to a temporary file. string filename; switch (art.Format) { case ITArtworkFormat.ITArtworkFormatJPEG: filename = "temp.jpg"; break; case ITArtworkFormat.ITArtworkFormatPNG: filename = "temp.png"; break; default: filename = "temp.bmp"; break; } filename = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\" + filename; art.SaveArtworkToFile(filename); Color darkest = Color.Black, lightest = Color.White; int avgR, avgG, avgB; using (Image img = Image.FromFile(filename)) { using (var img2 = new Bitmap(img, new Size(10, 10))) { int darkestindex = darkest.R + darkest.G + darkest.B; int lightestindex = lightest.R + lightest.G + lightest.B; int totR = 0, totG = 0, totB = 0; for (int y = 0; y < 10; ++y) { for (int x = 0; x < 10; ++x) { var color = img2.GetPixel(x, y); int index = color.R + color.G + color.B; totR += color.R; totG += color.G; totB += color.B; if (index < darkestindex) { darkestindex = index; darkest = color; } if (index > lightestindex) { lightestindex = index; lightest = color; } } } avgR = (int)Math.Round(totR / 100F); avgG = (int)Math.Round(totG / 100F); avgB = (int)Math.Round(totB / 100F); } using (var img2 = new Bitmap(img, new Size(50, 50))) { for (int x = 0; x < 50; ++x) { int totR = 0, totG = 0, totB = 0; for (int y = 0; y < 50; ++y) { var color = img2.GetPixel(x, y); totR += color.R; totG += color.G; totB += color.B; } Color c = Color.FromArgb(160, (int)Math.Round(totR / 50F), (int)Math.Round(totG / 50F), (int)Math.Round(totB / 50F)); for (int y = 0; y < 50; ++y) { img2.SetPixel(x, y, c); } } BackgroundImage = new Bitmap(img2); } } Color forecolor = Color.FromArgb(Math.Min(Math.Max(0, 255 - avgR), 255), Math.Min(Math.Max(0, 255 - avgG), 255), Math.Min(Math.Max(0, 255 - avgB), 255)); Color backcolor = Color.FromArgb(Math.Min(Math.Max(0, avgR), 255), Math.Min(Math.Max(0, avgG), 255), Math.Min(Math.Max(0, avgB), 255)); if (ColorDist(forecolor, backcolor) < 210) { forecolor = ColorDist(backcolor, lightest) < ColorDist(backcolor, darkest) ? darkest : lightest; } //lblTrackName.OutlineColor = lightest; lblTrackName.ForeColor = lblAlbum.ForeColor = lblArtist.ForeColor = forecolor; foreach (var btn in _starsButtons) { btn.ForeColor = forecolor; } BackColor = backcolor; break; } } catch { // do nothing. } }
private void button15_Click(object sender, EventArgs e) { iTunes = new iTunesAppClass(); mainLibrary = iTunes.LibraryPlaylist; tracks = mainLibrary.Tracks; var count = tracks.Count; var sb = new StringBuilder(); for (int i = 1; i < tracks.Count + 1; i++) { IITFileOrCDTrack track = tracks[i] as IITFileOrCDTrack; if (track != null) { if (track.Location != null) { if (track.Location.StartsWith(FileRoot)) { if (string.IsNullOrWhiteSpace(track.Description)) { try { string sortAlbumString = string.Format("{0} {1}", track.Year, track.Album); var fiSong = new FileInfo(track.Location); var artistString = fiSong.Directory.Parent.Name; if (track.SortAlbum != sortAlbumString) { track.SortAlbum = sortAlbumString; } if (string.IsNullOrWhiteSpace(track.Description)) { track.Description = track.Artist; // stick MusicBrainz' Artist info into Description } track.Artist = artistString; track.AlbumArtist = artistString; track.SortAlbumArtist = artistString; // todo: is albumartist null? //if (track.SortArtist != track.AlbumArtist) // track.SortArtist = track.AlbumArtist; sb.AppendLine(track.Location); //track.UpdateInfoFromFile(); } catch (Exception ex) { sb.AppendLine(ex.Message); } } } } } } textBox1.Text = sb.ToString(); }