Vous ne trouvez pas de réponse à votre problème ? Alors posez la question dans le forum. Souvenez-vous qu'il n'y a jamais de question bête, mais rester dans l'ignorance parce que l'on n'ose pas poser une question, ça c'est une erreur !

VDOWNLOAD - MULTIPLE TÉLÉCHARGEUR DE FICHIERS


Information sur la source

Catégorie :Réseau & Internet Niveau : Expert Date de création : 17/01/2004 Vu : 19 534

Note :
5 / 10 - par 4 personnes
5,00 / 10

  • 1

  • 2

  • 3

  • 4

  • 5

  • 6

  • 7

  • 8

  • 9

  • 10

Commentaire sur cette source (2)
Ajouter un commentaire et/ou une note

Description

Permet de télécharger des fichiers sur Internet. Vous pouvez en télécharger simultanément autant que vous voulez. Renvoi si vous le voulez à un alias que vous avez défini les informations de progression (taille du fichier, bits copiés, pourcentage et taux de transfert) et vous informe quand un téléchargement est fini.
 

Source

  • ;vdownload - Créé le vendredi 16 Janvier 2004 par Had`S - Version 1.0
  • ;$vdownload(name|_,AP|_,AF|_,url,emplacement).[bin|txt]
  • ;name = Nom du téléchargement. Il est évidemment préférable de mettre des noms différents (ou de mettre _) si vous faites plusieurs téléchargement en même temps. Si vous mettez _ le nom sera généré aléatoirement. Le nom du socket sera toujours vdownload_S où S est le nom du socket défini ou le nom du socket généré aléatoirement.
  • ;AP = Alias de progression. Le snippet renvoi à l'alias que vous mettez: $1=taille total du fichier, $2=bits-copiés, $3=pourcentage, $4=taux de transfert en bits/s, si vous mettez _ alors le snippet ne renverra pas les informations de progression à un alias.
  • ;AF = Alias de fin. Le snippet exécute l'alias que vous mettez quand le téléchargement est fini.
  • ;url = adresse du fichier à télécharger sur Internet.
  • ;emplacement = emplacement où le fichier téléchargé sera enregistré.
  • ;Par défaut, le snippet analyse le type de données (binaire ou texte) du fichier à télécharger afin d'écrire avec le type de données le plus approprié au fichier. Vous pouvez forcer le snippet à écrire les données en binaire ou en texte normal en mettant comme propriété : bin (binaire)ou txt (texte normal).
  • ;/vdownload <name|wildcard> <== pour annuler un ou plusieurs téléchargements.
  • ;Exemples d'utilisation inclus à la fin du code.
  • alias vdownload {
  • ;Si l'alias a été exécuté sous la forme d'un $identifeur...
  • if ($isid) {
  • if ($0 < 5) return Manque des paramètres
  • if ($1 == _) var %u = $r(a,z) $+ $r(1,9999) $+ $r(a,z) $+ $r(a,z) $+ $r(1,99) $+ $r(a,z)
  • else { if ($sockopen(download_ $+ $1)) return Erreur! Socket déja ouvert! | var %u = $1 }
  • ;Ecriture dans la hashtable
  • if ($2 != _) hadd -m vdownload %u $+ _progs $2
  • if ($3 != _) hadd -m vdownload %u $+ _fin $3
  • hadd -m vdownload %u $+ _host $gettok($iif($mid($4,1,7) == http:// && $len($4) > 7,$mid($4,8),$4),1,47)
  • hadd vdownload %u $+ _file / $+ $gettok($iif($mid($4,1,7) == http:// && $len($4) > 7,$mid($4,8),$4),2-,47)
  • hadd vdownload %u $+ _dest $5-
  • hadd vdownload %u $+ _tm $iif($findtok(bin txt,$prop,32),$prop,auto)
  • ;Ouverture du socket
  • sockopen vdownload_ $+ %u $hget(vdownload,%u $+ _host) 80
  • return OK
  • }
  • ;L'alias a été exécuté sous la forme d'une /commande...
  • else {
  • if (!$1) goto end
  • sockclose vdownload_ $+ $1-
  • if (* !isin $1-) $iif($fopen(vdownload_ $+ $1-),.fclose vdownload_ $+ $1-) | else .fclose vdownload_ $+ $1-)
  • if ($hget(vdownload)) {
  • hdel -w vdownload $1- $+ _*
  • ;Si aucun item n'est présent dans la hashtable, autant la supprimer.
  • if (!$hget(vdownload,0).item) .hfree vdownload
  • }
  • .timervdownload_ $+ $1- off
  • }
  • :end
  • }
  • on *:sockopen:vdownload_*:{
  • var %u = $gettok($sockname,2-,95)
  • ;Vérification d'erreur..
  • if ($sockerr) { echo $color(info) Erreur ! (1) | vdownload %u | halt }
  • sockwrite -n $sockname GET $hget(vdownload,%u $+ _file) HTTP/1.0
  • sockwrite -n $sockname HOST: $hget(vdownload,%u $+ _host)
  • sockwrite -n $sockname $crlf
  • hadd vdownload %u $+ _header no
  • hadd vdownload %u $+ _prog 0 | hadd vdownload %u $+ _tt 0
  • hadd vdownload %u $+ _taux 0
  • }
  • on *:sockread:vdownload_*:{
  • var %u = $gettok($sockname,2,95)
  • if ($hget(vdownload,%u $+ _header) == no) {
  • ;Donc si on est ici, ça veut dire qu'on s'apprête à recevoir les headers, et donc des informations utiles sur le fichier..
  • var %a
  • sockread %a
  • ;Analyse et détéction du type de fichier pour permettre au snippet de choisir la méthode d'écriture (binaire ou texte) ..
  • if (Content-Type: * iswm %a) {
  • hadd vdownload %u $+ _type $gettok(%a,2-,58)
  • if ($hget(vdownload,%u $+ _tm) == auto) {
  • if (text/plain isin $hget(vdownload,%u $+ _type)) || (text/html isin $hget(vdownload,%u $+ _type)) hadd vdownload %u $+ _tm txt
  • else hadd vdownload %u $+ _tm bin
  • }
  • }
  • if (Content-Length: * iswm %a) hadd vdownload %u $+ _taille $gettok(%a,2-,58)
  • ;Fin des headers, signalons donc que les headers ont été reçus.
  • if (!%a) { hadd vdownload %u $+ _header yes | .timervdownload_ $+ %u 0 1 vdownloadtimer %u }
  • }
  • else {
  • if (!$fopen(vdownload_ $+ %u)) .fopen -no vdownload_ $+ %u " $+ $hget(vdownload,%u $+ _dest) $+ "
  • ;Incrémentation du nombre de bits reçus.
  • hinc vdownload %u $+ _prog $sock($sockname).rq
  • hinc vdownload %u $+ _tt $sock($sockname).rq
  • ;Exécution de l'alias de progression (si il y en a un) défini par l'utilisateur
  • if ($hget(vdownload,%u $+ _progs)) $hget(vdownload,%u $+ _progs) $hget(vdownload,%u $+ _taille) $hget(vdownload,%u $+ _prog) $round($calc(($hget(vdownload,%u $+ _prog) / $hget(vdownload,%u $+ _taille)) *100) ,1) $+ % $hget(vdownload,%u $+ _taux)
  • if ($hget(vdownload,%u $+ _tm) == txt) {
  • var %b
  • ;Utilisation de $sockbr pour lire toute les informations...
  • :reading | sockread -f %b | if (!$sockbr) return | .fwrite vdownload_ $+ %u %b $crlf | goto reading
  • }
  • else { sockread &a | .fwrite -b vdownload_ $+ %u &a }
  • }
  • }
  • ;Pour obtenir le nombre de bits reçus en 1 seconde
  • alias -l vdownloadtimer {
  • if ($hget(vdownload,0).item) {
  • hadd vdownload $1 $+ _taux $hget(vdownload,$1 $+ _tt) | hadd vdownload $1 $+ _tt 0
  • }
  • }
  • on *:sockclose:vdownload_*:{
  • ;Fermeture des accès fichiers, et suppresion des données, timer...
  • if ($fopen($sockname)) .fclose $sockname
  • var %u = $gettok($sockname,2,95) , %fin = $hget(vdownload,$gettok($sockname,2-,95) $+ _fin)
  • if ($hget(vdownload)) hdel -w vdownload %u $+ _*
  • if (!$hget(vdownload,0).item) .hfree -w vdownload
  • .timervdownload_ $+ %u off
  • ;Fait la commande de fin rentré par l'utilisateur
  • if (%fin) %fin
  • }
  • ;Exemples
  • ;-Télécharge simplement le logo de Google France et l'ouvre à la fin du téléchargement.
  • ;//var %i = $vdownload(google,_,run google.gif,http://www.google.fr/intl/fr_fr/images/logo.gif,google.gif)
  • ;-Télécharge mIRC 6.12 en affichant la progression et indiquant à la fin que le téléchargement est terminé.
  • ;//var %i = $vdownload(_,progtmp-01-,Echo 4 -s Téléchargement de mIRC Terminé.,http://webperso.easynet.fr/mirc/mirc612.exe,download\\mIRC612.exe)
;vdownload - Créé le vendredi 16 Janvier 2004 par Had`S - Version 1.0


;$vdownload(name|_,AP|_,AF|_,url,emplacement).[bin|txt]

;name = Nom du téléchargement. Il est évidemment préférable de mettre des noms différents (ou de mettre _) si vous faites plusieurs téléchargement en même temps. Si vous mettez _ le nom sera généré aléatoirement. Le nom du socket sera toujours vdownload_S  où S est le nom du socket défini ou le nom du socket généré aléatoirement.
;AP = Alias de progression. Le snippet renvoi à l'alias que vous mettez: $1=taille total du fichier, $2=bits-copiés, $3=pourcentage, $4=taux de transfert en bits/s, si vous mettez _ alors le snippet ne renverra pas les informations de progression à un alias.
;AF  = Alias de fin. Le snippet exécute l'alias que vous mettez quand le téléchargement est fini.
;url  = adresse du fichier à télécharger sur Internet.
;emplacement = emplacement où le fichier téléchargé sera enregistré.
;Par défaut, le snippet analyse le type de données (binaire ou texte) du fichier à télécharger afin d'écrire avec le type de données le plus approprié au fichier. Vous pouvez forcer le snippet à écrire les données en binaire ou en texte normal en mettant comme propriété : bin (binaire)ou txt (texte normal).

;/vdownload <name|wildcard>  <== pour annuler un ou plusieurs téléchargements.

;Exemples d'utilisation inclus à la fin du code.

alias vdownload {
  ;Si l'alias a été exécuté sous la forme d'un $identifeur...
  if ($isid) {
    if ($0 <  5) return Manque des paramètres
    if ($1 == _) var %u = $r(a,z) $+ $r(1,9999) $+ $r(a,z) $+ $r(a,z) $+ $r(1,99) $+ $r(a,z)
    else { if ($sockopen(download_ $+ $1)) return Erreur! Socket déja ouvert! | var %u = $1 }
    ;Ecriture dans la hashtable
    if ($2 != _) hadd -m vdownload %u $+ _progs $2
    if ($3 != _) hadd -m vdownload %u $+ _fin $3
    hadd -m vdownload %u $+ _host $gettok($iif($mid($4,1,7) == http:// && $len($4) > 7,$mid($4,8),$4),1,47)
    hadd  vdownload %u $+ _file / $+ $gettok($iif($mid($4,1,7) == http:// && $len($4) > 7,$mid($4,8),$4),2-,47)
    hadd vdownload %u $+ _dest $5-
    hadd vdownload %u $+ _tm $iif($findtok(bin txt,$prop,32),$prop,auto)
    ;Ouverture du socket
    sockopen vdownload_ $+ %u  $hget(vdownload,%u $+ _host) 80
    return OK
  }
  ;L'alias a été exécuté sous la forme d'une /commande...
  else {
    if (!$1) goto end
    sockclose vdownload_ $+ $1-
    if (* !isin $1-) $iif($fopen(vdownload_  $+ $1-),.fclose vdownload_ $+ $1-) | else .fclose vdownload_ $+ $1-)
    if ($hget(vdownload)) {
      hdel -w vdownload $1- $+ _*
      ;Si aucun item n'est présent dans la hashtable, autant la supprimer.
      if (!$hget(vdownload,0).item) .hfree vdownload
    }
    .timervdownload_ $+ $1- off
  }
  :end
}
on *:sockopen:vdownload_*:{
  var %u = $gettok($sockname,2-,95)
  ;Vérification d'erreur..
  if ($sockerr) { echo $color(info)  Erreur ! (1) | vdownload %u | halt }
  sockwrite -n $sockname GET $hget(vdownload,%u $+ _file) HTTP/1.0
  sockwrite -n $sockname  HOST: $hget(vdownload,%u $+ _host)
  sockwrite -n $sockname $crlf
  hadd vdownload %u $+ _header no
  hadd vdownload %u $+ _prog 0 | hadd vdownload %u $+ _tt 0
  hadd vdownload %u $+ _taux 0
}
on *:sockread:vdownload_*:{
  var %u = $gettok($sockname,2,95)
  if ($hget(vdownload,%u $+ _header) == no) {
    ;Donc si on est ici, ça veut dire qu'on s'apprête à recevoir les headers, et donc des informations utiles sur le fichier..
    var %a
    sockread  %a
    ;Analyse et détéction du type de fichier pour permettre au snippet de choisir la méthode d'écriture (binaire ou texte) ..
    if (Content-Type: * iswm %a) {
      hadd vdownload %u $+ _type $gettok(%a,2-,58)
      if ($hget(vdownload,%u $+ _tm) == auto) {
        if (text/plain isin $hget(vdownload,%u $+ _type)) || (text/html isin $hget(vdownload,%u $+ _type)) hadd vdownload %u $+ _tm txt
        else hadd vdownload %u $+ _tm bin
      }
    }
    if (Content-Length: * iswm %a) hadd vdownload %u $+ _taille $gettok(%a,2-,58)
    ;Fin des headers, signalons donc que les headers ont été reçus.
    if (!%a) { hadd vdownload %u $+ _header yes | .timervdownload_ $+ %u 0 1 vdownloadtimer %u }
  }
  else {
    if (!$fopen(vdownload_ $+ %u)) .fopen -no vdownload_ $+ %u " $+ $hget(vdownload,%u $+ _dest) $+ "
    ;Incrémentation du nombre de bits reçus.
    hinc vdownload  %u $+ _prog $sock($sockname).rq
    hinc vdownload  %u $+ _tt $sock($sockname).rq
    ;Exécution de l'alias de progression (si il y en a un) défini par l'utilisateur
    if ($hget(vdownload,%u $+ _progs)) $hget(vdownload,%u $+ _progs) $hget(vdownload,%u $+ _taille) $hget(vdownload,%u $+ _prog) $round($calc(($hget(vdownload,%u $+ _prog) / $hget(vdownload,%u $+ _taille)) *100) ,1) $+ % $hget(vdownload,%u $+ _taux)
    if ($hget(vdownload,%u $+ _tm) == txt) {
      var %b
    ;Utilisation de $sockbr pour lire toute les informations...
      :reading | sockread  -f  %b | if (!$sockbr) return | .fwrite  vdownload_ $+ %u %b $crlf | goto reading
    }
    else { sockread &a | .fwrite -b vdownload_ $+ %u &a }
  }
}
;Pour obtenir le nombre de bits reçus en 1 seconde
alias -l vdownloadtimer {
  if ($hget(vdownload,0).item) {
    hadd vdownload $1 $+ _taux $hget(vdownload,$1 $+ _tt) | hadd vdownload $1 $+ _tt 0
  }
}
on *:sockclose:vdownload_*:{
  ;Fermeture des accès fichiers, et suppresion des données, timer...
  if ($fopen($sockname)) .fclose $sockname
  var %u = $gettok($sockname,2,95) , %fin = $hget(vdownload,$gettok($sockname,2-,95) $+ _fin)
  if ($hget(vdownload)) hdel -w vdownload %u $+ _*
  if (!$hget(vdownload,0).item) .hfree -w vdownload
  .timervdownload_ $+ %u off
  ;Fait la commande de fin rentré par l'utilisateur
  if (%fin) %fin
}

;Exemples
;-Télécharge simplement le logo de Google France et l'ouvre à la fin du téléchargement.
;//var %i = $vdownload(google,_,run google.gif,http://www.google.fr/intl/fr_fr/images/logo.gif,google.gif)

;-Télécharge mIRC 6.12 en affichant la progression et indiquant à la fin que le téléchargement est terminé.
;//var %i = $vdownload(_,progtmp-01-,Echo 4 -s Téléchargement de mIRC Terminé.,http://webperso.easynet.fr/mirc/mirc612.exe,download\\mIRC612.exe)

Commentaires et avis

signaler à un administrateur
Commentaire de Kerrigan le 19/01/2004 19:09:15

pas mal du tout

signaler à un administrateur
Commentaire de JStaline le 30/01/2006 22:46:54

Chez moi ca ne marche pas avec certaines images, elle ne veulent plus s'ouvrir.

Ajouter un commentaire



Nos sponsors

Sondage...

CalendriCode

Janvier 2009
LMMJVSD
   1234
567891011
12131415161718
19202122232425
262728293031 

Consulter la suite du CalendriCode



Développement réalisé par Nicolas SOREL (Nix) avec l'aide de : Cyril DURAND et Emmanuel BAÏSE, Merci à Vincent pour ses précieux conseils
CodeS-SourceS.com© Toute reproduction même partielle est interdite sauf accord écrit du Webmaster
CodeS-SourceS.com© est une marque déposée tous droits réservés
Temps d'éxécution de la page : 0,218 sec

Google Coop CodeS-SourceS Google Coop CodeS-SourceS


Certaines images présentes sur le site (notament certains avatars) sont issues des collections IconShock, donc si vous souhaitez utiliser ces icons vous devez les acheter, ne les copiez pas et ne utilisez pas dans vos sites et applications sans les avoir commandé.