예제 #1
0
        public ActionResult AddSong(AdminViewModel vm)
        {
            var  addsong = vm.AddSong;
            Song song    = new Song()
            {
                Name          = addsong.Name,
                YearOfRelease = addsong.Year,
                Album         = addsong.SelectedAlbum,
                Artist        = addsong.SelectedArtist,
                File          = addsong.File.InputStream,
                Owner         = new MongoDB.Bson.ObjectId("58a86904bd1f138ddc58847b")
            };

            string[] tmp = addsong.Genres.Split(' ');
            foreach (string s in tmp)
            {
                song.Genres.Add(s);
            }
            tmp = addsong.Tags.Split(' ');
            foreach (string s in tmp)
            {
                song.Tag.Add(s);
            }
            if (userService.User.Id == new MongoDB.Bson.ObjectId("58a86904bd1f138ddc58847b"))
            {
                songRepo.Add(song);
                var album = albumRepo.GetAlbumById(song.Album);
                album.Songs.Add(song.SongId);
                albumRepo.UpdateAlbum(album);
            }
            return(RedirectToAction("Index", "Admin"));
        }
예제 #2
0
        public void PopulateSongTable1()
        {
            var    gDriveServiceContainer = new GDriveService();
            var    gdriveService          = gDriveServiceContainer.GetService();
            var    songRepository         = new SongRepository(new Repository("log"));
            int    maxSongs   = 10;
            int    songCount  = 0;
            string tempFolder = @"C:\temp2\";

            FilesResource.ListRequest request = gdriveService.Files.List();
            var fileList = new List <File>();

            try
            {
                FileList files = request.Execute();
                fileList.AddRange(files.Items);
                request.PageToken = files.NextPageToken;
                foreach (var file in fileList)
                {
                    try
                    {
                        testContextInstance.WriteLine("{0}", file.WebContentLink);
                        WebClient webClient = new WebClient();
                        string    filename  = tempFolder + file.OriginalFilename;
                        webClient.DownloadFile(file.WebContentLink, filename);

                        // Extract mp3 tags
                        SONG song = new SONG();
                        song.LOCATION = filename;
                        if (song.IsMp3File())
                        {
                            song.Populate();

                            testContextInstance.WriteLine(song.GENRE);
                            songRepository.Add(file.Id, file.WebContentLink, file.OriginalFilename, file.FileSize, song.TITLE, song.ARTIST, song.ALBUM, song.GENRE, song.LOCATION, song.RATING, song.TrackNumber);
                        }

                        System.IO.File.Delete(filename);
                    }
                    catch (Exception ex1)
                    {
                        testContextInstance.WriteLine("Error: {0}", ex1.Message);
                    }

/*					songCount++;
 *                                      if (songCount>maxSongs)
 *                                      {
 *                                              return;
 *                                      } */
                }
            }
            catch (Exception e)
            {
                testContextInstance.WriteLine("Error: {0}", e.Message);
            }
        }
예제 #3
0
        public void PopulateSongTable2()
        {
            var         gDriveServiceContainer = new GDriveService();
            var         gdriveService          = gDriveServiceContainer.GetService();
            List <File> fileList = new List <File>();

            FilesResource.ListRequest request = gdriveService.Files.List();
            string tempFolder     = @"E:\MusicTemp\";
            var    songRepository = new SongRepository(new Repository("log"));

            do
            {
                try
                {
                    FileList files = request.Execute();
                    fileList.AddRange(files.Items);
                    request.PageToken = files.NextPageToken;
                    foreach (var file in fileList)
                    {
                        try
                        {
                            testContextInstance.WriteLine("{0}", file.WebContentLink);
                            WebClient webClient = new WebClient();
                            string    filename  = tempFolder + file.OriginalFilename;
                            webClient.DownloadFile(file.WebContentLink, filename);

                            // Extract mp3 tags
                            SONG song = new SONG();
                            song.LOCATION = filename;
                            if (song.IsMp3File())
                            {
                                song.Populate();

                                testContextInstance.WriteLine(song.GENRE);
                                songRepository.Add(file.Id, file.WebContentLink, file.OriginalFilename, file.FileSize, song.TITLE, song.ARTIST, song.ALBUM, song.GENRE, song.LOCATION, song.RATING, song.TrackNumber);
                            }

                            System.IO.File.Delete(filename);
                        }
                        catch (Exception ex1)
                        {
                            testContextInstance.WriteLine("Error: {0}", ex1.Message);
                        }
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine("An error occurred: " + e.Message);
                    request.PageToken = null;
                }
            } while (!String.IsNullOrEmpty(request.PageToken));
        }
예제 #4
0
        public ActionResult AddSong(MySongsViewModel model)
        {
            var song = new Song()
            {
                Name   = model.Name,
                Artist = model.Artist,
                Album  = model.Album,
                File   = model.Song.InputStream,
                Owner  = userService.User.Id
            };

            songRepo.Add(song);
            return(RedirectToAction("Index", "MySongs"));
        }
예제 #5
0
        public void Add_Song_AddsSongToDatabase()
        {
            var song = new Song
            {
                Id    = Guid.NewGuid(),
                Album = new Album {
                    Id = Guid.NewGuid()
                }
            };

            _songRepository.Add(song);

            var songs = _context.Songs.ToList();

            Assert.IsTrue(songs.Contains(song));
        }
예제 #6
0
        public void ProcessFile(string filename, Google.Apis.Drive.v2.Data.File file, DynamicTableEntity existingFile)
        {
            SONG song = new SONG();

            song.LOCATION = filename;
            song.Populate();

            if (song.ARTIST == null)
            {
                Debug.WriteLine("song.ARTIST == null");
                return;
            }


            if (existingFile == null)
            {
                songRepository.Add(file.Id, file.WebContentLink, file.OriginalFilename, file.FileSize, song.TITLE, song.ARTIST, song.ALBUM, song.GENRE, song.LOCATION, song.RATING, song.TrackNumber);
            }
            else
            {
                songRepository.Update(file.Id, file.WebContentLink, file.OriginalFilename, file.FileSize, song.TITLE, song.ARTIST, song.ALBUM, song.GENRE, song.LOCATION, song.RATING, song.TrackNumber);
            }
        }
예제 #7
0
        public void DownloadGDriveFiles()
        {
            var    songRepository = new SongRepository(new Repository("log"));
            string tempFolder     = @"C:\temp2\";
            string search         = "title='Sunspot.mp3'";
            //			string search = "";
            var gDriveService = new GDriveService();
            var files         = gDriveService.GetFiles(search);

            foreach (var file in files)
            {
                try
                {
                    testContextInstance.WriteLine("{0}", file.WebContentLink);
                    WebClient webClient = new WebClient();
                    string    filename  = tempFolder + file.OriginalFilename;
                    webClient.DownloadFile(file.WebContentLink, filename);

                    // Extract mp3 tags
                    SONG song = new SONG();
                    song.LOCATION = filename;
                    if (song.IsMp3File())
                    {
                        song.Populate();

                        testContextInstance.WriteLine(song.GENRE);
                        songRepository.Add(file.Id, file.WebContentLink, file.OriginalFilename, file.FileSize, song.TITLE, song.ARTIST, song.ALBUM, song.GENRE, "", 0, song.TrackNumber);
                    }

                    System.IO.File.Delete(filename);
                }
                catch (Exception ex)
                {
                    testContextInstance.WriteLine(ex.Message);
                }
            }
        }