Esempio n. 1
0
        public void PopulateSongTable()
        {
            var gDriveServiceContainer = new GDriveService();
            var gdriveService          = gDriveServiceContainer.GetService();
            var songRepository         = new SongRepository(new Repository("log"));

            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
                    {
                        songRepository.Set(file.Id, file.DownloadUrl);
                    }
                    catch (Exception ex1)
                    {
                        testContextInstance.WriteLine("Error: {0}", ex1.Message);
                    }
                }
            }
            catch (Exception e)
            {
                testContextInstance.WriteLine("Error: {0}", e.Message);
            }
        }
Esempio n. 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);
            }
        }
Esempio n. 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));
        }