; ; Téléchargement de vidéo arte avec VLC v1.3b ; #include #include #include #include #include $nom="Téléchargement Arte avec VLC - v1.3b" $batch=StringTrimRight(@ScriptFullPath,4)&".bat" $title="" $url="" $urlbis="" $desc="" $mms="" ; Permet d'éteindre l'ordinateur à la fin du batch si nécessaire if $CmdLine[0]>0 AND $CmdLine[1]=="shutdown" Then FileDelete($batch) Arret() Endif ; Récupération de l'URL et du titre dans la fenêtre ouverte de firefox $winlist = WinList() For $i = 1 to $winlist[0][0] If StringInStr ( $winlist[$i][0], "ARTE+7") Then WinActivate($winlist[$i][0]) Send("^u") WinWaitNotActive($winlist[$i][0]) Send("^a") Send("^c") Winclose("[active]") $source=ClipGet() $array = StringRegExp($source, '(?i)(.*?) [-] ARTE[+]7(?i)', 2) if UBound($array)>0 Then $tmp=StringReplace($array[1],"'"," ") $title=@ScriptDir&"\"&StringRegExpReplace($tmp,"[^0-9A-Za-z-éÉ()èÈçÇàÀêÊîÎëËïÏùô ]","")&".ogv" EndIf $array = StringRegExp($source, '(?i)http://.*HQ.*?[.]wmv(?i)', 2) if UBound($array)>0 Then $url=$array[0] Endif $array = StringRegExp($source, '(?i)http://.*?[.]wmv(?i)', 3) if UBound($array)>0 Then For $j = 1 to UBound($array) if (NOT StringInStr($url,$array[$j-1])) AND (NOT StringInStr($urlbis,$array[$j-1])) Then $urlbis&=$array[$j-1]&"|" Endif Next Endif $array = StringRegExp($source, '(?i)(?s)
(.*?)
(?i)', 2) if UBound($array)>0 Then $desc=""&@CR&$array[1]&@CR&@CR&"" EndIf EndIf Next ; Affichage de l'interface GuiCreate($nom, 600, 300) GuiCtrlCreateLabel("Liste:", 20, 193) $_liste=GuiCtrlCreateList("", 70, 190, 450, 100,BitXOR ($GUI_SS_DEFAULT_LIST,$LBS_SORT)) GUICtrlSetTip(-1,"Liste accessible en lançant directement "&$batch) $dataliste="" if FileExists($batch) Then $handle=FileOpen($batch,0) $line=FileReadLine($handle) $list=0 while $line If $list Then $array = StringRegExp($line, 'url="(?i)(.*?[.]mpg)(?i)', 3) if UBound($array)>0 Then $dataliste&=AnsiToOem($array[0],0)&"|" Endif EndIf If StringInStr($line,"shutdown") Then GUICtrlSetState($_shut,$GUI_CHECKED) EndIf If StringInStr($line,":batch") Then $list=1 EndIf $line=FileReadLine($handle) Wend FileClose($handle) GUICtrlSetData($_liste,$dataliste) EndIf $_del = GUICtrlCreateButton(" X ", 538, 190, 40, 40, $BS_ICON) GUICtrlSetTip(-1,"Supprimer ce téléchargement") GUICtrlSetImage(-1, "shell32.dll", 240) GUICtrlSetState($_del,$GUI_DISABLE) GuiCtrlCreateLabel("Url:", 20, 23) $_url=GuiCtrlCreateInput("", 70, 20, 450) GuiCtrlCreateLabel("Nom:", 20, 63) $_title=GuiCtrlCreateInput($title, 70, 60, 450) $_ftitle=GuiCtrlCreateButton(" ... ", 550, 60) GUICtrlSetTip(-1,"Choisir où enregistrer la vidéo") GuiCtrlCreateLabel("Vlc:", 20, 103) $vlc = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\VideoLAN\VLC", "") if NOT FileExists($vlc) Then $vlc="C:\Program Files\VideoLAN\VLC\vlc.exe" EndIf if NOT FileExists($vlc) Then $vlc="" EndIf $_vlc=GuiCtrlCreateInput($vlc, 70, 100, 450) $_fvlc=GuiCtrlCreateButton(" ... ", 550, 100) GUICtrlSetTip(-1,"Désigner l'emplacement de VLC") $_go=GuiCtrlCreateButton(" Télécharger immédiatement ", 50, 140) $_traiter=GuiCtrlCreateButton("L", 538, 245,40,40, $BS_ICON) GUICtrlSetTip(-1,"Lancer tous ces téléchargements") GUICtrlSetImage(-1, "shell32.dll", 148) $_poubelle=GuiCtrlCreateButton("P", 10, 245,40,40, $BS_ICON) GUICtrlSetImage(-1, "shell32.dll", 191) GUICtrlSetTip(-1,"Supprimer toute la liste") $_batch=GuiCtrlCreateButton(" Ajouter à la liste ", 240, 140) if NOT FileExists($batch) Then GUICtrlSetState($_traiter,$GUI_DISABLE) GUICtrlSetState($_poubelle,$GUI_DISABLE) Endif $_shut=GUICtrlCreateCheckbox ("Eteindre après", 360,142,default,default,$BS_RIGHTBUTTON) GuiCtrlCreateLabel("Format:", 470, 145) $_type=GUICtrlCreateCombo("Mpg", 510, 140, default, default, $CBS_DROPDOWNLIST) GUICtrlSetData(-1, "Ogv", "Ogv") GUICtrlSetTip(-1,"Mpeg2 ou Ogg/Theora") ; Gestion du menu GuiSetState() If $url Then ;InetGet($url, @ScriptDir&"\arte.txt", 1) ;$array = StringRegExp(FileRead(@ScriptDir&"\arte.txt"), '(?i)mms://.*?[.]wmv(?i)', 3) ;if UBound($array)>0 Then $mms=$array[0] ;FileDelete(@ScriptDir&"\arte.txt") GUICtrlSetData($_url,$url) GUICtrlSetTip($_url,$url) EndIf While 1 Switch GuiGetMsg() case $GUI_EVENT_CLOSE ExitLoop case $_type $tmp=GUICtrlRead($_title) If GUICtrlRead($_type)=="Mpg" AND StringRight($tmp,3)="ogv" Then GUICtrlSetData($_title,StringMid($tmp,1,StringLen($tmp)-3)&"mpg") If GUICtrlRead($_type)=="Ogv" AND StringRight($tmp,3)="mpg" Then GUICtrlSetData($_title,StringMid($tmp,1,StringLen($tmp)-3)&"ogv") case $_ftitle If GUICtrlRead($_type)=="Mpg" Then $dest = FileOpenDialog("Emplacement du fichier cible ?", @ScriptDir, "Vidéo Mpeg2 (*.mpg)", 2 ) Else $dest = FileOpenDialog("Emplacement du fichier cible ?", @ScriptDir, "Vidéo Theora (*.ogv)", 2 ) EndIf If NOT @error Then GUICtrlSetData($_title,$dest) EndIf case $_fvlc $dest = FileOpenDialog("Emplacement de VLC ?", @ProgramFilesDir, "Executable (*.exe)", 2 ) If NOT @error Then GUICtrlSetData($_vlc,$dest) EndIf case $_go $vlc=Check() if $vlc Then If GUICtrlRead($_shut)==$GUI_CHECKED Then GUICtrlSetState($_traiter,$GUI_DISABLE) GUICtrlSetState($_go,$GUI_DISABLE) GUICtrlSetState($_batch,$GUI_DISABLE) GUICtrlSetState($_del,$GUI_DISABLE) GUICtrlSetState($_shut,$GUI_DISABLE) GUICtrlSetState($_poubelle,$GUI_DISABLE) RunWait ($vlc) Arret() Else Run($vlc) exit Endif Endif case $_batch $vlc=Check() if $vlc Then if NOT FileExists($batch) Then $data='@echo off'&@CRLF&'title ARTE+7'&@CRLF&'if "%1"=="batch" goto batch'&@CRLF&AnsiToOem('echo Merci de ne pas fermer cette fenêtre, téléchargements en cours...',1)&@CRLF&'call %0 batch'&@CRLF if GUICtrlRead($_shut)==$GUI_CHECKED Then $data&='"'&@ScriptFullPath&'" shutdown'&@CRLF Endif FileWrite($batch,$data&'del %0'&@CRLF&'exit'&@CRLF&':batch'&@CRLF&AnsiToOem($vlc,1)&@CRLF) Else FileWrite($batch,AnsiToOem($vlc,1)&@CRLF) EndIf $dataliste&=GUICtrlRead($_title)&"|" GUICtrlSetData($_liste,GUICtrlRead($_title)&"|") GUICtrlSetState($_traiter,$GUI_ENABLE) GUICtrlSetState($_poubelle,$GUI_ENABLE) Endif case $_del $enleve=StringReplace(StringReplace(AnsiToOem(GUICtrlRead($_liste),1),".","[.]"),"\","\\") If $enleve Then If (UBound(StringRegExp($dataliste,".*?([|]).*?",3))==1) Then FileDelete($batch) $dataliste="" GUICtrlSetState($_traiter,$GUI_DISABLE) GUICtrlSetState($_poubelle,$GUI_DISABLE) Else $handle=FileOpen($batch,0) $data=FileRead($handle) Fileclose($handle) $data=StringRegExpReplace($data,@CRLF&"(.*?)"&$enleve&"(.*?)"&@CRLF,@CRLF) $handle=FileOpen($batch,2) FileWrite($handle,$data) Fileclose($handle) $dataliste=StringReplace($dataliste,GUICtrlRead($_liste)&"|","") EndIf GUICtrlSetData($_liste, "") GUICtrlSetData($_liste,$dataliste) GUICtrlSetState($_del,$GUI_DISABLE) EndIf case $_shut If FileExists($batch) Then $handle=FileOpen($batch,0) $data=FileRead($handle) Fileclose($handle) $handle=FileOpen($batch,2) If GUICtrlRead($_shut)==$GUI_CHECKED Then FileWrite($handle,StringReplace($data,"batch"&@CRLF&"del","batch"&@CRLF&'"'&@ScriptFullPath&'" shutdown'&@CRLF&"del")) Else FileWrite($handle,StringReplace($data,"batch"&@CRLF&'"'&@ScriptFullPath&'" shutdown'&@CRLF&"del","batch"&@CRLF&"del")) EndIf Fileclose($handle) EndIf case $_liste If GUICtrlRead($_liste) Then GUICtrlSetState($_del,$GUI_ENABLE) Else GUICtrlSetState($_del,$GUI_DISABLE) Endif case $_traiter Run($batch) exit case $_poubelle FileDelete($batch) $dataliste="" GUICtrlSetState($_traiter,$GUI_DISABLE) GUICtrlSetState($_poubelle,$GUI_DISABLE) GUICtrlSetData($_liste, "") GUICtrlSetData($_liste,$dataliste) GUICtrlSetState($_del,$GUI_DISABLE) EndSwitch WEnd ; prépare l'appel à VLC Func Check() if Not GUICtrlRead($_url) Then MsgBox(16,"Erreur !","Il faut me dire quoi télécharger !") return 0 EndIf if Not GUICtrlRead($_title) Then MsgBox(16,"Erreur !","Et on le met où le fichier téléchargé ?") return 0 EndIf if FileExists(GUICtrlRead($_title)) Then if (MsgBox(4+32,"Attention ?","Le fichier "&GUICtrlRead($_title)&" existe déja; On le remplace ?")==7) Then return 0 Endif EndIf if NOT FileExists(GUICtrlRead($_vlc)) Then MsgBox(16,"Erreur !","Pas trouvé VLC... Il est où ?") return 0 EndIf If StringLen($desc)>0 Then $info=FileOpen(GUICtrlRead($_title)&".html",2) FileWrite($info,$desc) FileClose($info) Endif If GUICtrlRead($_type)=="Mpg" Then return '"'&GUICtrlRead($_vlc)&'" "'&GUICtrlRead($_url)&'" :sout=#transcode{vcodec=mp2v,vb=768,acodec=mp3,ab=128}:duplicate{dst=std{access=file,mux=ts,dst="'&GUICtrlRead($_title)&'"}}' Else return '"'&GUICtrlRead($_vlc)&'" "'&GUICtrlRead($_url)&'" :sout=#transcode{vcodec=theo,vb=768,acodec=vorb,ab=96}:duplicate{dst=std{access=file,mux=ogg,dst="'&GUICtrlRead($_title)&'"}}' EndIf EndFunc ; Fonction pour convertir de ANSI vers ASCII pour écriture des fichiers BATCH windows Func AnsiToOem($src,$sens) $ASCII = Chr(132) & Chr(148) & Chr(129) & Chr(225) & Chr(142) & Chr(153) & Chr(154) & Chr(128) & Chr(130) & Chr(131) & Chr(133) & Chr(134) & Chr(135) & Chr(136) & Chr(137) & Chr(138) & Chr(139) & Chr(140) & Chr(143) & Chr(144) & Chr(147) & Chr(150) & Chr(151) & Chr(20) & Chr(145) & Chr(146) & Chr(155) & Chr(156) & Chr(166) & Chr(167) & Chr(171) & Chr(172) & Chr(237) & Chr(241) & Chr(246) & Chr(253) & Chr(21) & Chr(157) $ANSI = Chr(228) & Chr(246) & Chr(252) & Chr(223) & Chr(196) & Chr(214) & Chr(220) & Chr(199) & Chr(233) & Chr(226) & Chr(224) & Chr(229) & Chr(231) & Chr(234) & Chr(235) & Chr(232) & Chr(239) & Chr(238) & Chr(197) & Chr(201) & Chr(244) & Chr(251) & Chr(249) & Chr(182) & Chr(230) & Chr(198) & Chr(162) & Chr(163) & Chr(170) & Chr(186) & Chr(189) & Chr(188) & Chr(216) & Chr(177) & Chr(247) & Chr(178) & Chr(167) & Chr(165) if $sens Then $in=$ANSI $out=$ASCII Else $in=$ASCII $out=$ANSI Endif $dst="" For $i = 1 to Stringlen($src) $car=StringMid($src,$i,1) $Pos = StringInStr($in, $car) If $Pos = 0 Then $dst&=$car Else $dst&=StringMid($out,$pos,1) Endif Next Return $dst EndFunc Func Arret() If MsgBox(0,"Arrêt ?","L'ordinateur va s'arrêter dans 30s. Vous pouvez encore l'empêcher en cliquant sur OK !",30)==1 Then exit Endif ShutDown(9) exit EndFunc