Esempio n. 1
0
        private async Task <string> UploadGoogleVideoAsync(Task <string> trimAndSilence, Task getCreationTime)
        {
            string videoUrl = "";

            try
            {
                await  getCreationTime;
                string processedVideoPath = await trimAndSilence;

                Logger.Log($"Uploading video to Google {processedVideoPath}...");
                GoogleStorage storage = new GoogleStorage();
                videoUrl = await storage.UploadVideoAsync(processedVideoPath, _creationTime);

                Logger.Log($"Video uploaded to Google: {videoUrl}");
            }
            catch (Exception e)
            {
                Logger.Log($"Failed to upload to google, but ignoring.", e);
            }

            return(videoUrl);
        }
Esempio n. 2
0
        private static async Task UploadLatestToGoogleAsync(int count)
        {
            var videos = await LoadVideosAsync();

            var sortedVideos = SortVideos(videos);

            Logger.Log($"Found {videos.Count} videos.");

            GoogleStorage         gStore      = new GoogleStorage();
            Storage               storage     = new Storage();
            List <Task <string> > uploadTasks = new List <Task <string> >();

            foreach (var e in sortedVideos)
            {
                Console.WriteLine("\t{0}\t{1}", e.RecordedTime, e.Url);
                uploadTasks.Add(UploadToGoogle(e));
            }

            Task.WaitAll(uploadTasks.ToArray());
            Logger.Log("Upload complete.");

            async Task <string> UploadToGoogle(SkiVideoEntity e)
            {
                string localPath = await Task <string> .Run(() => DownloadVideo(e.Url));

                e.HotUrl = await gStore.UploadVideoAsync(localPath, e.RecordedTime);

                storage.UpdateMetadata(e);
                Logger.Log($"Google HotUrl updated {e.HotUrl}");
                return(e.HotUrl);
            }

            IEnumerable <SkiVideoEntity> SortVideos(IEnumerable <SkiVideoEntity> videos)
            {
                return(videos.OrderByDescending(v => v.RecordedTime)
                       .Where(v => v.HotUrl == null)
                       .Take(count));
            }
        }