Пример #1
0
        public string parseInfo(SongData song)
        {
            var fullRequest = "";
            var artist = song.Artist;
            var album = song.Album;
            var title = song.Title;

            // Remove anything in parenthesis/brackets and all special characters
            string regEx = @"(?<=\()(.*?)(?=\))|(?<=\[)(.*?)(?=\])|(?<=\{)(.*?)(?=\})|[^\w ]";

            // Handle passed parameters
            if (artist != "UNKNOWN")
            {
                artist = Regex.Replace(artist, regEx, "");
                fullRequest += artist;
            }

            if (album != "UNKNOWN" && album != artist)
            {
                album = Regex.Replace(album, regEx, "");
                fullRequest += " " + album;
            }

            if (title != "UNKNOWN" && title != album)
            {
                title = Regex.Replace(title, regEx, "");
                fullRequest += " " + title;
            }

            return fullRequest;
        }
Пример #2
0
        //Never forget to take this out
        public async Task<SongData> getAmazonInfo(SongData song)
        {
            var fullRequest = parseInfo(song);
            var newSong = await getData(song, fullRequest);

            return newSong;
        }
Пример #3
0
        public List<SongData> fileDiag()
        {
            //These variables are string array lists to store song locations.
            var newPaths = new ArrayList();
            var songList = new List<SongData>();

            //Open file dialog to select tracks and add them to the play list
            var open = new OpenFileDialog { Filter = "MP3 File (*.mp3)|*.mp3;", DefaultExt = ".mp3", Multiselect = true };

            //Show open
            Nullable<bool> result = open.ShowDialog();

            //Process open file dialog box result
            if (result != false)
            {
                newPaths.AddRange(open.FileNames); //Saves the full paths
            }

            // Try to convert ArrayList to Object List (SongData)
            foreach (string path in newPaths)
            {
                newSong = new TagLibDataAccesser().getSongTags(path);
                //newSong = await dgHandler.populateDataGrid(newSong);
                songList.Add(newSong);
            }

            return songList;
        }
        ///////////////////////////////////////////////////////
        // TagLib File MetaData Accessor (from string URL Path)
        // - Obtains local file meta-data, assigns UNKNOWN if missing
        //
        // - Uses       SongData newSong = new TagLibDataAccesser().getSongTags({string:path})
        // - Output     New SongData object with updated field values
        ///////////////////////////////////////////////////////
        public SongData getSongTags(string path)
        {
            TagLib.File tagFile = TagLib.File.Create(path);

            uint trackNumber = tagFile.Tag.Track;
            string songTitle = tagFile.Tag.Title;
            string artist = tagFile.Tag.AlbumArtists.FirstOrDefault();
            string albumTitle = tagFile.Tag.Album;
            uint year = tagFile.Tag.Year;
            string genre = tagFile.Tag.Genres.FirstOrDefault();

            // Set Song title to file name, else UNKNOWN
            if (songTitle == null)
                try
                {
                    string editedPath = System.IO.Path.GetFileNameWithoutExtension(path);
                    songTitle = Regex.Replace(editedPath, @"^[\d-]*\s*", "");
                }
                catch
                {
                    songTitle = "Unknown";
                }

            // Set Album name to folder name holding file, else UNKNOWN
            if (albumTitle == null)
                try
                {
                    albumTitle = System.IO.Path.GetFileName(System.IO.Path.GetDirectoryName(path));
                }
                catch
                {
                    //
                }

            // Check for Artist in "Contributing Artists" Meta-Data
            if (artist == null || artist == "")
            {
                artist = tagFile.Tag.JoinedPerformers;
            }
            // If still null, set to UNKNOWN
            if (artist == null || artist == "")
                try
                {
                    artist = System.IO.Path.GetFileName(System.IO.Path.GetDirectoryName(System.IO.Path.GetDirectoryName(path)));
                }
                catch
                {
                    artist = "Unknown";
                }
            if (genre == null) { genre = "Unknown"; }

            // Year will default to 0 as a UINT if unknown

            // Assign data to new SongData object
            var newSongObject = new SongData { Title = songTitle, Artist = artist, Album = albumTitle, Year = (int)year, Genre = genre, FilePath = path};

            return newSongObject;
        }
Пример #5
0
        ///////////////////////////////////////////////////////
        // ProcessDirectory Handler
        // - Processes directory string and handles it (if/then)
        //
        // - Uses       DirectoryHandler k = new DirectoryHandler();
        //              k.processDirectory(path, false);
        // - Output     Handles directory, [Upload to DB {if boolean true}, or add to DataGrid {if boolean false}]
        ///////////////////////////////////////////////////////
        public async Task<List<SongData>> dirDiag(string targetDirectory, List<SongData> songList)
        {

            // Recurse into subdirectories of this directory. 
            string[] subdirectoryEntries = Directory.GetDirectories(targetDirectory);
            foreach (string subdirectory in subdirectoryEntries)
            {
                await dirDiag(subdirectory, songList);
            }

            // Process the list of files found in the directory. (Only grabs .mp3's)
            string[] fileEntries = Directory.GetFiles(targetDirectory, "*.mp3");
            foreach (string filePath in fileEntries)
            {
                newSong = new TagLibDataAccesser().getSongTags(filePath);
                songList.Add(newSong);
            }

            return songList;
        }
Пример #6
0
        public bool checkDup(List<SongData> songList, SongData checkSong)
        {
            var isDup = false;

            if (songList != null)
            {
                // Check if there are duplicates detected in DataGrid by Path
                foreach (SongData song in songList)
                {
                    if (checkSong.FilePath == song.FilePath)
                    {
                        //Log the duplicate!
                        isDup = true;
                        return isDup;
                    }

                    isDup = false;
                }
                return isDup;
            }
            return isDup;
        }
Пример #7
0
        ///////////////////////////////////////////////////////
        // WORKING - KEEP IN MAIN
        // File Drop handler for DataGrid
        // - Process through each file dropped into DataGrid
        ///////////////////////////////////////////////////////
        private async void dgvPlayList_Drop(object sender, DragEventArgs e)
        {
            // Get songs in playlist
            var playlistSongs = getPlaylistSongs();

            if (e.Data.GetDataPresent(DataFormats.FileDrop))
            {
                //These variables are string array lists to store song locations.
                var songList = new List<SongData>();

                var files = (string[])e.Data.GetData(DataFormats.FileDrop);
                foreach (var path in files)
                {
                    newSong = new TagLibDataAccesser().getSongTags(path);
                    songList.Add(newSong);
                }

                if (songList != null)
                {
                    foreach (SongData song in songList)
                    {
                        // Assign path to variable
                        var path = song.FilePath;

                        // Get full request
                        SongData amazonSong = await amazonAccesser.getAmazonInfo(song);

                        // Set amazonSong Path
                        amazonSong.FilePath = path;

                        // Add song to master List
                        //songList.Add(amazonSong);

                        // Check for duplicate values
                        bool isDup = dupCheck.checkDup(playlistSongs, amazonSong);

                        if (!isDup)
                        {
                            // Add AmazonSong to playlist
                            dgvPlayList.Items.Add(amazonSong);
                        }
                    }
                }
                QueueNextSong();
            }
        }
Пример #8
0
 private void setLabels(SongData localObj)
 {
    
     // Assign Song labels
     tbAmazonArtistInfo.Text = localObj.Artist;
     tbAmazonAlbumInfo.Text = localObj.Album;
     tbAmazonTitleInfo.Text = localObj.Title;
     tbAmazonYearInfo.Text = localObj.Year.ToString();
     tbAmazonAsinInfo.Text = localObj.ASIN;
     tbAmazonPriceInfo.Text = localObj.Price;
    
     if (localObj.Artwork != null)
     {
         albumArtPanel.AlbumArtImage = BitmapFrame.Create(new Uri(localObj.Artwork));
     }
 }
Пример #9
0
        public async Task<SongData> getData(SongData newSong, string fullRequest)
        {
            try
            {
                // Instantiate Amazon ProductAdvertisingAPI client
                BasicHttpBinding binding = new BasicHttpBinding(BasicHttpSecurityMode.Transport);
                binding.MaxReceivedMessageSize = int.MaxValue;
                AWSECommerceServicePortTypeClient amazonClient = new AWSECommerceServicePortTypeClient(
                binding,
                new EndpointAddress("https://webservices.amazon.com/onca/soap?Service=AWSECommerceService"));

                // add authentication to the ECS client
                amazonClient.ChannelFactory.Endpoint.Behaviors.Add(new AmazonSigningEndpointBehavior(accessKeyId, secretKey));

                // prepare an ItemSearch request
                ItemSearchRequest request = new ItemSearchRequest();
                request.SearchIndex = "MP3Downloads";
                request.RelationshipType = new string[] { "Tracks" };
                request.ResponseGroup = new string[] { "ItemAttributes", "Images", "Offers", "RelatedItems" };

                request.Keywords = fullRequest;

                ItemSearch itemSearch = new ItemSearch();
                itemSearch.Request = new ItemSearchRequest[] { request };
                itemSearch.AWSAccessKeyId = accessKeyId;
                itemSearch.AssociateTag = "1330-3170-0573";

                // send the ItemSearch request
                ItemSearchResponse response = amazonClient.ItemSearch(itemSearch);

                var item = response.Items[0].Item[0];

                //<ProductTypeName>DOWNLOADABLE_MUSIC_TRACK</ProductTypeName>
                if (response.Items[0].Item[0].ItemAttributes.ProductTypeName == "DOWNLOADABLE_MUSIC_ALBUM")
                {
                    item = response.Items[0].Item[1];
                }

                // if no response to search
                if (item == null)
                {
                    try
                    {
                        // Try new search and remove the album
                        newSong.Album = "UNKNOWN";

                        // Re-iterate over the search method
                        await getData(newSong, fullRequest);
                    }
                    catch
                    {
                        // Removing the album produced no results
                        // Continue forward...
                    }
                }

                // Get year from full Release Date var
                var formatYear = DateTime.Parse(item.ItemAttributes.ReleaseDate).Year;

                newSong.UserID = 1;
                newSong.LocationID = 1;
                newSong.Album = item.RelatedItems[0].RelatedItem[0].Item.ItemAttributes.Title;
                newSong.Artist = item.ItemAttributes.Creator[0].Value;
                newSong.Title = item.ItemAttributes.Title;
                newSong.Year = (int)formatYear;
                newSong.Genre = item.ItemAttributes.Genre;
                newSong.FilePath = "";
                newSong.Duration = (int)item.ItemAttributes.RunningTime.Value;
                newSong.Price = item.Offers.Offer[0].OfferListing[0].Price.FormattedPrice;
                newSong.ASIN = item.ASIN;
                newSong.Artwork = item.LargeImage.URL;

                return newSong;
            }
            catch
            {
                return newSong;
            }
        }