public void ServiceRemoveCorrectSongsOnRemove()
        {
            //arrange
            var conn = ConnectionHelper.CreateMemoryTable();

            conn.InsertTestData("Insert into YoutubeSong values ('song1',1,100,'title1')");
            conn.InsertTestData("Insert into YoutubeSong values ('song2',2,100,'title2')");
            var loggerStub = new Mock <ILoggerFacade>();
            var service    = new YoutubePlaylistService(conn, loggerStub.Object);
            var song       = new YoutubeSong
            {
                Title      = "title1",
                VideoId    = "song1",
                PlaylistNr = 1,
            };
            var playlist = new Playlist
            {
                Id = "100",
            };


            //act
            service.RemoveSong(song, playlist);

            //assert
            var res = service.LoadSongsBelongingToPlaylist(100);

            Assert.AreEqual(1, res.Count);
            var firstSongRes = (YoutubeSong)res.First();

            Assert.AreEqual("title2", firstSongRes.Title);
            Assert.AreEqual("song2", firstSongRes.VideoId);
        }
        public void ServiceReplaceCorrectSongsOnSave()
        {
            //arrange
            var conn       = ConnectionHelper.CreateMemoryTable();
            var loggerStub = new Mock <ILoggerFacade>();
            var service    = new YoutubePlaylistService(conn, loggerStub.Object);
            var song       = new YoutubeSong
            {
                Title   = "test Song",
                VideoId = "testVideoId",
            };
            var playlist = new Playlist
            {
                Id = "4",
            };

            //act
            service.SaveSong(song, playlist);
            service.SaveSong(song, playlist);

            //assert
            var res = service.LoadSongsBelongingToPlaylist(4);

            Assert.AreEqual("test Song", res.First().Title);
            Assert.AreEqual(1, res.Count);
        }
예제 #3
0
        public YoutubeAudioPlayer(YoutubeSong song)
        {
            if (song == null)
                Throw.ArgumentNullException(() => song);

            this.Song = song;
        }
예제 #4
0
        public async Task <IActionResult> PutYoutubeSong(int id, YoutubeSong youtubeSong)
        {
            if (id != youtubeSong.Id)
            {
                return(BadRequest());
            }

            _context.Entry(youtubeSong).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!YoutubeSongExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
예제 #5
0
        public YoutubeSongViewModel(YoutubeSong wrapped, Func <string> downloadPathFunc)
            : base(wrapped)
        {
            this.hasThumbnail = this.WhenAnyValue(x => x.Thumbnail)
                                .Select(x => x != null)
                                .ToProperty(this, x => x.HasThumbnail);

            // Wait for the opening of the context menu to download the YouTube information
            this.WhenAnyValue(x => x.IsContextMenuOpen)
            .FirstAsync(x => x)
            .SelectMany(_ => this.LoadContextMenu().ToObservable())
            .Subscribe();

            // We have to set a dummy here, so that we can connect the commands
            this.isDownloading = Observable.Never <bool>().ToProperty(this, x => x.IsDownloading);

            this.DownloadVideoCommand = ReactiveCommand.CreateAsyncTask(this.WhenAnyValue(x => x.IsDownloading).Select(x => !x),
                                                                        x => this.DownloadVideo((VideoInfo)x, downloadPathFunc()));

            this.DownloadAudioCommand = ReactiveCommand.CreateAsyncTask(this.WhenAnyValue(x => x.IsDownloading).Select(x => !x),
                                                                        x => this.DownloadAudio((VideoInfo)x, downloadPathFunc()));

            this.isDownloading = this.DownloadVideoCommand.IsExecuting
                                 .CombineLatest(this.DownloadAudioCommand.IsExecuting, (x1, x2) => x1 || x2)
                                 .ToProperty(this, x => x.IsDownloading);
        }
예제 #6
0
        public void SmokeTest()
        {
            var song1 = new YoutubeSong("www.youtube.com?watch=abcde", TimeSpan.Zero)
            {
                Title = "A"
            };
            var song2 = new YoutubeSong("www.youtube.com?watch=abcdef", TimeSpan.Zero)
            {
                Title = "B"
            };

            var songs = (IReadOnlyList <YoutubeSong>) new[] { song1, song2 }.ToList();

            var songFinder = Substitute.For <IYoutubeSongFinder>();

            songFinder.GetSongsAsync(Arg.Any <string>()).Returns(Observable.Return(songs));

            using (var library = Helpers.CreateLibrary())
            {
                Guid token = library.LocalAccessControl.RegisterLocalAccessToken();
                var  vm    = new YoutubeViewModel(library, new ViewSettings(), new CoreSettings(), token, songFinder);

                Assert.Equal(songs, vm.SelectableSongs.Select(x => x.Model).ToList());
                Assert.Equal(songs.First(), vm.SelectableSongs.First().Model);
                Assert.False(vm.IsSearching);
            }
        }
예제 #7
0
        public YoutubeAudioPlayer(YoutubeSong song)
        {
            if (song == null)
            {
                Throw.ArgumentNullException(() => song);
            }

            this.Song = song;
        }
예제 #8
0
        private YoutubeSong MapSong(SearchResult result)
        {
            //TODO: will have to make a new request to get length of video.
            var thumbnail = getPicture(result.Snippet.Thumbnails);
            var song      = new YoutubeSong(thumbnail, result.Snippet.Title, result.Id.VideoId, new TimeSpan())
            {
                Description = result.Snippet.Description,
                Embeddable  = isEmbeddable(result.Id.VideoId, _youtubeService),
                Artist      = result.Snippet.ChannelTitle,
            };

            return(song);
        }
예제 #9
0
        /// <summary>
        /// Resolves the given YouTube URL and adds the song to the playlist.
        ///
        /// This method will only execute successfully if the <see cref="SongSourceViewModel{T}.AddToPlaylistCommand"/> command can execute.
        /// </summary>
        public async Task AddDirectYoutubeUrlToPlaylist(Uri url, int?targetIndex)
        {
            if (url == null)
            {
                throw new ArgumentNullException(nameof(url));
            }

            YoutubeSong song = await this.youtubeSongFinder.ResolveYoutubeSongFromUrl(url);

            if (song == null)
            {
                this.Log().Error("Could not register direct YouTube url \{url}");
                return;
            }
예제 #10
0
        public YoutubeAudioPlayer(YoutubeSong song)
        {
            if (song == null)
                Throw.ArgumentNullException(() => song);

            string vlcPath = ApplicationHelper.DetectVlcFolderPath();

            VlcContext.LibVlcDllsPath = vlcPath;
            VlcContext.LibVlcPluginsPath = Path.Combine(vlcPath, "plugins");

            VlcContext.StartupOptions.IgnoreConfig = true;

            VlcContext.Initialize();

            this.player = new VlcControl();

            this.player.TimeChanged += (sender, e) => this.CheckSongFinished();
        }
예제 #11
0
        /// <summary>
        /// Resolves the given YouTube URL and adds the song to the playlist.
        ///
        /// This method will only execute successfully if the <see
        /// cref="SongSourceViewModel{T}.AddToPlaylistCommand" /> command can execute.
        /// </summary>
        public async Task AddDirectYoutubeUrlToPlaylist(Uri url, int?targetIndex)
        {
            if (url == null)
            {
                Throw.ArgumentNullException(() => url);
            }

            YoutubeSong song = await this.youtubeSongFinder.ResolveYoutubeSongFromUrl(url);

            if (song == null)
            {
                this.Log().Error("Could not register direct YouTube url {0}", url.OriginalString);
                return;
            }

            this.SelectedSongs = new[] { new YoutubeSongViewModel(song, () => { throw new NotImplementedException(); }) };

            await this.AddToPlaylistCommand.ExecuteAsync(targetIndex);
        }
예제 #12
0
            public async Task NullUriThrowsArgumentNullException()
            {
                const string youtubePath = "http://youtube.com?v=yadda";
                var          song        = new YoutubeSong(youtubePath, TimeSpan.FromMinutes(1));
                var          songFinder  = Substitute.For <IYoutubeSongFinder>();

                songFinder.ResolveYoutubeSongFromUrl(Arg.Any <Uri>()).Returns(Task.FromResult(song));

                using (var library = new LibraryBuilder().WithPlaylist().Build())
                {
                    Guid accessToken = library.LocalAccessControl.RegisterLocalAccessToken();

                    var playlist = library.Playlists.First();
                    library.SwitchToPlaylist(playlist, accessToken);

                    var fixture = new DirectYoutubeViewModel(library, new CoreSettings(), accessToken, songFinder);

                    await Helpers.ThrowsAsync <ArgumentNullException>(() => fixture.AddDirectYoutubeUrlToPlaylist(null, null));
                }
            }
예제 #13
0
            public async Task SmokeTest()
            {
                const string youtubePath = "http://youtube.com?v=yadda";
                var          song        = new YoutubeSong(youtubePath, TimeSpan.FromMinutes(1));
                var          songFinder  = Substitute.For <IYoutubeSongFinder>();

                songFinder.ResolveYoutubeSongFromUrl(Arg.Any <Uri>()).Returns(Task.FromResult(song));

                using (var library = new LibraryBuilder().WithPlaylist().Build())
                {
                    Guid accessToken = library.LocalAccessControl.RegisterLocalAccessToken();

                    var playlist = library.Playlists.First();
                    library.SwitchToPlaylist(playlist, accessToken);

                    var fixture = new DirectYoutubeViewModel(library, new CoreSettings(), accessToken, songFinder);

                    await fixture.AddDirectYoutubeUrlToPlaylist(new Uri(youtubePath), null);

                    Assert.Equal(1, playlist.Count());
                }
            }
예제 #14
0
 private async Task DownloadVideo(VideoInfo videoInfo, string downloadPath)
 {
     await this.DownloadFromYoutube(videoInfo, () => YoutubeSong.DownloadVideoAsync(videoInfo, downloadPath,
                                                                                    Observer.Create <double>(progress => this.DownloadProgress = (int)progress)));
 }
예제 #15
0
 public YoutubePreviewViewModel(YoutubeSong song)
 {
     _song = song;
 }
예제 #16
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));
        }
예제 #17
0
 public YoutubeSongViewModel(YoutubeSong wrapped)
     : base(wrapped)
 {
 }