Exemplo n.º 1
0
 /// <summary>
 /// Convertit l'entrée de playlist minifiée en réelle entrée de playlist
 /// </summary>
 /// <param name="youtube_client"></param>
 /// <param name="soundcloud_client"></param>
 /// <returns></returns>
 public PlayListEntry expand(Youtube.Youtube youtube_client, SoundCloud.SoundCloud soundcloud_client)
 {
     PlayListEntry p = null;
     if (this.url.StartsWith("https://www.youtube.com") || this.url.StartsWith("https://m.youtube.com"))
         p = new PlayListEntry(youtube_client.resolveTrack(this.url), this.user, false);
     else if (this.url.StartsWith("https://soundcloud.com/") || this.url.StartsWith("https://m.soundcloud.com/"))
         p = new PlayListEntry(soundcloud_client.resolveTrack(this.url), this.user, false);
     return p;
 }
Exemplo n.º 2
0
 /// <summary>
 /// Transforme une mini playlist en réelle playlist
 /// </summary>
 /// <param name="youtube_client"></param>
 /// <param name="soundcloud_client"></param>
 /// <returns></returns>
 public Playlist expand(Youtube.Youtube youtube_client, SoundCloud.SoundCloud soundcloud_client)
 {
     Playlist p = new Playlist();
     foreach (PlayListEntryMinified e in to_play)
     {
         p.to_play.Add(e.expand(youtube_client, soundcloud_client));
     }
     foreach (PlayListEntryMinified e in played)
     {
         p.played.Add(e.expand(youtube_client, soundcloud_client));
     }
     p.banned = this.banned;
     return p;
 }
Exemplo n.º 3
0
 public Downloader()
 {
     Youtube = Youtube.Instance;
     Debug.AutoFlush = true;
     ThreadPool.QueueUserWorkItem(a => {
         while (true) {
             try {
                 _stopper.WaitOne();
                 ThreadPool.QueueUserWorkItem(aa => Download(_songs.Take()));
             } catch (Exception) {
                 MessageBox.Show(@"An error has occurred please reload the application.");
                 break;
             }
         }
     });
 }
Exemplo n.º 4
0
 /// <summary>
 /// Transforme les messages présents dans la boite mail en entrées de playlist pour la lecture
 /// </summary>
 /// <param name="youtube_client">Instance du client youtube permettant d'interragir avec le service de vidéo en ligne</param>
 /// <param name="soundcloud_client">Instance du client soundcloud permettant d'interragir avec le service de son en ligne</param>
 /// <returns></returns>
 public List<Music.PlayListEntry> getPlaylistEntriesFromMail(Youtube.Youtube youtube_client, SoundCloud.SoundCloud soundcloud_client)
 {
     List<Music.PlayListEntry> res = new List<Music.PlayListEntry>();
     List<Gmail> msg = this.getMessages();
     foreach (Gmail g in msg)
     {
         Music.ITrack track = null;
         if (Youtube.Youtube.isCompatible(g.content))
             track = youtube_client.resolveTrack(g.content);
         else if (SoundCloud.SoundCloud.isCompatible(g.content))
             track = soundcloud_client.resolveTrack(g.content);
         if (track != null)
         {
             res.Add(new Music.PlayListEntry(track, g.user, false));
         }
     }
     return res;
 }
Exemplo n.º 5
0
 public Voice(Settings settings, Media media, Youtube youtube)
 {
     _settings = settings ?? throw new ArgumentNullException(nameof(Settings));
     _media    = media ?? throw new ArgumentNullException(nameof(Media));
     _youtube  = youtube ?? throw new ArgumentNullException(nameof(Youtube));
 }
Exemplo n.º 6
0
 public static async Task <bool> IsValid(string link)
 {
     return(Youtube.IsValid(link));
 }
Exemplo n.º 7
0
        public override async Task <ResultType> Run(CancellationToken cancellationToken)
        {
            if (cancellationToken.IsCancellationRequested)
            {
                return(ResultType.Cancelled);
            }

            JobStatus = VideoJobStatus.Running;
            if ((VideoInfo as YoutubeVideoInfo) == null)
            {
                Status = "Retrieving video info...";
                bool wantCookies = Notes != null && Notes.Contains("cookies");
                var  result      = await Youtube.RetrieveVideo(VideoInfo.VideoId, VideoInfo.Username, wantCookies);

                switch (result.result)
                {
                case Youtube.RetrieveVideoResult.Success:
                    VideoInfo = result.info;
                    break;

                case Youtube.RetrieveVideoResult.ParseFailure:
                    // this seems to happen randomly from time to time, just retry later
                    return(ResultType.TemporarilyUnavailable);

                default:
                    return(ResultType.Failure);
                }
            }

            string filenameWithoutExtension = "youtube_" + VideoInfo.Username + "_" + VideoInfo.VideoTimestamp.ToString("yyyy-MM-dd") + "_" + VideoInfo.VideoId;
            string filename     = filenameWithoutExtension + ".mkv";
            string tempFolder   = Path.Combine(Util.TempFolderPath, filenameWithoutExtension);
            string tempFilepath = Path.Combine(tempFolder, filename);

            {
                if (!await Util.FileExists(tempFilepath))
                {
                    if (cancellationToken.IsCancellationRequested)
                    {
                        return(ResultType.Cancelled);
                    }

                    Directory.CreateDirectory(tempFolder);
                    Status = "Running youtube-dl...";
                    await StallWrite(tempFilepath, 0, cancellationToken);                       // don't know expected filesize, so hope we have a sensible value in minimum free space

                    if (cancellationToken.IsCancellationRequested)
                    {
                        return(ResultType.Cancelled);
                    }
                    List <string> args = new List <string>()
                    {
                        "-f", "bestvideo[height<=?1080]+bestaudio/best",
                        "-o", tempFilepath,
                        "--merge-output-format", "mkv",
                        "--no-color",
                        "--abort-on-error",
                        "--abort-on-unavailable-fragment",
                        "--no-sponsorblock",
                    };
                    string limit = Util.YoutubeSpeedLimit;
                    if (limit != "")
                    {
                        args.Add("--rate-limit");
                        args.Add(limit);
                    }
                    bool wantCookies = Notes != null && Notes.Contains("cookies");
                    if (wantCookies)
                    {
                        args.Add("--cookies");
                        args.Add(@"d:\cookies.txt");
                    }
                    bool nokill = Notes != null && Notes.Contains("nokill");
                    args.Add("https://www.youtube.com/watch?v=" + VideoInfo.VideoId);
                    var data = await ExternalProgramExecution.RunProgram(
                        @"yt-dlp", args.ToArray(), youtubeSpeedWorkaround : !nokill,
                        stdoutCallbacks : new System.Diagnostics.DataReceivedEventHandler[1] {
                        (sender, received) => {
                            if (!String.IsNullOrEmpty(received.Data))
                            {
                                Status = received.Data;
                            }
                        }
                    }
                        );
                }

                string finalFilename = GenerateOutputFilename();
                string finalFilepath = Path.Combine(Util.TargetFolderPath, finalFilename);
                if (File.Exists(finalFilepath))
                {
                    throw new Exception("File exists: " + finalFilepath);
                }

                Status = "Waiting for free disk IO slot to move...";
                try {
                    await Util.ExpensiveDiskIOSemaphore.WaitAsync(cancellationToken);
                } catch (OperationCanceledException) {
                    return(ResultType.Cancelled);
                }
                try {
                    // sanity check
                    Status = "Sanity check on downloaded video...";
                    TimeSpan actualVideoLength   = (await FFMpegUtil.Probe(tempFilepath)).Duration;
                    TimeSpan expectedVideoLength = VideoInfo.VideoLength;
                    if (actualVideoLength.Subtract(expectedVideoLength).Duration() > TimeSpan.FromSeconds(5))
                    {
                        // if difference is bigger than 5 seconds something is off, report
                        Status = "Large time difference between expected (" + expectedVideoLength.ToString() + ") and actual (" + actualVideoLength.ToString() + "), stopping.";
                        return(ResultType.Failure);
                    }

                    Status = "Moving...";
                    await Task.Run(() => Util.MoveFileOverwrite(tempFilepath, finalFilepath));

                    await Task.Run(() => Directory.Delete(tempFolder));
                } finally {
                    Util.ExpensiveDiskIOSemaphore.Release();
                }
            }

            Status    = "Done!";
            JobStatus = VideoJobStatus.Finished;
            return(ResultType.Success);
        }
 protected Liver()
 {
     IsLive    = false;
     MyYoutube = new Youtube();
 }
 public void Download(string url)
 {
     Youtube.ClearQueue();
     Youtube.Queue(url);
     Youtube.DownloadQueue().Wait();
 }
Exemplo n.º 10
0
 /// <summary>
 /// Charge la playlist depuis un format JSON
 /// </summary>
 /// <param name="youtube_client">Client youtube</param>
 /// <param name="soundcloud_client">Client Soundcloud</param>
 public void load(Youtube.Youtube youtube_client, SoundCloud.SoundCloud soundcloud_client)
 {
     if (File.Exists("save.json") == false)
         return;
     string data = new StreamReader(File.OpenRead("save.json")).ReadToEnd();
     Playlist p = (JsonConvert.DeserializeObject<PlaylistMinified>(data)).expand(youtube_client, soundcloud_client);
     this.to_play = p.to_play;
     this.played = p.played;
     this.playing = p.playing;
     this.banned = p.banned;
 }
Exemplo n.º 11
0
        public async Task <ActionResult <dynamic> > PostYoutubeSong(YoutubeLink youtubeLink)
        {
            var SongCount         = _context.TSongs.ToList <YoutubeSong>().Count;
            var PlaylistCount     = _playlistContext.TPlaylist.ToList <YoutubePlaylist>().Count;
            var SongPlaylistCount = _songPlaylistContext.TSongPlaylist.ToList <SongPlaylist>().Count;

            // This gets the YoutubeVideo object and downloads the mp3
            _youtube = new Youtube(youtubeLink.Url, @"C:\Users\nsedler\source\repos\WebApplication3\WebApplication3\Files\");
            Tuple <Video, Playlist> VideoPlaylist = await _youtube.GetYoutubeVideoAsync();

            await _youtube.DownloadYoutubeVideoAsync();

            //Sets the Songs fields
            YoutubeSong _song = new YoutubeSong();

            if (VideoPlaylist.Item1 != null)
            {
                _song = new YoutubeSong();
                var video = VideoPlaylist.Item1;
                _song.Title  = video.Title;
                _song.Length = video.Duration.Ticks;
                _song.Url    = $"https://localhost:44370/StaticSongs/{video.Title}.mp3";
                _song.Id     = SongCount + 1;

                _context.TSongs.Add(_song);
                await _context.SaveChangesAsync();
            }
            else
            {
                YoutubePlaylist YoutubePlaylist = new YoutubePlaylist();
                var             Playlist        = await _YoutubeClient.Playlists.GetAsync(VideoPlaylist.Item2.Id);

                YoutubePlaylist.Name = Playlist.Title;
                YoutubePlaylist.Id   = PlaylistCount + 1;

                _playlistContext.TPlaylist.Add(YoutubePlaylist);
                await _playlistContext.SaveChangesAsync();



                await foreach (var video in _YoutubeClient.Playlists.GetVideosAsync(VideoPlaylist.Item2.Id))
                {
                    _song        = new YoutubeSong();
                    _song.Title  = video.Title;
                    _song.Length = video.Duration.Ticks;
                    _song.Url    = $"https://localhost:44370/StaticSongs/{video.Title}.mp3";
                    _song.Id     = SongCount + 1;

                    _context.TSongs.Add(_song);
                    await _context.SaveChangesAsync();

                    SongPlaylist SongPlaylist = new SongPlaylist();
                    SongPlaylist.Id         = SongPlaylistCount + 1;
                    SongPlaylist.SongId     = _song.Id;
                    SongPlaylist.PlaylistId = YoutubePlaylist.Id;

                    _songPlaylistContext.TSongPlaylist.Add(SongPlaylist);
                    await _songPlaylistContext.SaveChangesAsync();

                    SongPlaylistCount++;
                    SongCount++;
                }

                return(CreatedAtAction("GetYoutubeSong", new { id = YoutubePlaylist.Id }, YoutubePlaylist));
            }

            return(CreatedAtAction("GetYoutubeSong", new { id = _song.Id }, _song));
        }