Example #1
0
 public Anime ClosestAnime(IEnumerable <Anime> animes, AnimeFile file)
 {
     return(animes
            .Select(anime => new StringDistance <Anime>(anime, file.Name,
                                                        string.IsNullOrEmpty(anime.Details.PreferredSearchTitle)
                 ? anime.Name
                 : anime.Details.PreferredSearchTitle))
            .Where(pair => pair.Distance <= 10)
            .OrderBy(pair => pair.Distance)
            .FirstOrDefault()?.Item);
 }
Example #2
0
        public static void MoveFile(AnimeFile file, string startPath, string movePath)
        {
            var relative = string.Join(Path.DirectorySeparatorChar.ToString(),
                                       file.Path.Split(Path.DirectorySeparatorChar)
                                       .Skip(startPath.Split(Path.DirectorySeparatorChar).Length));
            var newPath   = Path.Combine(movePath, relative);
            var fileDepth = relative.Split(Path.DirectorySeparatorChar);

            if (fileDepth.Length > 1)
            {
                var added = string.Join(Path.DirectorySeparatorChar.ToString(),
                                        fileDepth.Take(fileDepth.Length - 1));
                Directory.CreateDirectory(Path.Combine(movePath, added));
            }
            Directory.Move(file.Path, newPath);
        }
        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);
        }