Exemplo n.º 1
0
        public MessageForm(string message, int timeout)
        {
            InitializeComponent();

            //Not visible
            this.Opacity = 0.0;
            //Make it so that the text won't go out of bounds horizontally, so the panel has to grow vertically
            lblText.MaximumSize = new Size(pnlText.Width - 15, 0);
            //Set the text
            lblText.Text = message;
            //Enlarge the panel if needed
            FitPanel(pnlText);


            //No active popup forms? set it to default position
            if (MessageFormManager.GetPopupforms().Count == 0)
            {
                //Set the location to the bottom right corner of the user's screen and a little bit above the taskbar
                this.Location = new Point(Screen.GetWorkingArea(this).Width - this.Width - 5, Screen.GetWorkingArea(this).Height - this.Height - 5);
            }
            else
            {
                int alreadyActiveFormCount = MessageFormManager.GetPopupforms().Count;
                //Set the location to the bottom right corner of the user's screen, and above all other active popups
                this.Location = new Point(Screen.GetWorkingArea(this).Width - this.Width - 5, Screen.GetWorkingArea(this).Height - (this.Height * (alreadyActiveFormCount + 1)) - ((alreadyActiveFormCount + 1) * 5));
            }

            this.timeout = timeout;
            //Start the timer that will "slowly" make the form more transparent
            tmrFadein.Start();
        }
Exemplo n.º 2
0
        /// <summary>
        /// Adds a downloadItem to the panel
        /// </summary>
        /// <param name="item"></param>
        /// <param name="pnl"></param>
        public static DownloadItem AddDownloadItem(YoutubeExplode.Models.Video video, Panel pnl)
        {
            try
            {
                DownloadItem toAddItem = new DownloadItem(video);
                //Determines where to place the downloadItem
                int y = 0;
                if (downloadItems.Count > 0)
                {
                    y = downloadItems.Count * downloadItems.Where(itm => !itm.IsDisposed).ToList()[0].Height;
                }

                pnl.Invoke((MethodInvoker)(() =>
                {
                    pnl.Controls.Add(toAddItem);
                }));

                toAddItem.Invoke((MethodInvoker)(() =>
                {
                    toAddItem.Location = new Point(toAddItem.Location.X, y);
                }));

                downloadItems.Add(toAddItem);
                return(toAddItem);
            }
            catch (Exception)
            {
                MessageFormManager.MakeMessagePopup("Something went wrong!", "Could not find a video with that youtube url!\r\nPlease try again.", 5);
            }
            return(null);
        }
Exemplo n.º 3
0
        private static async void AddDownloadItems(string url, Panel pnl)
        {
            try
            {
                YoutubeClient client = new YoutubeClient();

                //Get the playlist object from the id
                YoutubeExplode.Models.Playlist playList = await client.GetPlaylistAsync(url);

                //We now have a playlist with every video from that playlist. (.Videos)
                foreach (YoutubeExplode.Models.Video video in playList.Videos)
                {
                    DownloadItem item = new DownloadItem(video);
                    //Determines where to place the downloadItem
                    int y = 0;
                    if (downloadItems.Count > 0)
                    {
                        y = downloadItems[downloadItems.Count - 1].Location.Y + item.Height;
                    }


                    pnl.Controls.Add(item);
                    item.Location = new Point(item.Location.X, y);
                    downloadItems.Add(item);
                }
            }
            catch (Exception)
            {
                MessageFormManager.MakeMessagePopup("Something went wrong!", "Could not find a video with that youtube url!\r\nPlease try again.", 5);
            }
        }
Exemplo n.º 4
0
        private void tmrCheckProgress_Tick(object sender, EventArgs e)
        {
            if (convertTask.IsCompleted)
            {
                if (!isHistory)
                {
                    pbLoad.Image           = null;
                    pbLoad.BackgroundImage = Properties.Resources.Check;

                    btnDownload.BackgroundImage = Properties.Resources.folderIcon;
                    btnDownload.Image           = null;

                    lblStatus.Text      = "Done.";
                    isConverting        = false;
                    btnDownload.Enabled = true;

                    //Play the sound
                    if (BLSettings.PlaySound)
                    {
                        System.Media.SoundPlayer player;

                        if (File.Exists(BLSettings.SoundFile))
                        {
                            player = new System.Media.SoundPlayer(BLSettings.SoundFile);
                        }
                        else
                        {
                            player = new System.Media.SoundPlayer(Simple_Youtube2Mp3.Properties.Resources.DefaultNotification); // here WindowsFormsApplication1 is the namespace and Connect is the audio file name
                        }
                        player.Play();
                    }

                    if (!IsActive(Application.OpenForms["Form1"].Handle) && BLSettings.ShowNotification) //Form currently not on the foreground? show message form!
                    {
                        MessageFormManager.MakeMessagePopup("Download Complete", theVideo.Title + "." + BLSettings.AudioType + " Complete!", 2);
                    }
                }
                else
                {
                    MessageFormManager.MakeMessagePopup("Succesfully Re-Downloaded " + historyRecord.Title + "!", 5);

                    lblStatus.Text      = historyRecord.DownloadDate;
                    lblStatus.Location  = pbLoad.Location;
                    btnDownload.Enabled = true;

                    pbLoad.Visible   = false;
                    pbDownload.Value = 0;
                }
                tmrCheckProgress.Stop();
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Adds a downloadItem to the panel
        /// </summary>
        /// <param name="item"></param>
        /// <param name="pnl"></param>
        public static DownloadItem AddDownloadItem(string url, Panel pnl)
        {
            try
            {
                string playlistId = "";
                string videoId    = "";
                YoutubeClient.TryParsePlaylistId(url, out playlistId);
                YoutubeClient.TryParseVideoId(url, out videoId);
                //VideoId AND playlistId valid? Then this is a song inside a playlist
                if (!string.IsNullOrEmpty(playlistId) && !string.IsNullOrEmpty(videoId) &&
                    MsgBox.Show("Attention", "This video is part of a playlist. Do you wish to download the entire playlist?", MsgBoxReason.YesNo) == DialogResult.Yes)
                {
                    AddDownloadItems(playlistId, pnl);
                }
                else if (!string.IsNullOrEmpty(videoId))
                {
                    DownloadItem toAddItem = new DownloadItem(url);
                    if (downloadItems.Count > 0)
                    {
                        toAddItem.Location = new Point(0, downloadItems[downloadItems.Count - 1].Location.Y + toAddItem.Height);
                    }


                    downloadItems.Add(toAddItem);
                    pnl.Controls.Add(toAddItem);
                    return(toAddItem);
                }
                else if (!string.IsNullOrEmpty(playlistId))
                {
                    AddDownloadItems(playlistId, pnl);
                    return(null);
                }
            }
            catch (Exception)
            {
                MessageFormManager.MakeMessagePopup("Something went wrong!", "Could not find a video with that youtube url!\r\nPlease try again.", 5);
            }
            return(null);
        }
Exemplo n.º 6
0
        private void tmrFadeout_Tick(object sender, EventArgs e)
        {
            if (this.Bounds.Contains(MousePosition)) //Cursor in the message? reset opacity to 1 and restart timeout timer
            {
                this.Opacity  = 1;
                secondsPassed = 0;
                tmrTimeout.Start();
            }
            else //Cursor out of the message? safely reduce opacity "slowly"
            {
                this.Opacity -= 0.02;
                if (this.Opacity <= 0)
                {
                    tmrFadeout.Stop();

                    tmrFadein.Dispose();
                    tmrFadeout.Dispose();
                    tmrTimeout.Dispose();
                    this.Dispose();
                    MessageFormManager.RepositionActivePopups();
                }
            }
        }
Exemplo n.º 7
0
 private void lblExit_Click(object sender, EventArgs e)
 {
     this.Dispose();
     MessageFormManager.RepositionActivePopups();
 }
Exemplo n.º 8
0
        public async void Download()
        {
            try
            {
                isDownloading = true;
                if (!canDownload)
                {
                    return;
                }

                pbLoad.Image = null;
                if (!downloadTask.IsCanceled)
                {
                    btnDownload.Enabled = false;
                    if (theVideo == null)
                    {
                        lblStatus.Location = pbLoad.Location;
                        MessageFormManager.MakeMessagePopup("Could not download that video!\r\nIt might be unavailable", 6);
                        return;
                    }
                    //Set the image to zzz - enqueue'd. Then, if it can download(if there aren't already a few threads downloading) it will change to downloading...
                    pbLoad.BackgroundImage = Properties.Resources.zzz;
                    lblStatus.Visible      = true;
                    lblStatus.Text         = "Enqueued.";
                    lblExit.Enabled        = false;



                    MediaStreamInfoSet streamInfoSet = await client.GetVideoMediaStreamInfosAsync(theVideo.Id);

                    var streamInfo = streamInfoSet.Muxed.WithHighestVideoQuality();
                    if (streamInfo == null)
                    {
                        lblStatus.Text         = "Error.";
                        pbLoad.Image           = null;
                        pbLoad.BackgroundImage = Properties.Resources.error;
                        lblTitle.Text          = "Could not download this video";
                        lblExit.Enabled        = true;
                        return;
                    }
                    if (BLSettings.KeepMp4)
                    {//Audio only
                    }
                    else
                    {//Video too
                    }

                    pbLoad.BackgroundImage = null;
                    pbLoad.Image           = Properties.Resources.load25x25;
                    lblStatus.Text         = "Downloading...";


                    pathToVideo = GetValidFilePath(BLIO.rootFolder + "\\Video\\", theVideo.Title, "." + BLSettings.VideoType);

                    downloadTask = Task.Run(async() =>
                    {
                        lblExit.Invoke((MethodInvoker)(() =>
                        {
                            lblExit.Enabled = true;
                        }));

                        ctsDownload.Token.ThrowIfCancellationRequested();
                        await client.DownloadMediaStreamAsync(streamInfo, pathToVideo, new Progress <double>(d => setProgressbarValue(pbDownload, (int)Math.Round(Convert.ToDouble(d.ToString()) * 100))), ctsDownload.Token);
                    }, ctsDownload.Token);

                    if (!downloadTask.IsCanceled)
                    {
                        await downloadTask;
                    }


                    pbLoad.Image           = null;
                    pbLoad.BackgroundImage = Properties.Resources.load25x25;
                    lblStatus.Text         = "Preparing...";

                    ConvertToMp3(pathToVideo);
                }
            }
            catch (System.Threading.Tasks.TaskCanceledException ex)
            {
                //Probably a timeout! multiple other threads downloading. gotta wait for them to finish, re-try this one.
                lblStatus.Invoke((MethodInvoker)(() =>
                {
                    lblStatus.Text = "Failed.";
                }));
                Download();
            }
            catch (VideoUnavailableException ex)
            {
                if (ex.Message.Contains("Country")) //Video not available in your country --code 150
                {
                    MessageFormManager.MakeMessagePopup(theVideo.Title + " Is not available in your country", 7);
                    lblStatus.Invoke((MethodInvoker)(() =>
                    {
                        lblStatus.Text = "Failed.";
                    }));
                }
                else
                {
                    //Re-try!
                    lblStatus.Invoke((MethodInvoker)(() =>
                    {
                        lblStatus.Text = "Retrying...";
                    }));

                    Download();
                }
            }
            catch (HttpRequestException ex)
            {
                //Re-try!
                lblStatus.Invoke((MethodInvoker)(() =>
                {
                    lblStatus.Text = "Retrying...";
                }));

                Download();
            }
        }
Exemplo n.º 9
0
 private static void ShowError(Exception ex, string message, string description)
 {
     MessageFormManager.MakeMessagePopup("Error.", ex.GetType().ToString() + "\r\nWhoops! Something went wrong...\r\n" + message, 8);
 }