Example #1
0
        private void GetPlaylist(string URL)
        {
            var process = new YoutubeDL(URL);

            Tracks.AddRange(process.GetData());
            Close();
        }
        private async Task Download()
#endif
        {
            while (TracksToDownload.Count > 0)
            {
                var track = TracksToDownload[0];
                if (downloadAgain)
                {
                    track.filePath = "";
                    track.UpdateItem();
                }
#if DEBUG
                YoutubeDL.DownloadTrack(track);
#else
                if (Counter < 3)
                {
                    YoutubeDL.DownloadTrack(track);
                }
                else
                {
                    await YoutubeDL.DownloadTrack(track);
                }
#endif
                TracksToDownload.Remove(track);
            }
        }
        void GetPlaylist(String URL)
        {
            YoutubeDL process = new YoutubeDL(URL);

            Tracks.AddRange(process.GetData());
            this.Close();
        }
        public List <Track> MakeTracksList(string URL)
        {
            var Array = new List <Track>();

            var GroupID       = Regex.Match(URL, @"v=([^&]*)").Groups;
            var GroupPlaylist = Regex.Match(URL, @"list=([^&]*)").Groups;
            var GroupUser     = Regex.Match(URL, @"/user/([^/]*)/").Groups;

            var IsTrack    = GroupID.Count > 1;
            var IsPlaylist = GroupPlaylist.Count > 1;
            var IsUser     = GroupUser.Count > 1;

            if (IsTrack)
            {
                var YoutubeID = GroupID[1].Value;
                var track     = new Track("", YoutubeID);
                track.MusicTab = this;
                Array.Add(track);
            }
            else if (IsPlaylist)
            {
                var Playlist = GroupPlaylist[1].Value;
                var youtube  = new YoutubeDL(Playlist);
                Array.AddRange(youtube.GetData());
            }
            else if (IsUser)
            {
                var User    = GroupUser[1].Value;
                var youtube = new YoutubeDL("ytuser:" + User);
                Array.AddRange(youtube.GetData());
            }

            return(Array);
        }
        internal static async void PlayAfterDownload(List <Track> tracks)
        {
            if (tracks.Count == 0)
            {
                return;
            }
            var track = tracks[0];

#if DEBUG
            YoutubeDL.DownloadTrack(track);
#else
            await YoutubeDL.DownloadTrack(track);
#endif
            track.MusicTab.Play(track);
            while (!MusicPlayer.Instance.IsPlaying)
            {
                //await Task.Delay(200);
                Thread.Sleep(200);
            }
            AddToDownload(tracks.GetRange(1, tracks.Count - 1));
        }
Example #6
0
        public static List <Track> MakeTracksList(string URL)
        {
            List <Track> Array = new List <Track>();

            var GroupID       = Regex.Match(URL, @"v=([^&]*)").Groups;
            var GroupPlaylist = Regex.Match(URL, @"list=([^&]*)").Groups;
            var GroupUser     = Regex.Match(URL, @"/user/([^/]*)/").Groups;

            bool IsTrack    = GroupID.Count > 1;
            bool IsPlaylist = GroupPlaylist.Count > 1;
            bool IsUser     = GroupUser.Count > 1;

            if (IsTrack)
            {
                foreach (Group g in GroupID)
                {
                    Debug.WriteLine(g.Value);
                }
                String YoutubeID = GroupID[1].Value;
                Track  track     = new Track("", "", YoutubeID);
                Array.Add(track);
            }
            else if (IsPlaylist)
            {
                String    Playlist = GroupPlaylist[1].Value;
                YoutubeDL youtube  = new YoutubeDL(Playlist);
                Array.AddRange(youtube.GetData());
            }
            else if (IsUser)
            {
                String    User    = GroupUser[1].Value;
                YoutubeDL youtube = new YoutubeDL("ytuser:" + User);
                Array.AddRange(youtube.GetData());
            }

            return(Array);
        }
Example #7
0
        public void SearchFor(String str)
        {
            Debug.WriteLine("Search");
            YoutubeDL     yt   = new YoutubeDL("\"ytsearch50: " + str + "\"");
            List <String> URLs = yt.Search("");

            using (WebClient client = new WebClient())
            {
                for (int i = 0; i < URLs.Count; i++)
                {
                    client.DownloadFile(@"https://i.ytimg.com/vi/" + URLs[i] + @"/hqdefault.jpg", @"./" + i + ".jpg");
                    PictureBox picture = new PictureBox();
                    picture.ImageLocation = @"./" + i + ".jpg";
                    picture.SizeMode      = PictureBoxSizeMode.Zoom;
                    picture.Size          = new Size(480 / 5, 360 / 5);
                    FlowLayoutPanel.Controls.Add(picture);
                }
            }

            //http://i.ytimg.com/vi/{video_id}/maxresdefault.jpg
            //http://img.youtube.com/vi/Ys5xfdn5rlo/2.jpg
            //https://i.ytimg.com/vi/Ys5xfdn5rlo/hqdefault.jpg?sqp=-oaymwEXCPYBEIoBSFryq4qpAwkIARUAAIhCGAE=&rs=AOn4CLDVDpwePx9tKLUbyaxWj9W8_YefaA
            //https://i.ytimg.com/vi/Ys5xfdn5rlo/hqdefault.jpg
        }
        public static async Task ConvertToMp3(Track track)
#endif
        {
            CheckBinary();

            if (string.IsNullOrWhiteSpace(track.filePath))
            {
                return;
            }
            if (!File.Exists(track.filePath))
            {
                return;
            }
            if (!string.Equals(Path.GetExtension(track.filePath), ".m4a", StringComparison.OrdinalIgnoreCase))
            {
                return;
            }
            var f             = TagLib.File.Create(track.filePath);
            var TotalDuration = f.Properties.Duration.TotalSeconds;

            var TemporaryOutput = Path.GetTempFileName();

            TemporaryOutput = Path.ChangeExtension(TemporaryOutput, ".mp3");

            var progressBar = YoutubeDL.CreateProgressBar(track);

            var process   = new Process();
            var startInfo = new ProcessStartInfo();

            startInfo.WindowStyle                    = ProcessWindowStyle.Hidden;
            startInfo.FileName                       = ffmpegDir;
            startInfo.Arguments                      = "-i \"" + track.filePath + "\"";
            startInfo.Arguments                     += " -acodec libmp3lame -ab 128k -y ";
            startInfo.Arguments                     += "\"" + TemporaryOutput + "\"";
            process.StartInfo                        = startInfo;
            process.StartInfo.UseShellExecute        = false;
            process.StartInfo.RedirectStandardOutput = true;
            process.StartInfo.RedirectStandardError  = true;
            process.StartInfo.WindowStyle            = ProcessWindowStyle.Hidden;
            process.StartInfo.CreateNoWindow         = true;
            process.Start();

            var reader = process.StandardError;

            while (!process.HasExited)
            {
#if DEBUG
                String str = reader.ReadLine();
#else
                var str = await reader.ReadLineAsync();
#endif
                if (string.IsNullOrWhiteSpace(str))
                {
                    continue;
                }
                var match = Regex.Match(str, @"time=(\d\d):(\d\d):(\d\d)");
                if (match.Success && match.Groups.Count == 4)
                {
                    var Hours   = match.Groups[1].ToString();
                    var Minutes = match.Groups[2].ToString();
                    var Seconds = match.Groups[3].ToString();

                    var Duration = int.Parse(Hours) * 3600 + int.Parse(Minutes) * 60 + int.Parse(Seconds);
                    Debug.WriteLine(Duration + " " + TotalDuration);
                    var Percent = (int)(Duration * 100 / TotalDuration);
                    //YoutubeDL.UpdateProgressBar(track, Percent);
                    Debug.WriteLine("{0} {1} {2}", Hours, Minutes, Seconds);
                }
            }
            YoutubeDL.RemoveProgressBar(track);
            if (File.Exists(TemporaryOutput))
            {
                var finalOutput = Path.GetDirectoryName(track.filePath) + "\\" +
                                  Path.GetFileNameWithoutExtension(track.filePath) + ".mp3";
                if (File.Exists(finalOutput))
                {
                    File.Delete(finalOutput);
                }
                File.Move(TemporaryOutput, finalOutput);
                if (File.Exists(finalOutput))
                {
                    track.filePath = finalOutput;
                    track.UpdateItem();
                }
            }

            MainWindow.SavePlaylists();
        }
Example #9
0
        public async Task DownloadTrack(Track track) =>
#endif
#if DEBUG
        YoutubeDL.DownloadTrack(track);