-- видеоскрипт для https://cloud.mail.ru (29/11/2017) -- открывает подобные ссылки -- https://cloud.mail.ru/public/GuR9/CpdDRwxu1 -- https://cloud.mail.ru/public/LHJZ/DGrDhjz72 -- https://cloud.mail.ru/public/4VZcMg86gm1s/Аудиокниги ------------------------------------------------------------------------------------------ local makepls = 0 -- создать плейлист m3u: 0 - нет, 1 - в папке Work ------------------------------------------------------------------------------------------ local nazv = '' -- название: '' - авто, 'ваше назавние' ------------------------------------------------------------------------------------------ require('json') if m_simpleTV.Control.ChangeAdress ~= 'No' then return end local inAdr = m_simpleTV.Control.CurrentAdress if inAdr == nil then return end if not inAdr:match('^https://cloud%.mail%.ru/public/%w+') then return end m_simpleTV.Control.ChangeAdress = 'Yes' m_simpleTV.Control.CurrentAdress = 'error' local session = m_simpleTV.WinInet.New('Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.2785.143 Safari/537.36') if session == nil then return end m_simpleTV.WinInet.SetOptionInt(session, 2, 5000, 0) m_simpleTV.WinInet.SetOptionInt(session, 6, 5000, 0) m_simpleTV.WinInet.SetOpenRequestFlags(session, 0x00800000 + 0x00002000 + 0x00001000) local function getmailkey() if m_simpleTV.User == nil then m_simpleTV.User = {} end if m_simpleTV.User.Mailru == nil then m_simpleTV.User.Mailru = {} end if m_simpleTV.User.Mailru.key ~= nil then return m_simpleTV.User.Mailru.key end local session = m_simpleTV.WinInet.New('Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.2785.143 Safari/537.36') if session == nil then return '' end m_simpleTV.WinInet.SetOptionInt(session, 2, 5000, 0) m_simpleTV.WinInet.SetOptionInt(session, 6, 8000, 0) local rc, answer = m_simpleTV.WinInet.Request(session, {url = 'https://cloud.mail.ru/api/v2/tokens/download', method = 'post', headers = 'Content-Type: application/x-www-form-urlencoded; charset=UTF-8', body = 'api=2&build=release-33.201602101549'}) m_simpleTV.WinInet.Close(session) if rc ~= 200 then return '' end -- debug_in_file('получаем в function getmailkey ответ\n' .. answer .. '\n\n', m_simpleTV.Common.GetMainPath(1) .. 'debug_cloud_mailru.txt') local token = answer:match('token":"(.-)"') if token == nil then return '' end m_simpleTV.User.Mailru.key = '?key=' .. token -- debug_in_file('получаем в function getmailkey Mailru.key = ' .. m_simpleTV.User.Mailru.key .. '\n\n', m_simpleTV.Common.GetMainPath(1) .. 'debug_cloud_mailru.txt') return m_simpleTV.User.Mailru.key end local function CloudMailCleanAddress(address) address = address:gsub(' ', '%%20'):gsub('%(', '%%28'):gsub('%)', '%%29'):gsub('%#', '%%23'):gsub("'", '%%27') address = address:gsub('.', function (c) if string.byte(c) > 127 then return string.format("%%%02X", string.byte(c)) else return c end end) -- debug_in_file('получаем в function CloudMailCleanAddress address = ' .. address .. '\n\n', 'C:\\T\\Mailru.txt') return address end local function FindingExt(link) local ext = link:match('^.+(%.cue)$') or link:match('^.+(%.txt)$') or link:match('^.+(%.doc).$') or link:match('^.+(%.log)$') or link:match('^.+(%.jpg)$') return ext ~= nil end if m_simpleTV.Control.CurrentAddress_UTF8 ~= nil then inAdr = CloudMailCleanAddress(m_simpleTV.Control.CurrentAddress_UTF8) end local rc, answer = m_simpleTV.WinInet.Request(session, {url = inAdr}) if rc ~= 200 then m_simpleTV.WinInet.Close(session) m_simpleTV.OSD.ShowMessage_UTF8('cloud_mailru ошибка[1]-' .. rc, 255, 10) return end -- debug_in_file('получаем в ответе inAdr answer\n' .. answer .. '\n\n', m_simpleTV.Common.GetMainPath(1) .. 'debug_cloud_mailru.txt') local tmp = answer:match('cloudBuilder%((.-)%);') if tmp == nil then return end tmp = string.gsub(tmp, '%[%]', '""') tmp = string.match(tmp, 'window%[.-%],({.+}),') -- debug_in_file('находим tmp в ответе inAdr\n' .. tmp .. '\n\n', m_simpleTV.Common.GetMainPath(1) .. 'debug_cloud_mailru.txt') local title = 'Выберите' local t = json.decode(tmp) if t == nil then m_simpleTV.OSD.ShowMessage_UTF8('cloud_mailru ошибка[2]', 255, 10) return end if m_simpleTV.Control.CurrentTitle_UTF8 ~= nil then if (t.folder.count ~= nil) and (t.folder.count.files == 1) then title = t.folder.list[1].name else title = t.folder.name end end local tab, i, n = {}, 1, 1 local IndexToplay, retAdr, is_find = 0, nil, false if makepls ~= 0 and title ~= nil then if nazv == '' then nazv = title end nfile = nazv:gsub('["\/:?|*<>]', ' ') nfile = m_simpleTV.Common.string_fromUTF8(nfile) debug_in_file('#EXTM3U' .. '\n' , m_simpleTV.Common.GetMainPath(1) .. nfile .. '.m3u') end while true do if t.folder.list == nil or t.folder.list[i] == nil then break end local name = t.folder.list[i].name local kind = t.folder.list[i].kind local link = t.folder.list[i].weblink .. getmailkey() tab[n] = {} tab[n].Id = n tab[n].Name = name tab[n].Kind = kind if kind == 'folder' then local count = 0 if t.folder.list[i].count.folders ~= nil then count = count + t.folder.list[i].count.folders end if t.folder.list[i].count.files ~= nil then count = count + t.folder.list[i].count.files end if count == 0 then kind = 'empty ' .. kind end tab[n].Name = tab[n].Name .. ' [' .. count .. ']' tab[n].Adress = CloudMailCleanAddress('https://cloud.mail.ru/public/' .. link) elseif kind == 'file' then is_find = FindingExt(link) if is_find == true then is_find = false tab[n] = nil n = n - 1 else tab[n].Adress = CloudMailCleanAddress('https://datacloudmail.ru/weblink/get/' .. link) local root = t.folder.list[i].parent --if root == '/' then tab[n].Adress = tab[n].Adress .. '/' .. CloudMailCleanAddress(tab[n].Name) end if makepls ~= 0 and title ~= nil then debug_in_file('#EXTINF:-1 group-title="' .. nazv .. '",' .. tab[n].Name .. '\n' .. tab[n].Adress .. '\n' , m_simpleTV.Common.GetMainPath(1) .. nfile .. '.m3u') end if retAdr == nil then IndexToplay = n - 1 retAdr = tab[n].Adress end end end n = n + 1 i = i + 1 end -- if retAdr ~= nil then debug_in_file('получаем retAdr = ' .. retAdr .. '\n\n', m_simpleTV.Common.GetMainPath(1) .. 'debug_cloud_mailru.txt') end -- do return end if retAdr == nil then if #tab > 0 then local _, id = m_simpleTV.OSD.ShowSelect_UTF8(title, 0, tab, 0, 1) if id == nil then id = 1 end if tab[id] == nil then return end retAdr = tab[id].Adress m_simpleTV.Control.CurrentAdress = 'wait' m_simpleTV.Control.PlayAddress(retAdr) return end m_simpleTV.OSD.ShowMessage_UTF8('Медиа файлов не найдено', 102200, 5) m_simpleTV.Control.CurrentAdress = 'error' return end m_simpleTV.Control.CurrentTitle_UTF8 = title if n > 2 then m_simpleTV.OSD.ShowSelect_UTF8(title, IndexToplay, tab, 10000) end m_simpleTV.WinInet.Close(session) m_simpleTV.Control.CurrentAdress = retAdr -- debug_in_file('получаем CurrentAdress = ' .. retAdr .. '\n\n', m_simpleTV.Common.GetMainPath(1) .. 'debug_cloud_mailru.txt')