diff --git a/test.jl b/test.jl index acec3c0..5f6e1f1 100644 --- a/test.jl +++ b/test.jl @@ -34,6 +34,22 @@ function humanbytes(B) end end +function humanbitrate(s) + """ + The function "humanbitrate" takes a string representing a bitrate in the format "a/b" and returns + the bitrate as a float with one decimal place. + + :param s: The parameter "s" is a string that represents a fraction in the format "a/b", where "a" + and "b" are numbers + :return: the bitrate as a string. + """ + items = split(s, "/") + a = parse(Float64, items[1]) + b = parse(Float64, items[2]) + bitrate = @sprintf("%8.1f", (a / b)) + return strip(bitrate) +end + function new_name(name) matches = Dict( "Сек" => r"(.+) Сек.*", @@ -58,7 +74,7 @@ function new_name(name) end function valid_file(filename) - valids = [".mp4", ".webm", ".mpeg"] + valids = [".avi", ".mkv", ".mp4", ".webm", ".mpeg"] _, ext = splitext(filename) return ext in valids end @@ -74,62 +90,57 @@ function file_info(filename) "hsize" => humanbytes(info.size), "mtime" => info.mtime, "ctime" => info.ctime, - "htime" => Dates.format(Dates.unix2datetime(info.ctime), "dd.mm.yyyy"), + "hmtime" => Dates.format(Dates.unix2datetime(info.mtime), "dd.mm.yyyy"), + "hctime" => Dates.format(Dates.unix2datetime(info.ctime), "dd.mm.yyyy"), "ext" => ext, "crc"=> Int(crc), ) return m end +# возвращает индекс видео-потока +function get_video_stream(stream) + for i in eachindex(stream) + if stream[i]["codec_type"] == "video" + return i + end + end + return -1 +end + +# Потоки могут быть перепутаны, поэтму нужно сначала +# определить индекс видео-потока function file_meta(filename) cmd = `ffprobe -v quiet -print_format json -show_format -show_streams "$filename"` out = read(cmd, String) data = JSON.parse(out) - # println(data["format"]["duration"]) + n = get_video_stream(data["streams"]) + dur = parse(Float64, data["format"]["duration"]) + hdur = Dates.unix2datetime(dur) + res = Dict( - "duration" => data["format"]["duration"], + "duration" => hdur, + "hduration" => Dates.format((hdur), "HH:MM:SS"), + "width" => data["streams"][n]["width"], + "height" => data["streams"][n]["height"], + "bit_rate" => humanbitrate(data["streams"][n]["avg_frame_rate"]), + "codec" => data["streams"][n]["codec_name"], + # "aspect_ratio" => data["streams"][n]["display_aspect_ratio"], ) return res end function check_file(filename) # println(filename) - v1 = file_info(filename) v2 = file_meta(filename) + v1 = file_info(filename) result = merge!(v1, v2) # println(info) return result end -function parallel_execution() - nthreads = Threads.nthreads() # Получаем количество доступных потоков - println("Running parallel execution: $(nthreads)") - results = Vector{Int}(undef, nthreads) # Создаем массив для хранения результатов - - # Создаем и запускаем потоки - v = 0 - @sync begin - for i in 1:24 - Threads.@spawn begin - # Код, который нужно выполнить параллельно - # return i * 2 - v += 1 - println("Hello from ", Threads.threadid()) - end - end - end - - println("loop finished: ", v) - - # Получаем результаты из потоков - # for i in 1:nthreads - # # v = results[i] - # println("Результат из потока $i: $v") - # end -end - function main() - dir = "d:\\vids\\ero" + dir = "d:\\torrent" @info "Обработка каталога: $dir" files = readdir(dir, join=true) @@ -138,12 +149,12 @@ function main() @time begin @sync begin - for file in filter(valid_file, files) - Threads.@spawn begin + for file in filter(valid_file, files) + Threads.@spawn begin meta = check_file(file) println(meta) - end - end + end + end end end @@ -163,6 +174,7 @@ function openDB() println(s.ext,' ', s.newurl) end end + # -------- основная программа -------------- # parallel_execution() # openDB()