//ツイート private void button2_Click(object sender, RoutedEventArgs e) { //iTunes COMのセットアップ iTunesApp iTunes = new iTunesApp(); IITTrack track = iTunes.CurrentTrack; if (iTunes == null) { System.Windows.Forms.MessageBox.Show("iTunesで曲が再生されていません"); return; } //変数の指定 var AlbumName = track.Album; var TrackInfo = track.TrackNumber + " / " + track.TrackCount; var Artist = track.Artist; var TrackName = track.Name; var Ruledline = "│"; var nowplaying = "#nowplaying\n"; IITArtworkCollection artwork = track.Artwork; DateTime dt = DateTime.Now; //ツイート var text = nowplaying + AlbumName + Ruledline + TrackName + Ruledline + Artist + Ruledline + dt; tokens.Statuses.Update(status => text); //お知らせ System.Windows.Forms.MessageBox.Show("実行します。"); }
private void App_OnPlayerPlayingTrackChangedEvent(object sender) { IITTrack track = this.iTunesApplication.CurrentTrack; if (!string.IsNullOrEmpty(track.Artist) && !string.IsNullOrEmpty(track.Name) && string.IsNullOrEmpty(this.iTunesApplication.CurrentStreamTitle)) { if (Globals.SaveAlbumArtwork) { try { IITArtworkCollection artworkCollection = track.Artwork; IITArtwork artwork = artworkCollection[1]; artwork.SaveArtworkToFile(this.DefaultArtworkFilePath); } catch { this.SaveBlankImage(); throw; } } TextHandler.UpdateText(track.Name, track.Artist, track.Album); } else if (!string.IsNullOrEmpty(this.iTunesApplication.CurrentStreamTitle)) { TextHandler.UpdateText(this.iTunesApplication.CurrentStreamTitle); } }
private void GetAlbumArt() { try { iTunesApp app = new iTunesAppClass(); IITArtworkCollection art1 = app.CurrentTrack.Artwork; IITArtwork art2 = art1[1]; art2.SaveArtworkToFile(String.Concat(Environment.CurrentDirectory, @"\Cover.jpg")); Stream r = File.Open(String.Concat(Environment.CurrentDirectory, @"\Cover.jpg"), FileMode.Open); Image temp = Image.FromStream(r); r.Close(); albumArtBox.Image = temp; _imageDirectory = String.Concat(Environment.CurrentDirectory, @"\Cover.jpg"); } catch (Exception) { albumArtBox.Image = Properties.Resources.art; _imageDirectory = String.Concat(Environment.CurrentDirectory, @"\No_Cover.jpg"); } }
private string getArtworkFileNameInternal() { try { if (currentTrack == null) { return(" "); } IITArtworkCollection artworks = currentTrack.Artwork; if (artworks.Count == 0) { return(""); } string suffix; switch (artworks[1].Format) { case ITArtworkFormat.ITArtworkFormatBMP: suffix = ".bmp"; break; case ITArtworkFormat.ITArtworkFormatJPEG: suffix = ".jpg"; break; case ITArtworkFormat.ITArtworkFormatPNG: suffix = ".png"; break; default: suffix = ".jpg"; break; } string filepath = artworkRootPath + replaceInvalidChars(currentTrack.Artist) + " - " + replaceInvalidChars(currentTrack.Album) + suffix; if (!File.Exists(filepath)) { artworks[1].SaveArtworkToFile(filepath); } return(filepath); } catch (Exception ex) { Console.Write("!"); } return(""); }
private Image GetArtwork(IITArtworkCollection collection) { if (collection.Count == 0) { return(null); } // 1-based index var artwork = collection[1]; var tempPath = Path.GetTempFileName(); artwork.SaveArtworkToFile(tempPath); Image image; using (var tmp = new Bitmap(tempPath)) { image = new Bitmap(tmp); } File.Delete(tempPath); return(image); }
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. } }