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); } }
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)); }
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); } } }