Exemplo n.º 1
0
        private static string UploadVideo(VimeoApi vimeo, string videoFile, string videoName, string videoDescr)
        {
            Console.WriteLine("Uploading {0}", videoFile);
            long t0    = Environment.TickCount;
            long lastt = t0;
            long lastb = 0;
            var  s     = vimeo.UploadVideo(videoFile, videoName, videoDescr,
                                           (n1, n2) =>
            {
                if (n1 - lastb > 0.1)
                {
                    var speed      = ((double)(n1 - lastb) / (Environment.TickCount - lastt)) / 1000;
                    var tremaining = Math.Truncate((n2 - n1) / (1048576 * speed));
                    Console.WriteLine("Sent: {0}MB - Total: {1}MB - Speed: {2:0.##}MB/Sec - Remaining: {3}",
                                      Math.Truncate((decimal)n1 / 1048576),
                                      Math.Truncate((decimal)n2 / 1048576),
                                      speed,
                                      String.Format("{0:00}:{1:00}:{2:00}", tremaining / 3600, (Math.Floor(tremaining / 60)) % 60, tremaining % 60));
                    lastb = n1;
                    lastt = Environment.TickCount;
                }
            });

            Console.WriteLine("Upload completed in {0}Sec", Math.Truncate((decimal)Environment.TickCount - t0) / 1000);
            Console.WriteLine("Video Uploaded: {0}", s);

            return(s);
        }
Exemplo n.º 2
0
        private static void MonitorFld(VimeoApi vimeo, string ChkFld, string DestFld)
        {
            var fs = Directory.GetFiles(ChkFld);

            foreach (var f in fs)
            {
                if (videoExtensions.Contains(Path.GetExtension(f).ToUpper()))
                {
                    string vname   = Path.GetFileNameWithoutExtension(f);
                    var    videoId = UploadVideo(vimeo, f, vname, "");

                    string imm = fs.First(s =>
                                          Path.GetFileNameWithoutExtension(s) == vname && f != s && Path.GetExtension(s).ToUpper() == ".JPG"
                                          );
                    if (imm != null || imm != "")
                    {
                        Thread.Sleep(1000);
                        Console.WriteLine("Setting picture");
                        vimeo.SetPicture(videoId, imm);
                    }

                    Console.WriteLine("Moving file {0}", Path.GetFileName(f));
                    GC.Collect();
                    GC.WaitForPendingFinalizers();
                    File.Move(f, DestFld + "\\" + Path.GetFileName(f));
                    if (imm != null || imm != "")
                    {
                        File.Move(imm, DestFld + "\\" + Path.GetFileName(imm));
                    }
                    Console.WriteLine("Done");
                }
            }
        }
Exemplo n.º 3
0
        static void Main(string[] args)
        {
            try
            {
                ProgramOptions opt = ReadOptions(args);

                if (opt.Command == CMD_HELP)
                {
                    Console.WriteLine(VimeoUploaderRes.About);
                    return;
                }

                VimeoApi vimeo = new VimeoApi(opt.Token);

                if (opt.Command == CMD_LV)
                {
                    Console.WriteLine("Getting list of uploaded videos");
                    displayVideos(vimeo.GetVideos());
                }

                else if (opt.Command == CMD_VIDEOINFO)
                {
                    Console.WriteLine("Getting information of video {0}", opt.VideoId);
                    displayVideoDetail(vimeo.GetVideoDetails(opt.VideoId));
                }

                else if (opt.Command == CMD_STATUS)
                {
                    Console.WriteLine("Getting status of video {0}", opt.VideoId);
                    Console.WriteLine(vimeo.GetVideoStatus(opt.VideoId));
                }

                else if (opt.Command == CMD_USERINFO)
                {
                    Console.WriteLine("Getting user information");
                    displayUserInfo(vimeo.GetUserInfo(), false);
                }

                else if (opt.Command == CMD_QUOTA)
                {
                    Console.WriteLine("Getting quota information");
                    displayUserInfo(vimeo.GetQuota(), true);
                }

                else if (opt.Command == CMD_UPLOAD)
                {
                    UploadVideo(vimeo, opt.FileVideo, opt.Name, opt.Description);
                    Console.WriteLine("Done");
                }

                else if (opt.Command == CMD_DELETE)
                {
                    Console.WriteLine("Are you sure to delete video {0}?", opt.VideoId);
                    Console.Write("Press Y to confirm: ");
                    var x = Console.ReadKey();
                    if (Char.ToUpper(x.KeyChar) == 'Y')
                    {
                        Console.WriteLine("\nDeleting video {0}", opt.VideoId);
                        vimeo.DeleteVideo(opt.VideoId);
                        Console.WriteLine("Done");
                    }
                }

                else if (opt.Command == CMD_EDT)
                {
                    Console.WriteLine("Setting information for video {0}", opt.VideoId);
                    vimeo.SetVideoMetadata(opt.VideoId, opt.Name, opt.Description);
                    Console.WriteLine("Done");
                }

                else if (opt.Command == CMD_SETPIC)
                {
                    Console.WriteLine("Setting picture for video {0}", opt.VideoId);
                    if (opt.FilePicture != null || opt.FilePicture != "")
                    {
                        vimeo.SetPicture(opt.VideoId, opt.FilePicture);
                    }
                    else
                    {
                        vimeo.SetPicture(opt.VideoId, opt.TimePicture);
                    }
                    Console.WriteLine("Done");
                }

                else if (opt.Command == CMD_SAVETOKEN)
                {
                    vimeo.SaveAuth();
                    Console.WriteLine("Done");
                }

                else if (opt.Command == CMD_PULLPLD)
                {
                    if (opt.CheckInterval == null || opt.CheckInterval == 0)
                    {
                        opt.CheckInterval = 5000;
                    }
                    Console.WriteLine("Monitor folder: {0} - Destination Folder: {1}", opt.CheckFolder, opt.DestFolder);
                    while (true)
                    {
                        MonitorFld(vimeo, opt.CheckFolder, opt.DestFolder);
                        Thread.Sleep(opt.CheckInterval);
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("Error: {0}", e.Message);
            }
            return;
        }