phatzilla Posted November 12, 2010 Share Posted November 12, 2010 Hey guys, i'm trying to code a youtube script which pulls uploaded video urls from a user-defined channel. Lets take this channel for example : http://www.youtube.com/user/ligafutbol32#g/u What i'd like to do is be able to grab a defined number of youtube URLS from that uploaded list on his channel and save them to a text file. I can't seem to get this one working, What i have so far expandcollapse popup#include <IE.au3> #include <file.au3> FileDelete("links.txt") _FileCreate("links.txt") $oIE = _IECreate("http://www.youtube.com/user/ligafutbol32#g/u") $nOffset = 1 $oLinks = _IELinkGetCollection($oIE) For $oLink In $oLinks Sleep(10) $findlink = StringInStr($oLink.href, "http://www.youtube.com/watch?v=") $done = StringReplace($oLink.href, "http://www.youtube.com/watch?v=", "") $done1 = StringLeft($done, 11) If $findlink = 0 Then Sleep(10) Else $file = FileOpen("links.txt", 1) FileWrite($file, $done1 & @CRLF) FileClose($file) EndIf Next FileDelete("vids.txt") _FileCreate("vids.txt") $file1 = FileOpen("links.txt", 0) ; Check if file opened for reading OK If $file1 = -1 Then MsgBox(0, "Error", "Unable to open file.") Exit EndIf ; Read in lines of text until the EOF is reached Global $total = "" While 1 $line = FileReadLine($file1) If @error = -1 Then ExitLoop If Not StringInStr($total, $line, 0) >= 1 Then $total = $total & $line & @CRLF EndIf WEnd ;MsgBox(1,"Total",$total) FileClose($file1) $file2 = FileOpen("vids.txt", 1) FileWrite($file2, $total & @CRLF) for $j = 8 to 50 step 1 _FileLineDelete("C:\vids.txt", $j) Next FileClose($file2) Func _FileLineDelete($FilePath, $LineNum) If Not _IsFileOpen($FilePath) Then SetError(1) Return 0 EndIf Local $Arr _FileReadToArray($FilePath, $Arr) Local $FO = FileOpen($FilePath, 2) If $FO = -1 Then SetError(1) Return 0 EndIf For $x = 1 To UBound($Arr) - 1 If $x = $LineNum Then ContinueLoop FileWriteLine($FO, $Arr[$x]) Next FileClose($FO) Return 1 EndFunc ;==>_FileLineDelete Func _IsFileOpen($FilePath) Local $D = FileOpen($FilePath, 0) FileClose($D) If $D = -1 Then Return 0 EndIf Return 1 EndFunc ;==>_IsFileOpen This script works horribly and is very unreliable, i am totally stuck and would like some help Link to comment Share on other sites More sharing options...
phatzilla Posted November 13, 2010 Author Share Posted November 13, 2010 anyone Link to comment Share on other sites More sharing options...
wakillon Posted November 14, 2010 Share Posted November 14, 2010 I don't understand the second part of your script but try like this expandcollapse popup#include <IE.au3> #include <file.au3> #include <Array.au3> $sFile = @ScriptDir & "\links.txt" FileDelete($sFile) Dim $_VideosIdArray[1] $oIE = _IECreate("http://www.youtube.com/user/ligafutbol32#g/u") $nOffset = 1 $oLinks = _IELinkGetCollection($oIE) For $oLink In $oLinks Sleep(10) $findlink = StringInStr($oLink.href, "http://www.youtube.com/watch?v=") $done = StringReplace($oLink.href, "http://www.youtube.com/watch?v=", "") $done1 = StringLeft($done, 11) If Stringinstr ( $done1, ':' ) = 0 And Not _AlreadyInArray ( $_VideosIdArray, $done1 ) Then _ArrayAdd ( $_VideosIdArray, $done1 ) Next _FileWriteFromArray ( $sFile, $_VideosIdArray ) _ArrayDisplay ( $_VideosIdArray ) ; you get all video Id ShellExecuteWait ( "links.txt" ) FileDelete("vids.txt") _FileCreate("vids.txt") $file1 = FileOpen("links.txt", 0) If $file1 = -1 Then Exit MsgBox(0, "Error", "Unable to open file.") Global $total = "" While 1 $line = FileReadLine($file1) If @error = -1 Then ExitLoop If Not StringInStr($total, $line, 0) >= 1 Then $total = $total & $line & @CRLF EndIf WEnd MsgBox(1,"Total",$total) FileClose($file1) $file2 = FileOpen("vids.txt", 1) FileWrite($file2, $total & @CRLF) for $j = 8 to 50 step 1 _FileLineDelete("C:\vids.txt", $j) Next FileClose($file2) Exit Func _FileLineDelete($FilePath, $LineNum) If Not _IsFileOpen($FilePath) Then SetError(1) Return 0 EndIf Local $Arr _FileReadToArray($FilePath, $Arr) Local $FO = FileOpen($FilePath, 2) If $FO = -1 Then SetError(1) Return 0 EndIf For $x = 1 To UBound($Arr) - 1 If $x = $LineNum Then ContinueLoop FileWriteLine($FO, $Arr[$x]) Next FileClose($FO) Return 1 EndFunc ;==> _FileLineDelete ( ) Func _IsFileOpen($FilePath) Local $D = FileOpen($FilePath, 0) FileClose($D) If $D = -1 Then Return 0 EndIf Return 1 EndFunc ;==> _IsFileOpen ( ) Func _AlreadyInArray ( $_SearchArray, $_Item ) $_Index = _ArraySearch ( $_SearchArray, $_Item ) If @error Then Return False Else If $_Index <> 0 Then Return True Else Return False EndIf EndIf EndFunc ;==> _AlreadyInArray ( ) AutoIt 3.3.14.2 X86 - SciTE 3.6.0 - WIN 8.1 X64 - Other Example Scripts Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now