SourcePictureFile := "D:\Screenshots\2014.12.18-17.03.25.9.jpg" ; указать путь к файлу, если его не будет в параметре
if (SourcePictureFile = "")
SourcePictureFile = %1%
if !IsObject(oPictures := GetMailRuPictureLinks(SourcePictureFile))
{
MsgBox, Не удалось получить ссылки
ExitApp
}
Gui, Margin, 15, 15
Gui, Font,, Tahoma
Loop % oPictures.MaxIndex()
{
Gui, +LastFound
size := oPictures[A_Index].size
SizeStr .= (A_Index = 1 ? "" : "|") . (A_Index = 4 ? "|" : "") . size
Gui, Add, Edit, x15 y+15 r1 w65, % size
Gui, Add, Edit, x+5 yp r1 w400, % oPictures[A_Index].url
Number1 := 1 + (A_Index - 1)*2, Number2 := Number1 + 1
Gui, Add, Button, v%Number1% x+5 hp gShow, Show
Gui, Add, Button, v%Number2% x+5 wp hp gCopy, Copy
}
GuiControlGet, Pos, Pos, % Number2
Gui, Add, Checkbox, vCheck gCheck x15 y+25, Использовать превью
Gui, Add, DDL, vDDL x+10 yp-3 w80 Disabled, % SizeStr ;
Gui, Add, Text, vText x+5 yp+3 Disabled, Размер превью
Gui, Add, Button, % "vBBCode gCopyBBCode x" PosX + PosW - 150 " yp-3 w150 Default", Копировать BBCode
GuiControl, Focus, BBCode
if hIcon := ExtractIcon(GetCloudExe(), 0)
Loop 2
PostMessage, WM_SETICON := 0x80, A_Index - 1, hIcon
Gui, Show,, Прямые ссылки
Return
Show:
Copy:
EditNumber := A_GuiControl + mod(A_GuiControl, 2)
GuiControlGet, url,, Edit%EditNumber%
if (A_ThisLabel = "Show")
Run, % url
else
Clipboard := url
Return
Check:
GuiControlGet, Check
Loop 2
GuiControl, % (Check ? "Enable" : "Disable"), % A_Index = 1 ? "DDL" : "Text"
Return
CopyBBCode:
GuiControlGet, Check
for k, v in oPictures
if (v.size = "original" && OriginalSizeUrl := v.url)
break
if !Check
Clipboard := "[img]" . OriginalSizeUrl . "[/img]"
else {
GuiControlGet, DDL
for k, v in oPictures
if (v.size = DDL)
break
Clipboard := "[url=" . OriginalSizeUrl . "][img]" . v.url . "[/img][/url]"
}
ToolTip, BBCode скопирован в буфер обмена
SetTimer, ToolTipDel, -1000
Return
ToolTipDel:
ToolTip
Return
GuiClose:
GuiEscape:
(hIcon && DllCall("DestroyIcon", Ptr, hIcon))
ExitApp
GetMailRuPictureLinks(filePath)
{
static i
if !Verify(filePath)
Return
Process, Exist, Cloud.exe
if !ErrorLevel {
if !(CloudExe := GetCloudExe()) {
MsgBox, Не удалось определить путь к Cloud.exe
Return
}
Run, % CloudExe
Process, Wait, Cloud.exe
}
if !(MailRuFolder := GetMailRuFolder()) {
MsgBox, Не удалось определить путь к папке облака
Return
}
SplitPath, filePath, FileName
if FileExist(Dest := MailRuFolder . "\" FileName) {
MsgBox, 4,, Файл %Dest% уже существует.`nПереписать?
IfMsgBox, No
NoOverwrite := 1
}
if !NoOverwrite {
FileCopy, % filePath, % Dest, 1
if ErrorLevel {
MsgBox, Не удалось скопировать файл %filePath% в папку %MailRuFolder%
Return
}
}
PrevClipboard := ClipboardAll, Clipboard := "", i := 0
SetTimer, LoadFile, 500
link := GetPublicLink(MailRuFolder, Dest), Clipboard := PrevClipboard
SetTimer, LoadFile, Off
TrayTip
if !InStr(link, "http") = 1 {
MsgBox, Не удалось получить публичную ссылку
Return
}
if !(html := GetHtml(link)) {
MsgBox, Не удалось получить код страницы с файлом
Return
}
Return ExtractData(html)
LoadFile:
m := mod(++i, 4)
TrayTip,, % "Идёт загрузка файла" . (m = 1 ? ". " : m = 2 ? ".. " : m = 3 ? "... " : "....")
Return
}
Verify(filePath)
{
if !FileExist(filePath) {
MsgBox, Файл %filePath% не найден
Return
}
if !Ping("cloud.mail.ru") {
MsgBox, Нет связи с cloud.mail.ru`nПроверьте подключение к интернету!
Return
}
Return 1
}
Ping(strHost)
{
oWMI := ComObjGet("winmgmts:")
Loop 2
bRet := oWMI.Get("Win32_PingStatus.address='" . strHost . "'").StatusCode = 0
until bRet
return bRet
}
GetCloudExe()
{
IniRead, CloudExe, % A_ScriptDir "\GetImageLink.ini", Paths, CloudExePath, % " "
if CloudExe
Return CloudExe
SetBatchLines, -1
Loop 2 {
if (A_Index = 1 && !A_Is64bitOS)
continue
SubKey := "SOFTWARE" . (A_Index = 1 ? "\Wow6432Node" : "") . "\Microsoft\Windows\CurrentVersion\Uninstall"
Loop, HKLM, % SubKey, 1, 1
{
if (A_LoopRegName = "DisplayName") {
RegRead, DisplayName
if (DisplayName = "Mail.Ru Cloud") {
RegRead, Location, HKLM, % A_LoopRegSubKey, InstallLocation
break 2
}
}
}
}
if FileExist(CloudExe := RTrim(Location, "\") . "\Cloud.exe") {
IniWrite, % CloudExe, % A_ScriptDir "\GetImageLink.ini", Paths, CloudExePath
Return CloudExe
}
FileSelectFile, CloudExe, 1, ::{20d04fe0-3aea-1069-a2d8-08002b30309d}, Укажите файл Cloud.exe`, путь будет сохранён:, Executable (*.exe)
if !CloudExe
Return
IniWrite, % CloudExe, % A_ScriptDir "\GetImageLink.ini", Paths, CloudExePath
Return CloudExe
}
GetMailRuFolder()
{
IniRead, CloudFolder, % A_ScriptDir "\GetImageLink.ini", Paths, CloudFolder, % " "
if !FileExist(CloudFolder)
RegRead, CloudFolder, HKCU, Software\Mail.Ru\Mail.Ru_Cloud, folder
FileSelectFolder, CloudFolder, *%CloudFolder%, 1, Укажите папку или подпапку Облака для копирования файла:
if !CloudFolder
Return
IniWrite, % CloudFolder, % A_ScriptDir "\GetImageLink.ini", Paths, CloudFolder
Return CloudFolder
}
GetPublicLink(MailRuFolder, Dest)
{
Loop 3 {
error := oVerb := ""
try {
for item in ComObjCreate("Shell.Application").Namespace(MailRuFolder).Items
if (item.Path = Dest)
for Verb in item.Verbs
if InStr(Verb.Name, "публич") && oVerb := Verb
break 2
if !IsObject(oVerb) {
MsgBox, Меню «Скопировать публичную ссылку» не найдено
Return
}
Loop {
Loop 30 {
Sleep 1000
Clipboard := ""
oVerb.DoIt
} until Clipboard != ""
if (Clipboard = "") {
MsgBox, 4,, Пока не удалось скопировать публичную ссылку.`nВозможно`, файл ещё не загрузился на Олако.`nПодождать?
IfMsgBox, No
break
}
} until Clipboard != ""
}
catch
continue
break
}
Return Clipboard
}
GetHtml(link)
{
Loop 3 {
Sleep, 100
try {
WebRequest := ComObjCreate("WinHttp.WinHttpRequest.5.1")
WebRequest.Open("GET", link)
WebRequest.Send()
html := WebRequest.ResponseText
}
catch
continue
} until html
Return html
}
ExtractData(html)
{
urls := RegExReplace(html, "s).+""thumbnails"": \{\s*(.+?)\s*}.+", "$1")
oPictures := []
Loop, parse, Urls, `n, `r
{
RegExMatch(Trim(A_LoopField), "U)""(\d+x\d+|original)"".+""(http.+)""", found)
if !(found1 && found2) {
MsgBox, Mail.ru изменили структуру страницы
Return
}
oPictures[A_Index] := {size: found1, url: found2}
}
Return oPictures
}
ExtractIcon(sFile, idx)
{
Return DllCall("Shell32\ExtractIcon", Ptr, DllCall("GetModuleHandle", UInt, 0, Ptr), Str, sFile, UInt, idx, Ptr)
}
Во время работы скрипта появляются всякие сообщения от иконки Cloud Mail.Ru, но на них можно не обращать внимания.
Скрипт написан с целью добавления в контекстное меню файлов с изображениями, но можно использовать и так.
Может, по интерфейсу будут какие-нибудь предложения?