Jump to content

need help to do a youtube search using autoit


Recommended Posts

goodmorning; autoit team
please their are any youtube search way working?
because i was using the get source and split it to get the result but know it does not working any way.
is the youtube disabled that? and is their any other simple way to do that?
i tested all examples found in this post but also it don't work
https://www.autoitscript.com/forum/topic/123945-youtube-search/

and here is the example that i use to and it don't work any more

local $hSearchOpenHNDL, $hSearchConnect, $sSearchGet
local $a_UrlsArray[1][5]
local $b_ButtonsDisabled = false, $b_SearchBTNFocus = false, $b_SearchListFocus, $h_SearchFocusHND
local $Return = "0"
local $s_OpenStringY = "/feed/trending"
local $ChannelUrl = "", $channelName = ""
if Not ($a_YoutubeSearchArray[0][0] = 0) then
GUICtrlSetData($searchInp, $s_youtubeSearchLastSearch)
$s_OpenStringY = "/results?search_query=" & StringReplace(GUICtrlRead($searchInp), " ", "+")
$a_UrlsArray = $a_YoutubeSearchArray
for $i = 1 to $a_UrlsArray[0][0]
_GUICtrlListBox_AddString($SearchList, $a_UrlsArray[$i][0] & $a_UrlsArray[$i][2] & $a_UrlsArray[$i][3])
next
_GUICtrlListBox_SetCurSel($SearchList, $I_youtubeSearchLastIndex-1)
GUICtrlSetState($SearchList, $GUI_focus)
else
if Ping("youtube.com", 1000) > 1 then
$hSearchOpenHNDL = _WinHttpOpen('')
if not (@Error) then
$hSearchConnect = _WinHttpConnect($hSearchOpenHNDL, "youtube.com")
if Not (@Error) then
$sSearchGet = _WinHttpSimpleRequest($hSearchConnect, "get", $s_OpenStringY)
if not (@Error) then
local $a_strings = _StringBetween($sSearchGet, '<a href="/watch', "<ul")
local $title = ""
local $url = ""
local $length = ""
local $result = ""
GUICtrlSetData($SearchList, "")
ReDim $a_UrlsArray[1][5]
for $i = 0 to UBound($a_strings)-1
$url = _StringBetween($a_strings[$i], "?", '"')
if @error then ContinueLoop
$url = "https://www.youtube.com/watch?" & $url[0]
$title = _StringBetween($a_strings[$i], 'dir="', '</a>')
if @error then ContinueLoop
$title = $title[0]
$title = StringRegExpReplace($title, '(.*\"\>)', "")
if StringRegExp($a_strings[$i], '[0-9]{1,2}\:[0-9]{1,2}\:[0-9]{1,2}', 0) = 1 then
$length = StringRegExp($a_strings[$i], '[0-9]{1,2}\:[0-9]{1,2}\:[0-9]{1,2}', 2)
elseIf StringRegExp($a_strings[$i], '[0-9]{1,2}\:[0-9]{1,2}', 0) = 1 then
$length = StringRegExp($a_strings[$i], '[0-9]{1,2}\:[0-9]{1,2}', 2)
else
$length = ""
endIf
if IsArray($length) then
$length = ": (" & $length[0] & ")"
else
$length = ""
endIf
$ChannelUrl = stringRegexpReplace($a_strings[$i], '(^.*?<a.*?\"(\/user|\/channel))+', "$2")
$channelName = stringRegexpReplace($ChannelUrl, '(.*?\".*?>)(.*</a>)+', "$2")
$ChannelUrl = stringRegexpReplace($ChannelUrl, '(\".*)+', "")
$channelName = stringRegexpReplace($channelName, '(</a>.*)+', "")
$result &= $title & @crlf & $url & @crlf
ReDim $a_UrlsArray[UBound($a_UrlsArray)+1][5]
$a_UrlsArray[UBound($a_UrlsArray)-1][0] = $title
$a_UrlsArray[UBound($a_UrlsArray)-1][1] = $url
$a_UrlsArray[UBound($a_UrlsArray)-1][2] = $length
if not ($channelName = "") then $a_UrlsArray[UBound($a_UrlsArray)-1][3] = ", (" & $channelName & ")"
if not ($channelUrl = "") then $a_UrlsArray[UBound($a_UrlsArray)-1][4] = "https://www.youtube.com" & $channelUrl
$a_UrlsArray[0][0] = UBound($a_UrlsArray)-1
_GUICtrlListBox_AddString($SearchList, $a_UrlsArray[UBound($a_UrlsArray)-1][0] & $length & $a_UrlsArray[UBound($a_UrlsArray)-1][3])
next
endIf
endIf
endIf
endIf
endIf

 

i hope any one can help me

thanks in advance

Link to comment
Share on other sites

i suggest you try using YouTube API instead of your current technique.

Signature - my forum contributions:

Spoiler

UDF:

LFN - support for long file names (over 260 characters)

InputImpose - impose valid characters in an input control

TimeConvert - convert UTC to/from local time and/or reformat the string representation

AMF - accept multiple files from Windows Explorer context menu

DateDuration -  literal description of the difference between given dates

Apps:

Touch - set the "modified" timestamp of a file to current time

Show For Files - tray menu to show/hide files extensions, hidden & system files, and selection checkboxes

SPDiff - Single-Pane Text Diff

 

Link to comment
Share on other sites

hello again
please
i have read it
i tried this but it give me a error msg
can any one help please to solve it?

 

#include "WinHttp.au3"

; Open needed handles
Global $hOpen = _WinHttpOpen()
Global $hConnect = _WinHttpConnect($hOpen, "www.googleapis.com")
Global $s_Request = _WinHttpSimpleSSLRequest($hConnect, "Get", "/youtube/v3/search/?part=snippet&q=test&maxResults=50&type=video&ApiKey=xxxxxx")
if not (@error) then
FileDelete("result.txt")
FileWrite("result.txt", $s_Request)
ShellExecute("result.txt")
endIf
_WinHttpCloseHandle($hConnect)
_WinHttpCloseHandle($hOpen)

 

Link to comment
Share on other sites

  • Developers
15 minutes ago, nacerbaaziz said:

i tried this but it give me a error msg

.... being?

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

hello
thanks for your fast replys

here is the error message that i got

{
 "error": {
  "errors": [
   {
    "domain": "usageLimits",
    "reason": "dailyLimitExceededUnreg",
    "message": "Daily Limit for Unauthenticated Use Exceeded. Continued use requires signup.",
    "extendedHelp": "https://code.google.com/apis/console"
   }
  ],
  "code": 403,
  "message": "Daily Limit for Unauthenticated Use Exceeded. Continued use requires signup."
 }
}

i tried to use key=
also i confirmed that the youtube api is enabled
i tried this with more than account and more than PC
the same result
i hope that i can find a way to do that simply

Link to comment
Share on other sites

If you mean to get the links from the search results:

;=============================================================================
#Region ;Include + Opt
#include <IE.au3>
#include <ProgressConstants.au3>
;=============================================================================
Global $oIE, $Load = 0, $Failed = 0, $Visible = 0 ;Change to show or hide the IE window.
Global $oLinks, $iNumLinks, $sTxt, $PrevLink = ''
;=============================================================================
QuerySite('chillstep')
;=============================================================================
Func QuerySite($Name)
    $GMarquee = GUICreate("Working", 240, 70, -1, @DesktopHeight / 4)
    $Progress_1 = GUICtrlCreateProgress(10, 10, 220, 20, 0x0008)
    $LabelP = GUICtrlCreateLabel('Working...', 10, 40, 100)
    GUISetState(@SW_SHOW)
    _ProgressMarquee_Start($Progress_1) ;Start
    ;=============================================================================
    $oIE = _IECreate("https://www.youtube.com/results?search_query=" & $Name, 0, $Visible, 0, 0)
    If $oIE <> @error Then
        Sleep(2000)
        Do
            $oLinks = _IELinkGetCollection($oIE)
            For $oLink In $oLinks
                If StringInStr($oLink.href, 'youtube.com/watch?v=') <> 0 Then
                    If $oLink.href <> $PrevLink Then
                    ConsoleWrite($oLink.href & @CRLF)
                    $PrevLink = $oLink.href
                    EndIf
                EndIf
                If StringInStr($oLink.href, 'reporthistory') <> 0 Then
                    ConsoleWrite('Found "about" link'&@CRLF)
                    $Load = 1
                    ExitLoop
                EndIf
            Next
            Sleep(100)
        Until $Load = 1
    Else
        _ProgressMarquee_Stop($Progress_1) ;Stop
        GUIDelete($GMarquee)
        MsgBox(64 + 262144, 'Failed', 'Error:' & @error & ' in: _IECreate')
        _IEQuit($oIE)
    EndIf
    _ProgressMarquee_Stop($Progress_1) ;Stop
    GUIDelete($GMarquee)
EndFunc   ;==>QuerySite
;=============================================================================
Func _ProgressMarquee_Start($iControlID)
    Return GUICtrlSendMsg($iControlID, $PBM_SETMARQUEE, True, 50)
EndFunc   ;==>_ProgressMarquee_Start
;=============================================================================
Func _ProgressMarquee_Stop($iControlID, $fReset = False)
    Local $fReturn = GUICtrlSendMsg($iControlID, $PBM_SETMARQUEE, False, 50)
    If $fReturn And $fReset Then
        GUICtrlSetStyle($iControlID, $PBS_MARQUEE)
    EndIf
    Return $fReturn
EndFunc   ;==>_ProgressMarquee_Stop
;=============================================================================

 

Edited by careca
Spoiler

Renamer - Rename files and folders, remove portions of text from the filename etc.

GPO Tool - Export/Import Group policy settings.

MirrorDir - Synchronize/Backup/Mirror Folders

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

String Trigger - Triggers pasting text or applications or internet links on specific strings.

Inconspicuous - Hide files in plain sight, not fully encrypted.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Au3Record.exe

Link to comment
Share on other sites

@careca
thanks for your reply

am sorry for the dellay

i need to get also the the time, the channel name, the channel url.
by this way i can't get this informations
also i can not know why my test does not work, when i tried it using the browser all things work without any problem.
but when i do that using autoit it did not work.
the problem it was working for me before.
 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...