1 (изменено: Malcev, 2020-09-04 08:14:47)

Тема: AHK: Заливка файлов на fex.net

Размер файлов до 10 гигов без регистрации и до 50 гигов с регистрацией.
Файл лежит на хостинге 7 дней.
Пример без регистрации:

file := "D:\Sequence 06.mp4"

ComObjError(false)
setbatchlines -1
Gui,  -border -caption +hwndhGui
Gui, Show, w0 h0
percents := 0
SetTimer, uploadPercent, 300
f := FileOpen(file, "r")
FileSize := f.length
SplitPath, file, FileName

HTTP := ComObjCreate("WinHTTP.WinHTTPRequest.5.1")
HTTP.Open("GET", "https://api.fex.net/api/v1/anonymous/upload-token", true)
HTTP.SetRequestHeader("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko")
HTTP.SetRequestHeader("Content-Type", "application/json")
HTTP.SetRequestHeader("Pragma", "no-cache")
HTTP.SetRequestHeader("Cache-Control", "no-cache, no-store")
HTTP.SetRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT")
HTTP.Send()
HTTP.WaitForResponse()
RegexMatch(HTTP.ResponseText, "s)""token"":""(.+?)""", match)
token := match1

HTTP.Open("POST", "https://api.fex.net/api/v1/anonymous/file", true)
HTTP.SetRequestHeader("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko")
HTTP.SetRequestHeader("Content-Type", "application/json")
HTTP.SetRequestHeader("Authorization","Bearer " token)
HTTP.SetRequestHeader("Pragma", "no-cache")
HTTP.SetRequestHeader("Cache-Control", "no-cache, no-store")
HTTP.SetRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT")
HTTP.Send("{""directory_id"":null,""size"":" FileSize ",""name"":""" FileName """}")
HTTP.WaitForResponse()
if (HTTP.Status = 400)
{
   if InStr(HTTP.ResponseText, """size""")
      msgbox, file is bigger than 10 gb.
   else if InStr(HTTP.ResponseText, "<title>400 Bad Request</title>")
      msgbox, file does not exist.
   else
      msgbox % HTTP.ResponseText
   ExitApp
}
RegexMatch(HTTP.ResponseText, "s)""anon_upload_link"":""(.+?)"".+?""location"":""(https:.+?):.+?(/.+?)""", match)
uploadLink := "https://fex.net/s/" match1, uploadLocation := match2 match3

HTTP.Open("POST", uploadLocation, true)
HTTP.SetRequestHeader("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko")
HTTP.SetRequestHeader("Content-Type", "application/json")
HTTP.SetRequestHeader("Authorization","Bearer " token)
HTTP.SetRequestHeader("Fsp-FileName", FileName)
HTTP.SetRequestHeader("Fsp-Size", FileSize)
HTTP.SetRequestHeader("Fsp-Version", "1.0.0")
HTTP.SetRequestHeader("Pragma", "no-cache")
HTTP.SetRequestHeader("Cache-Control", "no-cache, no-store")
HTTP.SetRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT")
HTTP.Send()
HTTP.WaitForResponse()

chunksize := 4194304
chunks := Ceil(FileSize/chunksize)
LastChunkSize := Mod(FileSize, chunksize)
loop % chunks
{ 
   offset := chunksize*(A_Index-1)
   If (A_Index = chunks) and (LastChunkSize != 0)
      chunksize := LastChunkSize
   safeArr := ComObjArray(0x11, chunksize) ; Create SAFEARRAY = VT_ARRAY|VT_UI1
   pvData := NumGet(ComObjValue(safeArr) + 12 + (A_PtrSize==8 ? 4 : 0)) ; get pvData memeber
   f.RawRead(pvData + 0, chunksize)
   loop
   {
      HTTP.Open("PATCH", uploadLocation, true)
      HTTP.SetRequestHeader("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko")
      HTTP.SetRequestHeader("Authorization","Bearer " token)
      HTTP.SetRequestHeader("Content-Type", "application/offset+octet-stream")
      HTTP.SetRequestHeader("Fsp-FileName", FileName)
      HTTP.SetRequestHeader("Fsp-Offset", offset)
      HTTP.SetRequestHeader("Fsp-Version", "1.0.0")
      HTTP.SetRequestHeader("Pragma", "no-cache")
      HTTP.SetRequestHeader("Cache-Control", "no-cache, no-store")
      HTTP.SetRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT")
      HTTP.Send(safeArr)
      HTTP.WaitForResponse()
      if (HTTP.Status = 200) or (HTTP.Status = 204)
         break
      if (HTTP.Status = 500)
      {
         sleep 1000
         continue
      }
      loop
      {
         HTTP.Open("POST", "https://api.fex.net/api/v1/anonymous/file", true)
         HTTP.SetRequestHeader("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko")
         HTTP.SetRequestHeader("Content-Type", "application/json")
         HTTP.SetRequestHeader("Authorization","Bearer " token)
         HTTP.SetRequestHeader("Pragma", "no-cache")
         HTTP.SetRequestHeader("Cache-Control", "no-cache, no-store")
         HTTP.SetRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT")
         HTTP.Send("{""directory_id"":null,""size"":" FileSize ",""name"":""" FileName """}")
         HTTP.WaitForResponse()
         if (HTTP.Status = 200)
            break
         sleep 50
      }
   }
   count+=100/chunks
   percents := Format("{1:0.2f}", count)
}
safeArr := ""
f.Close()
if InStr(HTTP.ResponseText, "download_url")
   msgbox % clipboard := uploadLink
else
   msgbox % "Error`n" HTTP.ResponseText
ExitApp


uploadPercent:
if StrLen(title) > 5
   title := ""
else
   title .= "."
WinSetTitle, ahk_id %hGui%,, % percents "%" title
return

Пример с фейковой регистрацией (время ожидания письма с подтверждением регистрации - waitingTime := 10 секунд.):

file := "D:\Sequence 06.mp4"

waitingTime := 10000
ComObjError(false)
setbatchlines -1
Gui,  -border -caption +hwndhGui
Gui, Show, w0 h0
percents := 0
SetTimer, uploadPercent, 300
f := FileOpen(file, "r")
FileSize := f.length
SplitPath, file, FileName

loop
{
   HTTP := ComObjCreate("WinHTTP.WinHTTPRequest.5.1")
   HTTP.Open("GET", "https://generator.email", true)
   HTTP.SetRequestHeader("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko")
   HTTP.SetRequestHeader("Pragma", "no-cache")
   HTTP.SetRequestHeader("Cache-Control", "no-cache, no-store")
   HTTP.SetRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT")
   HTTP.Send()
   HTTP.WaitForResponse()
   RegexMatch(HTTP.ResponseText, "s)var gasmurl=""(.+?)"".+?""email_ch_text"">(.+?)<", match)
   fakeLinkEmail := "https://generator.email" match1, fakeEmail := match2

   HTTP.Open("POST", "https://api.fex.net/api/v1/auth/registration-email", true)
   HTTP.SetRequestHeader("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko")
   HTTP.SetRequestHeader("Content-Type", "application/json")
   HTTP.SetRequestHeader("Pragma", "no-cache")
   HTTP.SetRequestHeader("Cache-Control", "no-cache, no-store")
   HTTP.SetRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT")
   HTTP.Send("{""email"":""" fakeEmail """,""password"":""password"",""first_name"":""first_name""}")
   HTTP.WaitForResponse()
   if (HTTP.Status = 200)
   {
      time := A_TickCount
      loop
      {
         HTTP.Open("GET", fakeLinkEmail, true)
         HTTP.SetRequestHeader("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko")
         HTTP.SetRequestHeader("Pragma", "no-cache")
         HTTP.SetRequestHeader("Cache-Control", "no-cache, no-store")
         HTTP.SetRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT")
         HTTP.Send()
         HTTP.WaitForResponse()
         RegexMatch(HTTP.ResponseText, "s)https%3A%2F%2Ffex\.net%2Fconfirm%2F(.+?)&", match)
         if (match1 != "")
            break 2
         if ((A_TickCount - time) > waitingTime)
            break
         sleep 50
      }
   }
}

HTTP.Open("POST", "https://api.fex.net/api/v1/auth/confirm-email/" match1, true)
HTTP.SetRequestHeader("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko")
HTTP.SetRequestHeader("Content-Type", "application/json")
HTTP.SetRequestHeader("Pragma", "no-cache")
HTTP.SetRequestHeader("Cache-Control", "no-cache, no-store")
HTTP.SetRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT")
HTTP.Send()
HTTP.WaitForResponse()
RegexMatch(HTTP.GetResponseHeader("Set-Cookie"), "s)token=(.+?);", match)
token := match1

HTTP.Open("GET", "https://api.fex.net/api/v2/file", true)
HTTP.SetRequestHeader("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko")
HTTP.SetRequestHeader("Content-Type", "application/json")
HTTP.SetRequestHeader("Authorization","Bearer " token)
HTTP.SetRequestHeader("Pragma", "no-cache")
HTTP.SetRequestHeader("Cache-Control", "no-cache, no-store")
HTTP.SetRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT")
HTTP.Send()
HTTP.WaitForResponse()
RegexMatch(HTTP.ResponseText, "s)""id"":(.+?),", match)
directory_id := match1

HTTP.Open("POST", "https://api.fex.net/api/v1/file/upload", true)
HTTP.SetRequestHeader("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko")
HTTP.SetRequestHeader("Content-Type", "application/json")
HTTP.SetRequestHeader("Authorization","Bearer " token)
HTTP.SetRequestHeader("Pragma", "no-cache")
HTTP.SetRequestHeader("Cache-Control", "no-cache, no-store")
HTTP.SetRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT")
HTTP.Send("{""directory_id"":" directory_id ",""size"":" FileSize ",""name"":""" FileName """}")
HTTP.WaitForResponse()
if (HTTP.Status = 400)
{
   if InStr(HTTP.ResponseText, """size""")
      msgbox, file is bigger than 50 gb.
   else if InStr(HTTP.ResponseText, "<title>400 Bad Request</title>")
      msgbox, file does not exist.
   else
      msgbox % HTTP.ResponseText
   ExitApp
}
RegexMatch(HTTP.ResponseText, "s)""location"":""(https:.+?):.+?(/.+?)""", match)
uploadLocation := match1 match2

HTTP.Open("POST", uploadLocation, true)
HTTP.SetRequestHeader("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko")
HTTP.SetRequestHeader("Content-Type", "application/json")
HTTP.SetRequestHeader("Authorization","Bearer " token)
HTTP.SetRequestHeader("Fsp-FileName", FileName)
HTTP.SetRequestHeader("Fsp-Size", FileSize)
HTTP.SetRequestHeader("Fsp-Version", "1.0.0")
HTTP.SetRequestHeader("Pragma", "no-cache")
HTTP.SetRequestHeader("Cache-Control", "no-cache, no-store")
HTTP.SetRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT")
HTTP.Send()
HTTP.WaitForResponse()

chunksize := 4194304
chunks := Ceil(FileSize/chunksize)
LastChunkSize := Mod(FileSize, chunksize)
loop % chunks
{ 
   offset := chunksize*(A_Index-1)
   If (A_Index = chunks) and (LastChunkSize != 0)
      chunksize := LastChunkSize
   safeArr := ComObjArray(0x11, chunksize) ; Create SAFEARRAY = VT_ARRAY|VT_UI1
   pvData := NumGet(ComObjValue(safeArr) + 12 + (A_PtrSize==8 ? 4 : 0)) ; get pvData memeber
   f.RawRead(pvData + 0, chunksize)
   loop
   {
      HTTP.Open("PATCH", uploadLocation, true)
      HTTP.SetRequestHeader("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko")
      HTTP.SetRequestHeader("Authorization","Bearer " token)
      HTTP.SetRequestHeader("Content-Type", "application/offset+octet-stream")
      HTTP.SetRequestHeader("Fsp-FileName", FileName)
      HTTP.SetRequestHeader("Fsp-Offset", offset)
      HTTP.SetRequestHeader("Fsp-Version", "1.0.0")
      HTTP.SetRequestHeader("Pragma", "no-cache")
      HTTP.SetRequestHeader("Cache-Control", "no-cache, no-store")
      HTTP.SetRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT")
      HTTP.Send(safeArr)
      HTTP.WaitForResponse()
      if (HTTP.Status = 204)
         break
      if (HTTP.Status = 200)
      {
         RegexMatch(HTTP.ResponseText, "s)""id"":(.+?),.+?""name"":""(.+?)""", match)
         files_ids := match1, title := match2
         break
      }
      if (HTTP.Status = 500)
      {
         sleep 1000
         continue
      }
      loop
      {
         HTTP.Open("POST", "https://api.fex.net/api/v1/file/upload", true)
         HTTP.SetRequestHeader("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko")
         HTTP.SetRequestHeader("Content-Type", "application/json")
         HTTP.SetRequestHeader("Authorization","Bearer " token)
         HTTP.SetRequestHeader("Pragma", "no-cache")
         HTTP.SetRequestHeader("Cache-Control", "no-cache, no-store")
         HTTP.SetRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT")
         HTTP.Send("{""directory_id"":" directory_id ",""size"":" FileSize ",""name"":""" FileName """}")
         HTTP.WaitForResponse()
         if (HTTP.Status = 200)
            break
         sleep 50
      }
   }
   count+=100/chunks
   percents := Format("{1:0.2f}", count)
}
safeArr := ""
f.Close()

HTTP.Open("POST", "https://api.fex.net/api/v1/file/share", true)
HTTP.SetRequestHeader("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko")
HTTP.SetRequestHeader("Content-Type", "application/json")
HTTP.SetRequestHeader("Authorization","Bearer " token)
HTTP.SetRequestHeader("Pragma", "no-cache")
HTTP.SetRequestHeader("Cache-Control", "no-cache, no-store")
HTTP.SetRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT")
HTTP.Send("{""files_ids"":[" files_ids "],""title"":""" title """}")
HTTP.WaitForResponse()
RegexMatch(HTTP.ResponseText, "s)""link"":""(.+?)""", match)
uploadLink := "https://fex.net/s/" match1
msgbox % clipboard := uploadLink
ExitApp


uploadPercent:
if StrLen(title) > 5
   title := ""
else
   title .= "."
WinSetTitle, ahk_id %hGui%,, % percents "%" title
return
+ DD

2

Re: AHK: Заливка файлов на fex.net

Добавил проверку и продолжение загрузки после прерванного соединениея.

3

Re: AHK: Заливка файлов на fex.net

Добавил загрузку с фейковой регистрацией.

4

Re: AHK: Заливка файлов на fex.net

Malcev, это замечательный скрипт.
Скажите - как сделать подобную заливку jpg-файла, но только на сайт https://www.google.ru/imghp  ?

5

Re: AHK: Заливка файлов на fex.net

Смотреть, какие запросы отправляются и повторять их.

6

Re: AHK: Заливка файлов на fex.net

Malcev, ну вот - в вашем скрипте как повторить запросы для https://www.google.ru/imghp  ?
И где посмотреть - какие запросы отправляются (там же не написано это на странице) ?

7 (изменено: Malcev, 2020-09-06 17:49:57)

Re: AHK: Заливка файлов на fex.net

В моем никак. Посмотреть, что отправляется можно в браузере в панеле разработчика.

8

Re: AHK: Заливка файлов на fex.net

А зачем может понадобиться заливать большие файлы на 7 дней?

9

Re: AHK: Заливка файлов на fex.net

DD
У каждого свои причуды, например можно на время скинуть важные огромные файлы в интернет, затем очистить диск / флешку и скачать обратно их.

10

Re: AHK: Заливка файлов на fex.net

Я таким способом отправляю видеоматериал заказчикам.