private async void PopulateVideoInfo()
        {
            try
            {
                
                Dictionary<string, string> info = await YTDownload.GetVideoDetails(id);
                if (info.Count == 0)
                {
                    SetErrorState(true);
                    return;
                }
                if(report)
                    HistoryManager.AddNewEntry(new HistoryEntry(info["thumbSmall"], info["title"], info["author"], id));
                if (_outputFormat == Settings.PossibleOutputFormats.FORMAT_MP3 && Settings.GetBoolSettingValueForKey(Settings.PossibleSettingsBool.SETTING_PARSE_TAGS))
                    try
                    {
                        suggestions = TagParser.AttemptToParseTags(info["title"], info["details"], "", info["author"]);
                        if (suggestions.suggestedAuthor != "")
                            tagArtist = suggestions.suggestedAuthor;
                        else
                            tagArtist = info["author"];
                        if (suggestions.suggestedTitle != "")
                            tagTitle = suggestions.suggestedTitle;
                    }
                    catch (Exception exce)
                    {
                        Debug.WriteLine(exce.Message);
                    }
                else
                    suggestions = new SuggestedTagsPackage();

                // Use dispatcher only to interact with the UI , putting the async method in there will block UI thread.
                // Info is obtained in the line above and populated on the UI thread.
                //Data loaded , 1/2 steps
                await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                    {
                        VideoThumb.Source = new BitmapImage(new Uri(info["thumbSmall"]));
                        VideoTitle.Text = info["title"];
                        VideoAuthor.Text = info["author"];
                        thumbUrl = info["thumbHigh"];
                        if (Settings.GetBoolSettingValueForKey(Settings.PossibleSettingsBool.SETTING_AUTO_COVER))
                            AlbumCoverPath = thumbUrl;

                        LoadingInfo.Visibility = Visibility.Collapsed;
                        ProgressYoutubeExtraction.Visibility = Visibility.Visible;
                    });


                await Task.Run(() =>
                    {
                        PopulateVideoDownloadInfo();
                    });                         
            }
            catch(Exception exc)
            {
                Debug.WriteLine(exc.Message);
            }
        }
        public VideoItem(string id,string origin = "",bool report = false) //origin as for playlist title
        {
            InitializeComponent();

            this.id = id;
            this.origin = origin;
            this.report = report;
            outputFormat = Settings.GetPrefferedOutputFormat();
            tagAlbum = origin;
            suggestions = new SuggestedTagsPackage();
            CheckTrimRemovalButtons();
            Task.Run(() =>
            {
                PopulateVideoInfo();
            });

        }
        public VideoItem(SearchItem item) // from search
        {
            InitializeComponent();

            id = item.id;
            origin = "";
            tagAlbum = "";
            report = false;
            downloadUrl = item.downloadUrl;
            outputFormat = Settings.GetPrefferedOutputFormat();

            title = item.title;
            desc = item.desc;

            ProgressYoutubeExtraction.Visibility = Visibility.Visible;

            suggestions = new SuggestedTagsPackage();
            CheckTrimRemovalButtons();
            Task.Run(async () =>
            {
                if(downloadUrl == null)
                    PopulateVideoDownloadInfo();
                await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                {
                    VideoThumb.Source = new BitmapImage(new Uri(item.thumbUrl));
                    VideoTitle.Text = title;
                    VideoAuthor.Text = item.author;

                    thumbUrl = item.thumbDownloadUrl;
                    if (Settings.GetBoolSettingValueForKey(Settings.PossibleSettingsBool.SETTING_AUTO_COVER))
                        AlbumCoverPath = thumbUrl;
                    LoadingInfo.Visibility = Visibility.Collapsed;

                });
            });
            if (_outputFormat != Settings.PossibleOutputFormats.FORMAT_MP3 ||
                !Settings.GetBoolSettingValueForKey(Settings.PossibleSettingsBool.SETTING_PARSE_TAGS)) return;
            try
            {
                suggestions = TagParser.AttemptToParseTags(title, desc, "", item.author);
                tagArtist = suggestions.suggestedAuthor != "" ? suggestions.suggestedAuthor : item.author;
                if (suggestions.suggestedTitle != "")
                    tagTitle = suggestions.suggestedTitle;
            }
            catch (Exception exce)
            {
                Debug.WriteLine(exce.Message);
            }
        }
Example #4
0
        public static SuggestedTagsPackage AttemptToParseTags(string title,string details,string tags,string vidAuthor)
        {
            title = Purify(title);
            details = Purify(details);
            //Debug.WriteLine(details);

            List<string> titles = new List<string>();
            List<string> authors = new List<string>();
            string suggTitle ="", suggArtist = "";
            // Do the same with title - separate strings
            foreach (char separator in separators)
            {
                var lines = title.Split(separator);
                if (lines.Length >= 2)
                    foreach (string part in lines)
                    {
                        if(IsTitlePartValid(part,vidAuthor)) titles.Add(part);
                    }
            }

            // Separate lines in details
            foreach (string line in details.Split("\n".ToCharArray(),StringSplitOptions.RemoveEmptyEntries))
            {
                foreach(char separator in separators)
                {
                    var lines = line.Split(separator);
                    bool foundKeywordTitle = false,foundKeywordArtist = false;
                    if (lines.Length >= 2)
                        foreach (string part in lines)
                        {
                            if (!foundKeywordTitle && !foundKeywordArtist)
                            {
                                foundKeywordArtist = IsArtistWord(part);
                                if (!foundKeywordArtist)
                                    foundKeywordTitle = (bool)IsTitleWord(part);
                            }

                            if (foundKeywordTitle && IsTitlePartValid(part,vidAuthor)) titles.Add(part);
                            if (foundKeywordArtist) authors.Add(part);
                        }
                }
            }

            for (int i = 0; i < titles.Count; i++)
            {
                if (titles[i].Length < 4 || string.IsNullOrWhiteSpace(titles[i]) || !ContainsLetters(titles[i]))
                    titles.RemoveAt(i);
                else
                {
                    titles[i] = titles[i].Trim();
                    if (title.Contains(titles[i]))
                        suggTitle = titles[i];

                }
            }
            for (int i = 0; i < authors.Count; i++)
            {
                authors[i] = authors[i].Trim();
                if (title.Contains(authors[i]))
                    suggArtist = authors[i];
            }
            authors.Add(vidAuthor);
            authors = authors.Distinct().ToList();
            titles = titles.Distinct().ToList(); // clear duplicates
            SuggestedTagsPackage pkg = new SuggestedTagsPackage();
            pkg.titles = titles;
            pkg.authors = authors;
            pkg.suggestedTitle = suggTitle;
            pkg.suggestedAuthor = suggArtist;

            return pkg;
        }