/// <summary>
        ///   Parses the Parameter Format to retrieve Tags from Filenames.
        /// </summary>
        /// <param name = "parameterFormat"></param>
        public TagFormat(string parameterFormat)
        {
            parameterParts.Clear();

              // Split the given parameters to see, if folders have been specified
              string[] parms = parameterFormat.Split(new[] {'\\'});
              for (int i = 0; i < parms.Length; i++)
              {
            if (!parms[i].StartsWith("<"))
              parms[i] = String.Format("<X>{0}", parms[i]);

            if (!parms[i].EndsWith(">"))
              parms[i] = String.Format("{0}<X>", parms[i]);
              }
              for (int i = parms.Length - 1; i >= 0; i--)
              {
            ParameterPart part = new ParameterPart(parms[i]);
            parameterParts.Add(part);
              }
        }
Esempio n. 2
0
        /// <summary>
        ///   Parses the Parameter Format to retrieve Tags from Filenames.
        /// </summary>
        /// <param name = "parameterFormat"></param>
        public TagFormat(string parameterFormat)
        {
            parameterParts.Clear();

            // Split the given parameters to see, if folders have been specified
            string[] parms = parameterFormat.Split(new[] { '\\' });
            for (int i = 0; i < parms.Length; i++)
            {
                if (!parms[i].StartsWith("<"))
                {
                    parms[i] = String.Format("<X>{0}", parms[i]);
                }

                if (!parms[i].EndsWith(">"))
                {
                    parms[i] = String.Format("{0}<X>", parms[i]);
                }
            }
            for (int i = parms.Length - 1; i >= 0; i--)
            {
                ParameterPart part = new ParameterPart(parms[i]);
                parameterParts.Add(part);
            }
        }
Esempio n. 3
0
        private void ReplaceParametersWithValues(List <ParameterPart> parameters, bool preview)
        {
            List <string> splittedFileValues = new List <string>();

            // Split up the file name
            // We use already the FileName from the Track instance, which might be already modified by the user.
            string file;

            if (preview)
            {
                file = String.Format(@"{0}\{1}", Path.GetDirectoryName(trackPreview.FullFileName),
                                     Path.GetFileNameWithoutExtension(trackPreview.FullFileName));
            }
            else
            {
                file = String.Format(@"{0}\{1}", Path.GetDirectoryName(track.FullFileName),
                                     Path.GetFileNameWithoutExtension(track.FileName));
            }

            string[] fileArray = file.Split(new[] { '\\' });

            // Now set Upper Bound depending on the length of parameters and file
            int upperBound;

            if (parameters.Count >= fileArray.Length)
            {
                upperBound = fileArray.Length - 1;
            }
            else
            {
                upperBound = parameters.Count - 1;
            }

            // Now loop through the delimiters and assign files
            for (int i = 0; i <= upperBound; i++)
            {
                ParameterPart parameterpart = parameters[i];
                string[]      delims        = parameterpart.Delimiters;
                List <string> parms         = parameterpart.Parameters;

                // Set the part of the File to Process
                string filePart = fileArray[fileArray.GetUpperBound(0) - i];
                splittedFileValues.Clear();

                int upperBoundDelims = delims.GetUpperBound(0);
                for (int j = 0; j <= upperBoundDelims; j++)
                {
                    if ((j == upperBoundDelims) | (delims[j] != ""))
                    {
                        if (filePart.IndexOf(delims[j]) == 0 && j == upperBoundDelims)
                        {
                            splittedFileValues.Add(filePart);
                            break;
                        }

                        int delimIndex = filePart.IndexOf(delims[j]);
                        if (delimIndex > -1)
                        {
                            splittedFileValues.Add(filePart.Substring(0, filePart.IndexOf(delims[j])));
                            filePart = filePart.Substring(filePart.IndexOf(delims[j]) + delims[j].Length);
                        }
                    }
                }

                int index = -1;
                // Now we need to Update the Tag Values
                foreach (string parm in parms)
                {
                    index++;
                    switch (parm)
                    {
                    case "<A>":
                        if (preview)
                        {
                            trackPreview.Artist = splittedFileValues[index];
                        }
                        else
                        {
                            track.Artist = splittedFileValues[index];
                        }
                        break;

                    case "<T>":
                        if (preview)
                        {
                            trackPreview.Title = splittedFileValues[index];
                        }
                        else
                        {
                            track.Title = splittedFileValues[index];
                        }
                        break;

                    case "<B>":
                        if (preview)
                        {
                            trackPreview.Album = splittedFileValues[index];
                        }
                        else
                        {
                            track.Album = splittedFileValues[index];
                        }
                        break;

                    case "<Y>":
                        if (preview)
                        {
                            trackPreview.Year = splittedFileValues[index];
                        }
                        else
                        {
                            track.Year = Convert.ToInt32(splittedFileValues[index]);
                        }
                        break;

                    case "<K>":
                        if (preview)
                        {
                            trackPreview.Track = splittedFileValues[index];
                        }
                        else
                        {
                            track.TrackNumber = Convert.ToUInt32(splittedFileValues[index]);
                        }
                        break;

                    case "<k>":
                        if (preview)
                        {
                            trackPreview.NumTrack = splittedFileValues[index];
                        }
                        else
                        {
                            track.TrackCount = Convert.ToUInt32(splittedFileValues[index]);
                        }
                        break;

                    case "<D>":
                        if (preview)
                        {
                            trackPreview.Disc = splittedFileValues[index];
                        }
                        else
                        {
                            track.DiscNumber = Convert.ToUInt32(splittedFileValues[index]);
                        }
                        break;

                    case "<d>":
                        if (preview)
                        {
                            trackPreview.NumDisc = splittedFileValues[index];
                        }
                        else
                        {
                            track.DiscCount = Convert.ToUInt32(splittedFileValues[index]);
                        }
                        break;

                    case "<G>":
                        if (preview)
                        {
                            trackPreview.Genre = splittedFileValues[index];
                        }
                        else
                        {
                            track.Genre = splittedFileValues[index];
                        }
                        break;

                    case "<O>":
                        if (preview)
                        {
                            trackPreview.AlbumArtist = splittedFileValues[index];
                        }
                        else
                        {
                            track.AlbumArtist = splittedFileValues[index];
                        }
                        break;

                    case "<C>":
                        if (preview)
                        {
                            trackPreview.Comment = splittedFileValues[index];
                        }
                        else
                        {
                            track.Comment = splittedFileValues[index];
                        }
                        break;

                    case "<N>":
                        if (preview)
                        {
                            trackPreview.Conductor = splittedFileValues[index];
                        }
                        else
                        {
                            track.Conductor = splittedFileValues[index];
                        }
                        break;

                    case "<R>":
                        if (preview)
                        {
                            trackPreview.Composer = splittedFileValues[index];
                        }
                        else
                        {
                            track.Composer = splittedFileValues[index];
                        }
                        break;

                    case "<U>":
                        if (preview)
                        {
                            trackPreview.Grouping = splittedFileValues[index];
                        }
                        else
                        {
                            track.Grouping = splittedFileValues[index];
                        }
                        break;

                    case "<S>":
                        if (preview)
                        {
                            trackPreview.SubTitle = splittedFileValues[index];
                        }
                        else
                        {
                            track.SubTitle = splittedFileValues[index];
                        }
                        break;

                    case "<M>":
                        if (preview)
                        {
                            trackPreview.Interpreter = splittedFileValues[index];
                        }
                        else
                        {
                            track.Interpreter = splittedFileValues[index];
                        }
                        break;

                    case "<E>":
                        if (preview)
                        {
                            trackPreview.BPM = splittedFileValues[index];
                        }
                        else
                        {
                            track.BPM = Convert.ToInt32(splittedFileValues[index]);
                        }
                        break;

                    case "<X>":
                        // ignore it
                        break;
                    }
                }
            }
        }