Exemplo n.º 1
0
        public static async Task <FFProbeResult> Probe(string filename)
        {
            ExternalProgramExecution.RunProgramReturnValue retval = await VodArchiver.ExternalProgramExecution.RunProgram(
                "ffprobe",
                new string[] {
                "-show_format",
                "-show_streams",
                "-print_format", "json",
                filename
            }
                );

            JObject jo         = JObject.Parse(retval.StdOut);
            var     jsonFormat = jo["format"];

            string               path      = System.IO.Path.GetFullPath(filename);
            DateTime             timestamp = System.IO.File.GetCreationTimeUtc(filename);
            ulong                filesize  = (ulong)jsonFormat["size"];
            ulong                bitrate   = (ulong)jsonFormat["bit_rate"];
            TimeSpan             duration  = TimeSpan.FromSeconds((double)jsonFormat["duration"]);
            List <FFProbeStream> streams   = new List <FFProbeStream>();

            foreach (JToken jsonStream in jo["streams"])
            {
                streams.Add(new FFProbeStream()
                {
                    Index     = (uint)jsonStream["index"],
                    CodecTag  = Util.ParseDecOrHex(jsonStream["codec_tag"].ToString()),
                    CodecType = jsonStream["codec_type"].ToString(),
                    Duration  = jsonStream["duration"] != null ? TimeSpan.FromSeconds((double)jsonStream["duration"]) : (TimeSpan?)null,
                    Framerate = jsonStream["r_frame_rate"] != null ? ParseFramerate((string)jsonStream["r_frame_rate"]) : 0.0f,
                });
            }

            return(new FFProbeResult()
            {
                Path = path,
                Timestamp = timestamp,
                Filesize = filesize,
                Bitrate = bitrate,
                Duration = duration,
                Streams = streams,
            });
        }
Exemplo n.º 2
0
        public static async Task <List <IVideoInfo> > RetrieveVideosFromParameterString(string parameter, bool flat, string usernameIfNotInJson)
        {
            string raw = "";

            try {
                List <string> args = new List <string>();
                if (flat)
                {
                    args.Add("--flat-playlist");
                }
                args.Add("--ignore-errors");
                args.Add("-J");
                args.Add(parameter);
                ExternalProgramExecution.RunProgramReturnValue data = await ExternalProgramExecution.RunProgram(@"yt-dlp", args.ToArray());

                raw = data.StdOut;
            } catch (ExternalProgramReturnNonzeroException ex) {
                // try anyway, this gets thrown when a video is unavailable for copyright reasons
                raw = ex.StdOut;
            }
            var json               = JObject.Parse(raw);
            var entries            = json["entries"];
            List <IVideoInfo> list = new List <IVideoInfo>();

            foreach (var entry in entries)
            {
                try {
                    var d = ParseFromJson(entry, flat, usernameIfNotInJson);
                    if (d.success)
                    {
                        list.Add(d.info);
                    }
                } catch (Exception ex) {
                    Console.WriteLine("Failed to parse video from Youtube: " + ex.ToString());
                }
            }
            return(list);
        }