You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

150 lines
4.0 KiB
Julia

12 months ago
# То же самое, но на julia
using Logging
12 months ago
using Printf
using Dates
12 months ago
using CRC32c
using JSON
using Base.Threads
12 months ago
12 months ago
debuglogger = ConsoleLogger(stderr, Logging.Debug)
global_logger(debuglogger)
12 months ago
# правильный перевод!
function humanbytes(B)
"""Return the given bytes as a human friendly KB, MB, GB, or TB string."""
B = float(B)
KB = float(1024)
MB = float(KB ^ 2) # 1,048,576
GB = float(KB ^ 3) # 1,073,741,824
TB = float(KB ^ 4) # 1,099,511,627,776
if B < KB
return @sprintf("%.2f Bytes", B)
elseif KB <= B && B < MB
return @sprintf("%.2f KB", (B / KB))
elseif MB <= B && B < GB
return @sprintf("%.2f MB", (B / MB))
elseif GB <= B && B < TB
return @sprintf("%.2f GB", (B / GB))
elseif TB <= B
return @sprintf("%.2f TB", (B / KB))
end
end
12 months ago
function new_name(name)
matches = Dict(
"Сек" => r"(.+) Сек.*",
"Сцен" => r"(.+) Сцен.*",
"Голые" => r"(.+) Голые.*",
"Откро" => r"(.+) Откро.*",
"Посте" => r"(.+) Посте.*",
"Изнас" => r"(.+) Изнас.*",
"Инцес" => r"(.+) Инцес.*",
"Лесб" => r"(.+) Лесб.*",
"Эро" => r"(.+) Эро.*"
)
for (k, v) in matches
if contains(name, k)
base, ext = splitext(name)
new_name = replace(base, v => s"\1")
# @debug base, new_name
return string(new_name, ext)
end
end
return name
end
function valid_file(filename)
valids = [".mp4", ".webm", ".mpeg"]
_, ext = splitext(filename)
return ext in valids
end
# file_info function returns information from file
function file_info(filename)
_, ext = splitext(filename)
info = stat(filename)
12 months ago
crc = CRC32c.crc32c(open(filename, "r"))
12 months ago
m = Dict(
"filename" => filename,
"size" => info.size,
12 months ago
"hsize" => humanbytes(info.size),
12 months ago
"mtime" => info.mtime,
"ctime" => info.ctime,
12 months ago
"htime" => Dates.format(Dates.unix2datetime(info.ctime), "dd.mm.yyyy"),
12 months ago
"ext" => ext,
12 months ago
"crc"=> Int(crc),
12 months ago
)
return m
end
12 months ago
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"])
return out
end
12 months ago
function check_file(filename)
12 months ago
# println(filename)
info = file_info(filename)
meta = file_meta(filename)
# println(info)
return meta
12 months ago
end
12 months ago
function parallel_execution()
nthreads = Threads.nthreads() # Получаем количество доступных потоков
println("Running parallel execution: $(nthreads)")
results = Vector{Int}(undef, nthreads) # Создаем массив для хранения результатов
# Создаем и запускаем потоки
for i in 1:nthreads
results[i] = Threads.@spawn begin
# Код, который нужно выполнить параллельно
return i * 2
end
end
12 months ago
12 months ago
# Получаем результаты из потоков
for i in 1:nthreads
println("Результат из потока $i: $(fetch(results[i]))")
end
12 months ago
end
12 months ago
function main()
dir = "d:\\vids\\ero"
@info "Обработка каталога: $dir"
files = readdir(dir, join=true)
n = length(files)
println("всего: $n files")
@time begin
@sync begin
for file in filter(valid_file, files)
@async begin
meta = @spawn check_file(file)
println(file)
end
end
end
end
# @sync begin
# for file in filter(valid_file, files)
# @async begin
# meta = check_file(file)
# end
# end
# end
println("обработано")
end
# -------- основная программа --------------
# parallel_execution()
main()