Написал для себя скрипт предотвращающий повторную загрузку аудио с сайта vk.com
--[[ <HCExtension>
@name CacheFix.Audio.VK
@author Anymore
@version 0.1
@description n/a
@rule ^http://a.vk.local
@rule ^http://vk\.com/
@event BeforeAnswerBodySend/BeforeAnswerBodySend
@event Init/Init
@event URLToFileNameConverting/URLToFileNameConverting
@event RequestHeaderReceived/RequestHeaderReceived
</HCExtension> ]]
function Init()
--hc.put_msg(1, 'init a.vk.local')
end
function BeforeAnswerBodySend()
if re.find(hc.answer_header, [[Content-Type: text]]) then
i = hc.monitor_index
ig = 'vkcc'..i
if hc.last_part then
ab = hc.get_global(ig)..hc.answer_body
ab = re.replace(ab, [[id="audio_info(\d+)_(\d+)" value="http://]], [[id="audio_info\1_\2" value="http://a.vk.local/\1_\2/]], true)
ab = re.replace(ab, [['(\d+)','(\d+)','http://]], [['\1','\2','http://a.vk.local/\1_\2/]], true)
ab = re.replace(ab, [["(\d+)_(\d+)":\["http:\\/\\/]], [["\1_\2":["http:\/\/a.vk.local\/\1_\2\/]], true)
ab = re.replace(ab, [[id="audio_info(\d+)_(\d+)_(\d+)" value="http://]], [[id="audio_info\1_\2_\3" value="http://a.vk.local/\1_\2/]] , true)
hc.answer_body = ab
hc.set_global(ig, nil)
else
ab = hc.get_global(ig)
if ab == nil then ab = '' end
hc.set_global(ig, ab..hc.answer_body)
hc.answer_body = nil
end
end
end
function URLToFileNameConverting()
ai = hc.get_global('a_vk_'..hc.monitor_index)
if not ( ai == nil ) then
ap = hc.cache_path..'a.vk.local\\'..ai..'.mp3' -- ap содержит путь к файлу в кеше
hc.preform_cache_file_name(ap)
hc.set_global('a_vk_'..hc.monitor_index, nil) --закоментированно для лога
end
end
function RequestHeaderReceived()
ai = re.replace(hc.url, [[http://a.vk.local/(\d+)_(\d+)/(.*)$]], [[\1_\2]], false)
if ai ~= hc.url then
hc.set_global('a_vk_'..hc.monitor_index, ai)
end
hc.request_header = re.replace(hc.request_header, [[http://a.vk.local/(\d+)_(\d+)/]], [[http://]], false)
end