예제 #1
0
        public void SetGDriveUrls1()
        {
            var    gDriveService = new GDriveService();
            string search        = "title contains '.mp3'";

            gDriveService.ProcessFiles(search, SetGDriveUrl, null);
        }
예제 #2
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);
            }
        }
예제 #3
0
        public void InsertRecentSongs()
        {
            var    gDriveConsole = new GDriveConsole.GDriveConsole();
            string search        = "mimeType = 'audio/mpeg'";
            var    gDriveService = new GDriveService();

            gDriveService.ProcessFiles(search, gDriveConsole.DownloadAndInsert, 100);
        }
예제 #4
0
        public void PopulateGDriveQueue()
        {
            Debug.WriteLine("PopulateGDriveQueue starting");

            var    gDriveService = new GDriveService();
            string search        = "";

            gDriveService.ProcessFiles(search, PopulateQueue, null);
        }
예제 #5
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);
            }
        }
예제 #6
0
        static void Main(string[] args)
        {
            Debug.WriteLine("Starting");
            var gDriveService = new GDriveService();
//            string search = "title contains '.mp3'";
            string search = "";

            gDriveService.ProcessFiles(search, SetGDriveUrl, null);
            Debug.WriteLine("Finished");
        }
예제 #7
0
        public void CountGDriveFiles()
        {
            var gDriveService = new GDriveService();
            //            string search = "title contains '.mp3'";
            //            string search = "mimeType contains 'mp3'";
            string search = "";

            gDriveService.ProcessFiles(search, CountFile, null);
            testContextInstance.WriteLine("Count: {0}", gDriveFileCount);
        }
        public void ListAllFilesTest()
        {
            var gDriveService = new GDriveService();

            // act
            var result = gDriveService.ListAllFiles();

            // assert

            Assert.IsInstanceOf <List <Google.Apis.Drive.v3.Data.File> >(result);
        }
예제 #9
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));
        }
예제 #10
0
        public async void TestDownload()
        {
            var service  = new GDriveService();
            var id       = "1e7NjXmSbmVk1bZYNTFXF8CoYWtg3dBcg";
            var expected = "hello world";

            var filePath = await service.DownloadFile(id);

            Assert.NotNull(filePath);

            var content = await File.ReadAllTextAsync(filePath);

            Assert.Equal(expected, content);

            if (File.Exists(filePath))
            {
                File.Delete(filePath);
            }
        }
예제 #11
0
        public void GetGDriveFiles()
        {
            string search        = "title='Ends.mp3'";
            var    gDriveService = new GDriveService();
            var    files         = gDriveService.GetFiles(search);

            foreach (var file in files)
            {
                testContextInstance.WriteLine("{0}", file.DownloadUrl);

                string downloadUrl = string.Format("https://googledrive.com/host/{0}", file.Id);

                WebClient webClient = new WebClient();
                string    filename  = System.IO.Path.GetTempFileName();
                webClient.DownloadFile(downloadUrl, filename);
                System.IO.FileInfo fileInfo = new System.IO.FileInfo(filename);
                testContextInstance.WriteLine("{0}", fileInfo.Length);
            }
        }
예제 #12
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);
                }
            }
        }
예제 #13
0
        public void SetGDriveUrls()
        {
            string folder       = @"E:\Gdrive\Music";
            string musicFolder  = @"E:\Gdrive\Music";
            var    musicDao     = GetMusicDao();
            var    allSongFiles = musicDao.GetSongFiles(folder);

            var musicFiles = from musicFile in allSongFiles
                             where musicFile.IsMp3File()
                             select musicFile;

            var songsWithDbInfo = from song in musicFiles
                                  select musicDao.GetSongByLocation(song.LOCATION);

            var existingFiles = from song in songsWithDbInfo
                                where song != null
                                select song;

            existingFiles = from song in existingFiles
                            where song.GDRIVE == null
                            select song;

            var gDriveService = new GDriveService();

            foreach (var song in existingFiles)
            {
                char[]   c        = { '\\' };
                string[] s        = song.LOCATION.Split(c);
                string   filename = s[s.Length - 1];
                string   search   = string.Format("title='{0}'", filename);
                var      files    = gDriveService.GetFiles(search);
                foreach (var file in files)
                {
                    testContextInstance.WriteLine("{0}", file.WebContentLink);

                    try
                    {
                        FileInfo fileInfo = null;
                        if (files.Count > 1)
                        {
                            int    start            = song.LOCATION.IndexOf("\\Music\\");
                            string adjustedFilename = musicFolder + song.LOCATION.Substring(start + 6);
                            fileInfo = new FileInfo(adjustedFilename);
                        }
                        if ((fileInfo == null) || (fileInfo.Length == file.FileSize))
                        {
                            testContextInstance.WriteLine("Found");
                            using (var context = new MusicEntities1())
                            {
                                var currentSong = context.SONG.Single(s1 => s1.ID == song.ID);
                                currentSong.GDRIVE = file.WebContentLink;
                                context.SaveChanges();
                                testContextInstance.WriteLine("{0} {1}", song.LOCATION, file.DownloadUrl);
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        testContextInstance.WriteLine("Error: {0} {1}", filename, ex.Message);
                    }
                }
            }
        }