Advertisement
toan9xpro2012

Youtube API test (autoit) get title

Nov 19th, 2014
285
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
AutoIt 2.95 KB | None | 0 0
  1. #include <Inet.au3>
  2.  
  3. $link = 'http://www.youtube.com/watch?v=IG-pvi3F53E'
  4. $id = 'IG-pvi3F53E' ;Tự lấy trên link xuống vì lười code
  5. $get = 'http://www.youtube.com/get_video_info?video_id=' & $id
  6.  
  7. $rev = _INetGetSource($get) ;Lấy dữ liệu trả về
  8. $tit = ''
  9. For $i = 1 To StringLen($rev)
  10.     If StringMid($rev,$i,6)= 'title=' Then ;Tìm chuỗi 'title='
  11.         For $j = $i+6 To StringLen($rev)
  12.             If StringMid($rev,$j,1) = '&' Then ;Điều kiện dừng
  13.                 ExitLoop
  14.             Else
  15.                 $tit = $tit & StringMid($rev,$j,1) ;Nếu không dừng thì thực hiện việc lấy chuỗi
  16.             EndIf
  17.         Next
  18.     EndIf
  19. Next
  20.  
  21. MsgBox(0,'',_UnicodeURLDecode($tit)) ;Giải mã URL và cho vào msgbox
  22.  
  23.  
  24. ;Phần này là UDF Mã hóa, giải mã URL
  25.  
  26. ;===============================================================================
  27. ; _UnicodeURLEncode()
  28. ; Description: : Encodes an unicode string to be URL-friendly
  29. ; Parameter(s): : $UnicodeURL - The Unicode String to Encode
  30. ; Return Value(s): : The URL encoded string
  31. ; Author(s): : Dhilip89
  32. ; Note(s): : -
  33. ;
  34. ;===============================================================================
  35.  
  36. Func _UnicodeURLEncode($UnicodeURL)
  37.     $UnicodeBinary = StringToBinary ($UnicodeURL, 4)
  38.     $UnicodeBinary2 = StringReplace($UnicodeBinary, '0x', '', 1)
  39.     $UnicodeBinaryLength = StringLen($UnicodeBinary2)
  40.     Local $EncodedString
  41.     For $i = 1 To $UnicodeBinaryLength Step 2
  42.         $UnicodeBinaryChar = StringMid($UnicodeBinary2, $i, 2)
  43.         If StringInStr("$-_.+!*'(),;/?:@=&abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890", BinaryToString ('0x' & $UnicodeBinaryChar, 4)) Then
  44.             $EncodedString &= BinaryToString ('0x' & $UnicodeBinaryChar)
  45.         Else
  46.             $EncodedString &= '%' & $UnicodeBinaryChar
  47.         EndIf
  48.     Next
  49.     Return $EncodedString
  50. EndFunc   ;==>_UnicodeURLEncode
  51.  
  52.  
  53.  
  54. ;===============================================================================
  55. ; _UnicodeURLDecode()
  56. ; Description: : Tranlates a URL-friendly string to a normal string
  57. ; Parameter(s): : $toDecode - The URL-friendly string to decode
  58. ; Return Value(s): : The URL decoded string
  59. ; Author(s): : nfwu, Dhilip89
  60. ; Note(s): : Modified from _URLDecode() that's only support non-unicode.
  61. ;
  62. ;===============================================================================
  63. Func _UnicodeURLDecode($toDecode)
  64.     Local $strChar = "", $iOne, $iTwo
  65.     Local $aryHex = StringSplit($toDecode, "")
  66.     For $i = 1 To $aryHex[0]
  67.         If $aryHex[$i] = "%" Then
  68.             $i = $i + 1
  69.             $iOne = $aryHex[$i]
  70.             $i = $i + 1
  71.             $iTwo = $aryHex[$i]
  72.             $strChar = $strChar & Chr(Dec($iOne & $iTwo))
  73.         Else
  74.             $strChar = $strChar & $aryHex[$i]
  75.         EndIf
  76.     Next
  77.     $Process = StringToBinary (StringReplace($strChar, "+", " "))
  78.     $DecodedString = BinaryToString ($Process, 4)
  79.     Return $DecodedString
  80. EndFunc   ;==>_UnicodeURLDecode
  81. #endregion
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement