DiscordRadioBot/Classes/YoutubeSearchEngine.cs
/// <summary>
/// Method used to treat the title of the music video, trying to remove unecessary 
/// stuff that isn't really part of the Author - Song Name format.
/// </summary>
/// <param name="result"> The instance of the YouTube SearchResult. </param>
/// <returns></returns>
Method used to treat the title of the music video, trying to remove unecessary
stuff that isn't really part of the Author - Song Name format.
Method used to treat the title of the music video trying to remove unecessary stuff that isn ' t really part of the Author - Song Name format .
private string ParseVideoTitle(SearchResult result)
        {
            string videoTitle1, videoTitle2, videoTitle3, videoTitle4, videoTitle5;
            #region Counting the amount of special chars in the title.
            int hifenCount = 0;
            int parentesisCount = 0;
            int squareBracketsCount = 0;
            int horizontalBarCount = 0;
            foreach(char character in result.Snippet.Title)
            {
                if(character == '-')
                {
                    hifenCount++;
                }
                else if(character == '(')
                {
                    parentesisCount++;
                }
                else if(character == '[')
                {
                    squareBracketsCount++;
                }
                else if(character == '|')
                {
                    horizontalBarCount++;
                }
            }
            #endregion
            videoTitle1 = result.Snippet.Title;
            int hifenLastIndex = videoTitle1.LastIndexOf('-');
            videoTitle2 = videoTitle1.Contains('-') && hifenCount >= 2 ? videoTitle1.Substring(0, hifenLastIndex) : videoTitle1;
            videoTitle3 = videoTitle2;
            int squareBracketsFirstIndex = videoTitle3.IndexOf('[');
            videoTitle4 = videoTitle3.Contains('[') && squareBracketsFirstIndex >= 5 ? videoTitle3.Substring(0, squareBracketsFirstIndex) : videoTitle3;
            int horizontalBarFirstIndex = result.Snippet.Title.IndexOf('|');
            videoTitle5 = videoTitle4.Contains('|') && horizontalBarFirstIndex >= 5 ? videoTitle4.Substring(0, horizontalBarFirstIndex) : videoTitle4;
            videoTitle5 = videoTitle5[videoTitle5.Length - 1] == ' ' ? videoTitle5.Remove(videoTitle5.Length - 1) : videoTitle5;
            return videoTitle5;
        }
private string ParseVideoTitle ( SearchResult result ) { string videoTitle1 , videoTitle2 , videoTitle3 , videoTitle4 , videoTitle5 ; region  Counting the amount of special chars in the title. int hifenCount = 0 ; int parentesisCount = 0 ; int squareBracketsCount = 0 ; int horizontalBarCount = 0 ; foreach ( char character in result . Snippet . Title ) { if ( character == ' ' ) { hifenCount ++ ; } else if ( character == ' ' ) { parentesisCount ++ ; } else if ( character == ' ' ) { squareBracketsCount ++ ; } else if ( character == ' ' ) { horizontalBarCount ++ ; } } endregion videoTitle1 = result . Snippet . Title ; int hifenLastIndex = videoTitle1 . LastIndexOf ( ' ' ) ; videoTitle2 = videoTitle1 . Contains ( ' ' ) && hifenCount >= 2 ? videoTitle1 . Substring ( 0 , hifenLastIndex ) : videoTitle1 ; videoTitle3 = videoTitle2 ; int squareBracketsFirstIndex = videoTitle3 . IndexOf ( ' ' ) ; videoTitle4 = videoTitle3 . Contains ( ' ' ) && squareBracketsFirstIndex >= 5 ? videoTitle3 . Substring ( 0 , squareBracketsFirstIndex ) : videoTitle3 ; int horizontalBarFirstIndex = result . Snippet . Title . IndexOf ( ' ' ) ; videoTitle5 = videoTitle4 . Contains ( ' ' ) && horizontalBarFirstIndex >= 5 ? videoTitle4 . Substring ( 0 , horizontalBarFirstIndex ) : videoTitle4 ; videoTitle5 = videoTitle5 [ videoTitle5 . Length - 1 ] == ' ' ? videoTitle5 . Remove ( videoTitle5 . Length - 1 ) : videoTitle5 ; return videoTitle5 ; }
Method used to treat the title of the music video, trying to remove unecessary
stuff that isn't really part of the Author - Song Name format.
Method used to treat the title of the music video trying to remove unecessary stuff that isn ' t really part of the Author - Song Name format .
/* TODO: Make this whole method better. Maybe using LINQ but I got to learn how 
             * to use it first. Theres also some other special characters that appear very 
             * rarely that would be nice to remove from the Title. */ //int parentesisLastIndex = videoTitle2.LastIndexOf('('); //videoTitle3 = videoTitle2.Contains('(') && (parentesisCount > 0 && parentesisLastIndex >= 5) ? videoTitle2.Substring(0, parentesisLastIndex) : videoTitle2;
None
result
SearchResult
The instance of the YouTube SearchResult.
The instance of the YouTube SearchResult .