public bool Execute() { Console.WriteLine("Discovering Files..."); var patterns = ps.settings.Patterns; var dbFiles = db.files; var files = Directory.GetFiles(ps.settings.FolderInput); var filesAdded = false; foreach (var f in files) { var fLower = f.ToLower(); FileInfo fileInfo = new FileInfo(f); if (!ps.settings.AllowedExt.Contains(fileInfo.Extension)) { continue; } foreach (var p in patterns) { if (p.Match(fileInfo.Name)) { if (!dbFiles.ContainsKey(fileInfo.Name)) { dbFiles.TryAdd(fileInfo.Name, new AnimeFile(fileInfo.FullName, FileStatus.DISCOVER)); filesAdded = true; } if (dbFiles[fileInfo.Name].fileStatus == FileStatus.DOWNLOAD) { dbFiles[fileInfo.Name].fileStatus = FileStatus.DISCOVER; filesAdded = true; } } } } if (filesAdded) { db.FlushData(); } return(true); }
public void Execute() { Console.WriteLine("Downloading Files..."); var packs = gfpat.Execute(); var limitPacks = packs.Take(5); foreach (var pack in limitPacks) { ircClient.SendMessageToAll(pack.ToString()); Thread.Sleep(10000); var down = ircClient.CheckIfDownloading(); while (ircClient.CheckIfDownloading()) { Thread.Sleep(5000); } // Check filesize is correct before marking as done FileInfo fi = new FileInfo(Path.Combine(ps.settings.FolderInput, pack.Filename)); double packSize = 0; Double.TryParse(pack.Size, out packSize); // make sure the file exists and only differs by 1 mb (rounding) if (fi.Exists && Math.Abs(packSize - fi.Length / (1024 * 1024)) < 2) { db.files.TryAdd(fi.Name, new AnimeFile(fi.FullName)); db.FlushData(); } else { Console.WriteLine("Could not download: " + pack.Filename); } } ircClient.StopClient(); }
public bool Execute(List <AnimeFile> encodeFiles) { Console.WriteLine(string.Format("Encoding {0} Files...", encodeFiles.Count)); foreach (var f in encodeFiles) { EncodeActivityTask task = new EncodeActivityTask(); FileInfo fi = new FileInfo(f.filePath); string outFile = Path.Combine(ps.settings.FolderOutput, fi.Name); Console.WriteLine("Encoding - " + fi.Name); task.Execute(ps.settings, f.filePath, outFile); f.fileStatus = FileStatus.ENCODE; f.encodePath = outFile; db.FlushData(); } return(true); }
public bool Execute(AnimeFile file) { UserCredential credential; using (var stream = new FileStream("credentials.json", FileMode.Open, FileAccess.Read)) { // The file token.json stores the user's access and refresh tokens, and is created // automatically when the authorization flow completes for the first time. string credPath = "token.json"; credential = GoogleWebAuthorizationBroker.AuthorizeAsync( GoogleClientSecrets.Load(stream).Secrets, Scopes, "user", CancellationToken.None, new FileDataStore(credPath, true)).Result; } // Create Drive API service. var service = new DriveService(new BaseClientService.Initializer() { HttpClientInitializer = credential, ApplicationName = ApplicationName, }); /* * var req = service.Files.List(); * req.PageSize = 30; * req.Fields = "nextPageToken, files(id, name, parents)"; * * var resf = req.Execute().Files; */ FileInfo fi = new FileInfo(file.encodePath); fileSize = fi.Length; var uploadStream = new FileStream(file.encodePath, FileMode.Open, FileAccess.Read); var insertRequest = service.Files.Create( new GFile { Name = fi.Name, Parents = new List <string> { "0Bwyizu5RNSItY3N4WXExVHhPUnM" } }, uploadStream, "application/octet-stream" ); insertRequest.ChunkSize = ChunkSize * 1024 * 1024; insertRequest.ProgressChanged += Upload_ProgressChanged; insertRequest.ResponseReceived += Upload_ResponseReceived; Console.WriteLine("Uploading: " + fi.Name); var createFileTask = insertRequest.UploadAsync(); createFileTask.ContinueWith(t => { uploadStream.Dispose(); }).Wait(); if (createFileTask.Result.Status != UploadStatus.Failed) { file.fileStatus = FileStatus.UPLOAD; db.FlushData(); } return(true); }