Latest news
Android

sourceforge.net: API ähnlich aktuelle Datei-Download-URLs ermitteln

An dieser Stelle nur ein kleines Beispiel, wie man mit PHP von sourceforge.net API ähnlich die Download URL zu einer Datei-Version eines Spiegel-Servers ermittelt mit Hilfe meiner sourceforge.net SF.net Klasse, die die Snoopy-Klasse erweitert, welche einen Web-Browser simuliert.

Hier die Klasse:

< ?php
/**

  • @see http://snoopy.sourceforge.net/
    /
    require_once (dirname(FILE) . DIRECTORY_SEPARATOR . ‘Snoopy.class.php’);
    /**
  • small and easy API like sourceforge.net file access class
  • @author Holger Schadeck holger@schadeck.eu
  • @access public
    /
    class SFnet extends Snoopy {
    var $sProjectsBaseUrl = ‘http://sourceforge.net/projects/‘;
    var $sProjectBaseUrl = ‘http://sourceforge.net/project/‘;
    var $sDownloadBaseUrl = ‘http://downloads.sourceforge.net/‘;
    var $host = ‘sourceforge.net’;
    var $agent = ‘Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.8.1.4) Gecko/20070515 Firefox/2.0.0.4’;
    var $aProjectsFilesData = array ();
    /**

    • gets links and data
    • @access private
    • @param string $sUrl URL
    • @return mixed array of links data or boolean false
      */
      function _getLinks($sUrl) {
      $expandlinks = $this->expandlinks;
      $this->expandlinks = false;
      if ($this->fetch($sUrl)) {
      $aLinks = $this->_striplinks($this->results);
      $aLinks = array_combine($aLinks, $this->_expandlinks($aLinks, $sUrl));
      $aReturnLinks = array ();
      foreach ($aLinks as $sLocal => $sRemote) {
      if (preg_match(‘/<a .

    ?href=’ . preg_quote($sLocal, ‘/’) . ‘.?>(.?)< \/a>/i’, $this->results, $aFound)) {
    $sRemote = html_entity_decode(utf8_decode($sRemote));
    $sLocal = html_entity_decode(utf8_decode($sLocal));
    $aReturnLinks = array (
    ‘text’ => trim(html_entity_decode(utf8_decode($aFound
    ))), ‘url_download’ => $sRemote, ‘data’ => parse_url($sRemote), ‘args’ => array ());
    parse_str($aReturnLinks, $aReturnLinks);
    }
    }
    $mReturn = $aReturnLinks;
    } else {
    $mReturn = (false);
    }
    $this->expandlinks = $expandlinks;
    return $mReturn;
    }
    /**

  • Gets and caches the file links data of all packages for a project
  • @access public
  • @param string $sProject name of a project (exmaple: http://sourceforge.net/projects/snoopy/ => snoopy)
  • @return array with project file links data arrays, each with the keys: "text", "url_download", "data" and "args"
    /
    function getFilesOfProject($sProject) {
    $sProjectUrl = $this->sProjectsBaseUrl . $sProject . ‘/’;
    $sDownloadUrl = $this->sDownloadBaseUrl . $sProject;
    if (!array_key_exists($sProject, $this->aProjectsFilesData) && $aLinks = $this->_getLinks($sProjectUrl)) {
    $aReturnLinks = array ();
    foreach (preg_grep(‘/^’ . preg_quote($this->sProjectBaseUrl . ‘showfiles.php’, ‘/’) . ‘.
    group_id=(+?).?#downloads$/’, array_keys($aLinks)) as $iKey => $sUrl) {
    if ($aLinks = $this->_getLinks($sUrl)) {
    $this->aProjectsFilesData = array ();
    foreach (preg_grep(‘/^’ . preg_quote($sDownloadUrl, ‘/’) . ‘/’, array_keys($aLinks)) as $iKey => $sFileUrl) {
    $this->aProjectsFilesData)] = & $aLinks;
    }
    return $this->aProjectsFilesData;
    } else {
    return array ();
    }
    break;
    }
    return array ();
    } else
    if (array_key_exists($sProject, $this->aProjectsFilesData)) {
    return $this->aProjectsFilesData;
    } else {
    return array ();
    }
    }
    /**
  • gets the url for a project file
  • @access public
  • @uses SFnet::getFilesOfProject to get cached or load not cached project files data
  • @param string $sProject name of the project
  • @param string $sFile name of the release file
  • @return mixed string URL of project file download or false;
    */
    function getDownloadUrlForProjectFile($sProject, $sFile) {
    $aProjectFilesData = & $this->getFilesOfProject($sProject);
    return ((array_key_exists($sFile, $aProjectFilesData)) ? $aProjectFilesData : (false));
    }
    /**
  • gets the modification timestamp for a project file
  • @access public
  • @uses SFnet::getFilesOfProject to get cached or load not cached project files data
  • @param string $sProject name of the project
  • @param string $sFile name of the release file
  • @return string timestamp of project file;
    */
    function getTimeForProjectFile($sProject, $sFile) {
    $aProjectFilesData = & $this->getFilesOfProject($sProject);
    return ((array_key_exists($sFile, $aProjectFilesData) && array_key_exists(‘modtime’, $aProjectFilesData)) ? $aProjectFilesData : (false));
    }
    }
    ?>

    Hier das Beispiel:

    < ?php
    /**

  • Just an example of sourceforge.net.php
  • @access public
  • @author Holger Schadeck
    */
    /**
  • including the SFnet class
    */
    require_once (‘lib/sourceforge.net.php’);
    $SFprojects = new SFnet();
    /**
  • declare the target project
    */
    $sProject = ‘mingw’;
    /**
  • loop over project file
    */
    foreach ($SFprojects->getFilesOfProject($sProject) as $sFile => $aFileData) {
    /**

    • show each file with download URL and modification timestamp
    • the use of SFnet::getDownloadUrlForProjectFile and SFnet::getTimeForProjectFile methods normally make no sense,
    • if its project name is the same as the project name of the project files loop,
    • because you can get the data from the file data array, here $aFileData and $aFileData];
    • @see SFnet::getFilesOfProject
      */
      echo $sFile . ‘ => ‘ . $SFprojects->getDownloadUrlForProjectFile($sProject, $sFile) . ‘ (Modifiziert: ‘ . $SFprojects->getTimeForProjectFile($sProject, $sFile) . ‘)

  • ‘;
    }
    ?>

    Wie man vielleich sieht, kann man sogar den Timestamp des Änderungsdatums ermitteln.
    Und hier das ganze zum Downloaden:

    Siehe auch  Medien hochqualitativ hardwarebeschleunigt unter Kontrolle

    One Comment

    1. Funzt nicht bei mir 🙁

      Warning: array_combine() expects parameter 1 to be array, null given in ..SFnet/lib/sourceforge.net.php on line 31

      Warning: Invalid argument supplied for foreach() in …SFnet/lib/sourceforge.net.php on line 33

      Schade sowas such ich nämlich.

    Schreibe einen Kommentar

    Deine E-Mail-Adresse wird nicht veröffentlicht.

    Ads Blocker Image Powered by Code Help Pro

    Werbeblocker erkannt!!! / Ads Blocker Detected!!!

    Wir haben festgestellt, dass Sie Erweiterungen verwenden, um Anzeigen zu blockieren. Bitte unterstützen Sie uns, indem Sie diese Werbeblocker deaktivieren.

    We have detected that you are using extensions to block ads. Please support us by disabling these ads blocker.