Exemplo n.º 1
0
        public override async void EndOfTrack(SpotifySession session)
        {
            session.PlayerPlay(false);
            wr.Close();

            // Move File
            var dir = downloadPath + escape(downloadingTrack.Album().Name()) + "\\";

            if (!Directory.Exists(dir))
            {
                Directory.CreateDirectory(dir);
            }
            var fileName = dir + escape(GetTrackFullName(downloadingTrack)) + ".mp3";

            if (GetDownloadType() == DownloadType.OVERWRITE && File.Exists(fileName))
            {
                File.Delete(fileName);
            }
            File.Move("downloading", fileName);

            // Tag
            var u = new UltraID3();

            u.Read(fileName);
            u.Artist   = GetTrackArtistsNames(downloadingTrack);
            u.Title    = downloadingTrack.Name();
            u.Album    = downloadingTrack.Album().Name();
            u.TrackNum = (short)downloadingTrack.Index();
            u.Year     = (short)downloadingTrack.Album().Year();

            var imageID = downloadingTrack.Album().Cover(ImageSize.Large);
            var image   = SpotifySharp.Image.Create(session, imageID);

            await WaitForBool(image.IsLoaded);

            var tc  = TypeDescriptor.GetConverter(typeof(Bitmap));
            var bmp = (Bitmap)tc.ConvertFrom(image.Data());

            var pictureFrame = new ID3v23PictureFrame(bmp, PictureTypes.CoverFront, "image", TextEncodingTypes.ISO88591);

            u.ID3v2Tag.Frames.Add(pictureFrame);

            u.Write();

            base.EndOfTrack(session);

            if (OnDownloadProgress != null)
            {
                OnDownloadProgress(100);
            }

            if (OnDownloadComplete != null)
            {
                OnDownloadComplete(true);
            }
        }
Exemplo n.º 2
0
 static void AddAlbumArt(string albumArtPath, UltraID3 u)
 {
     using (Image img = Image.FromFile(albumArtPath))
     {
         ID3FrameCollection myArtworkCollection = u.ID3v2Tag.Frames.GetFrames(MultipleInstanceID3v2FrameTypes.ID3v23Picture);
         ID3v23PictureFrame AlbumArt = new ID3v23PictureFrame(new Bitmap(img), PictureTypes.CoverFront, "", TextEncodingTypes.ISO88591);
         u.ID3v2Tag.Frames.Add(AlbumArt);
         u.Write();
     }
 }
Exemplo n.º 3
0
        private void getAlbumArt()
        {
            ID3FrameCollection frames = ID3tag.ID3v2Tag.Frames.GetFrames(MultipleInstanceID3v2FrameTypes.ID3v23Picture);

            if (frames.Count > 0)
            {
                ID3v23PictureFrame image = (ID3v23PictureFrame)frames[0];
                albumArtPicBox.Image   = image.Picture;
                picDemensionLabel.Text = image.Picture.Width + " x " + image.Picture.Height;
            }
            else
            {
                // no picture
                picDemensionLabel.Text = string.Empty;
            }
        }
Exemplo n.º 4
0
 public void SetCover(Bitmap picture)
 {
     ID3v23PictureFrame pictureFrame = new ID3v23PictureFrame
                                           {
                                               MIMEType = "image/jpeg",
                                               Picture = picture,
                                               PictureType = PictureTypes.CoverFront
                                           };
     id3v2tag.Frames.Remove(CommonID3v2FrameTypes.Picture);
     id3v2tag.Frames.Add(pictureFrame);
 }
Exemplo n.º 5
0
        private void btnDownload_Click(object sender, EventArgs e)
        {
            WebClient client = new WebClient();
            string    finalPath;

            SetEnabled(false);
            SetInfo("Downloading Songs ...");
            totalTracksCount = m_lbxEntries.CheckedItems.Count;
            List <Track> tracks = m_lbxEntries.CheckedItems.Cast <Track>().ToList();

            if (chkBxDownloadPath.Checked)
            {
                finalPath = downloadFolder;
            }
            else
            {
                finalPath = m_Direcotry;
            }

            if (type != SearchType.TRACK)
            {
                finalPath = Path.Combine(finalPath, title);
                if (!System.IO.Directory.Exists(finalPath))
                {
                    System.IO.Directory.CreateDirectory(finalPath);
                }
            }

            ThreadPool.QueueUserWorkItem(
                (_) =>
            {
                foreach (var track in tracks)
                {
                    string fileName = String.Format("{0}.mp3", track.title);
                    foreach (var chr in Path.GetInvalidFileNameChars().Union(Path.GetInvalidPathChars()))
                    {
                        fileName = fileName.Replace("" + chr, "_");
                    }

                    SetInfo("Downloading " + fileName);
                    tracksCount++;

                    tempDownloadFolder = Path.Combine(finalPath, fileName);

                    if (File.Exists(tempDownloadFolder))
                    {
                        if (chkBxSkip.Checked)
                        {
                            continue;
                        }
                        else
                        {
                            File.Delete(tempDownloadFolder);
                        }
                    }

                    // string streamurl = client.DownloadString(new Uri(string.Format("http://api.soundcloud.com/i1/tracks/{0}/streams?client_id={1}", track.id, clientID)));

                    wbClient.DownloadProgressChanged += new DownloadProgressChangedEventHandler(client_DownloadProgressChanged);
                    wbClient.DownloadFileCompleted   += HandleDownloadComplete;

                    var syncObject = new Object();
                    lock (syncObject)
                    {
                        wbClient.DownloadFileAsync(new Uri(track.streamurl), tempDownloadFolder, syncObject);
                        Monitor.Wait(syncObject);
                    }

                    var u = new UltraID3();
                    u.Read(tempDownloadFolder);

                    if (track.artwork_url != null && chkBxImageTags.Checked)
                    {
                        Stream stream = wbClient.OpenRead(track.artwork_url);
                        Bitmap bmp    = new Bitmap(stream);

                        var pictureFrame = new ID3v23PictureFrame(bmp, PictureTypes.CoverFront, "image", TextEncodingTypes.ISO88591);
                        u.ID3v2Tag.Frames.Add(pictureFrame);
                    }

                    string[] splitTitle = null;
                    if (track.title.Contains("-"))
                    {
                        splitTitle = track.title.Split('-');
                        u.Title    = splitTitle[1];
                    }
                    if (chkBxArtistTag.Checked)
                    {
                        if (splitTitle != null)
                        {
                            u.Artist = splitTitle[0];
                        }
                        else
                        {
                            u.Artist = ((User)track.user).username;
                        }
                    }
                    u.Write();
                }

                SetInfo("Finished Downloading!");
                SetEnabled(true);
                SetChecked(false);
                totalTracksCount = 0;
                tracksCount      = 0;
                if (chkBxOpenFolder.Checked)
                {
                    System.Diagnostics.Process.Start("explorer.exe", finalPath);
                }
            });
        }
Exemplo n.º 6
0
        public override async void EndOfTrack(SpotifySession session)
        {
            session.PlayerPlay(false);
            wr.Close();

            // Move File
            string album = downloadingTrack.Album().Name();
            album = filterForFileName(album);

            var dir = downloadPath + album + "\\";
            if (!Directory.Exists(dir))
                Directory.CreateDirectory(dir);

            string song = GetTrackFullName(downloadingTrack);
            song = filterForFileName(song);

            var fileName = dir + song + ".mp3";

            try
            {
                File.Move("downloading", fileName);
                FileInfo fileInfo = new FileInfo(fileName);
                String path = fileInfo.DirectoryName;
            }
            catch (Exception e) {

                File.Delete("downloading");
                LogString("Track deleted because the track already exists! Path: " + fileName + " Track Name:" + SpotifyDownloader.GetTrackFullName(downloadingTrack));
                
                base.EndOfTrack(session);

                if (OnDownloadProgress != null)
                    OnDownloadProgress(100);

                if (OnDownloadComplete != null)
                    OnDownloadComplete();
                
                return;
            }

            try
            {
                // Tag
                var u = new UltraID3();
                //u.GetMPEGTrackInfo();
                u.Read(fileName);
                u.Artist = GetTrackArtistsNames(downloadingTrack);
                u.Title = downloadingTrack.Name();
                u.Album = downloadingTrack.Album().Name();

                var imageID = downloadingTrack.Album().Cover(ImageSize.Large);
                var image = SpotifySharp.Image.Create(session, imageID);
                await WaitForBool(image.IsLoaded);

                var tc = TypeDescriptor.GetConverter(typeof(Bitmap));
                var bmp = (Bitmap)tc.ConvertFrom(image.Data());

                var pictureFrame = new ID3v23PictureFrame(bmp, PictureTypes.CoverFront, "image", TextEncodingTypes.ISO88591);
                u.ID3v2Tag.Frames.Add(pictureFrame);

                u.Write();

                base.EndOfTrack(session);
            }
            catch (Exception e) { };

            LogString("Track downloaded and saved! Path: " + fileName + " Track Name:" + SpotifyDownloader.GetTrackFullName(downloadingTrack));

            if (OnDownloadProgress != null)
                OnDownloadProgress(100);

            if (OnDownloadComplete != null)
                OnDownloadComplete();
        }
Exemplo n.º 7
0
        private void btnDownload_Click(object sender, EventArgs e)
        {
            string finalPath;
            SetEnabled(false);
            SetInfo("Downloading Songs");
            totalTracksCount = m_lbxEntries.CheckedItems.Count;
            var tracks = m_lbxEntries.CheckedItems.Cast<Track>();

            if (chkBxDownloadPath.Checked)
            {
                finalPath = downloadFolder;
            }
            else
            {
                finalPath = m_Direcotry;
            }

            if (type != SearchType.TRACK)
            {
                finalPath = Path.Combine(finalPath, title);
                if (!System.IO.Directory.Exists(finalPath))
                {
                    System.IO.Directory.CreateDirectory(finalPath);
                }
            }

            ThreadPool.QueueUserWorkItem(
                (_) =>
                {
                    foreach (var track in tracks)
                    {
                        string fileName = String.Format("{0}.mp3", track.title);
                        foreach (var chr in Path.GetInvalidFileNameChars().Union(Path.GetInvalidPathChars()))
                        {
                            fileName = fileName.Replace("" + chr, "_");
                        }

                        SetInfo("Downloading " + fileName);
                        tracksCount++;

                        tempDownloadFolder = Path.Combine(finalPath, fileName);

                        if (File.Exists(tempDownloadFolder))
                        {
                            if (chkBxSkip.Checked)
                            {
                                continue;
                            }
                            else
                            {
                                File.Delete(tempDownloadFolder);
                            }
                        }

                        string url = String.Format("{0}/stream.json?client_id={1}", track.uri, clientID);
                        wbClient.DownloadProgressChanged += new DownloadProgressChangedEventHandler(client_DownloadProgressChanged);
                        wbClient.DownloadFileCompleted += HandleDownloadComplete;

                        var syncObject = new Object();
                        lock (syncObject)
                        {
                            wbClient.DownloadFileAsync(new Uri(url), tempDownloadFolder, syncObject);
                            Monitor.Wait(syncObject);
                        }

                        var u = new UltraID3();
                        u.Read(tempDownloadFolder);
                       
                        if (track.artwork_url != null && chkBxImageTags.Checked)
                        {
                            Stream stream = wbClient.OpenRead(track.artwork_url);
                            Bitmap bmp = new Bitmap(stream);

                            var pictureFrame = new ID3v23PictureFrame(bmp, PictureTypes.CoverFront, "image", TextEncodingTypes.ISO88591);
                            u.ID3v2Tag.Frames.Add(pictureFrame);
                        }
                        if (track.title.Contains("-"))
                        {
                            string[] splitTitle = track.title.Split('-');
                            u.Title = splitTitle[1];
                            if (chkBxArtistTag.Checked)
                            {
                                u.Artist = splitTitle[0]; //((User)track.user).username;
                            }
                        }
                        else
                        {
                            u.Title = track.title;
                        }
                        u.Write();
                    }

                    SetInfo("Finished Downloading!");
                    SetEnabled(true);
                    SetChecked(false);
                    totalTracksCount = 0;
                    tracksCount = 0;
                    if (chkBxOpenFolder.Checked)
                    {
                        System.Diagnostics.Process.Start("explorer.exe", finalPath);
                    }
                });
        }
Exemplo n.º 8
0
        public override async void EndOfTrack(SpotifySession session)
        {
            session.PlayerPlay(false);
            wr.Close();

            // Move File
            var dir = downloadPath + escape(downloadingTrack.Album().Name()) + "\\";
            if (!Directory.Exists(dir))
                Directory.CreateDirectory(dir);
            var fileName = dir + escape(GetTrackFullName(downloadingTrack)) + ".mp3";
            if(GetDownloadType() == DownloadType.OVERWRITE && File.Exists(fileName))
                File.Delete(fileName);
            File.Move("downloading", fileName);

            // Tag
            var u = new UltraID3();
            u.Read(fileName);
            u.Artist = GetTrackArtistsNames(downloadingTrack);
            u.Title = downloadingTrack.Name();
            u.Album = downloadingTrack.Album().Name();
            u.TrackNum = (short)downloadingTrack.Index();

            var imageID = downloadingTrack.Album().Cover(ImageSize.Large);
            var image = SpotifySharp.Image.Create(session, imageID);
            await WaitForBool(image.IsLoaded);

            var tc = TypeDescriptor.GetConverter(typeof(Bitmap));
            var bmp = (Bitmap)tc.ConvertFrom(image.Data());

            var pictureFrame = new ID3v23PictureFrame(bmp, PictureTypes.CoverFront, "image", TextEncodingTypes.ISO88591);
            u.ID3v2Tag.Frames.Add(pictureFrame);

            u.Write();

            base.EndOfTrack(session);

            if (OnDownloadProgress != null)
                OnDownloadProgress(100);

            if (OnDownloadComplete != null)
                OnDownloadComplete(true);
        }