Menu

Show posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Show posts Menu

Messages - svezij

#1
Software / Re: Nefunkční stahování z Idnes.cz
August 21, 2013, 12:59:06 PM
Opět zdravím, nevím, jestli se to tu smí nebo nesmí, ale napsal jsem jednoduchou funkci v PHP, přes kterou je možné přímo stáhnout video z idnes.cz. Bohužel nemám přístupný žádný hosting a tak to nemůžu dát přímo na web a napojit na jednoduchý formulář, a tak je to uděláno jen pro "znalejší" a stáhne to soubor na localhost do daného umístění na disku. Pokud by někdo měl tu možnost dát to někam na web, jsem i ochotný tam dodělat nějaký jednoduchý formulář, a např. po stažení všech souborů to zazipovat a nabídnout uživateli ke stažení přes prohlížeč (a pak samozřejmě smazat, ať to neplní disk). O úpravách se každopádně dá mluvit. Kdyby funkci někdo ale přece jen potřeboval takto a využil ji (mně dost pomohla a ušetřila čas), tak tady je:

/**
   * Downloads video from IDNES page.
   *
   * @param array|string $pages Array with URL on requested pages | URL on requested page
   * @param string $destDir Destination directory, the place where the video will be saved.
   * @param type $namePattern Pattern of destination filename:
   *                          %S% - source filename
   *                          %C% - counter (according to the count of given pages is counter padded by zeros)
   *    example:
   *      'Piano school - Lesson no. %C%' => returns e.g. 'Piano school - Lesson no. 03'
   */
  function download_idnes_videos($pages = array(), $destDir = '', $namePattern = '%S%')
  {
    // check parameter
    if (!is_array($pages)) {
      $pages = (array)$pages;
    }

    // get services from pages
    array_walk($pages, function(&$page) {
      preg_match('/videoFLV.+data:\s*["\'](.+?)["\']/', @file_get_contents($page), $matches);
      $page = (($matches) ? $matches[1] : '');
    });

    // download videos
    $count = count($pages);
    $sprintf = (($count < 10) ? '%d' : (($count < 100) ? '%02d' : '%03d'));
    $echoSprintf = $sprintf . '. ';

    $i = 1;
    foreach ($pages as $service) {
      if ($service) {
        $xml = simplexml_load_file($service);

        foreach ($xml->items->item as $item) {
          if ($item->type == 'video') {
            $video = $item->linkvideo->server . $item->linkvideo->path . $item->linkvideo->file;

            $source = @fopen($video, 'r');
            if (!$source) {
              $server = (($item->linkvideo->server == 'http://stream7p.idnes.cz/') ? 'http://stream6p.idnes.cz/' : 'http://stream7p.idnes.cz/');
              $video = $server . $item->linkvideo->path . $item->linkvideo->file;

              $source = @fopen($video, 'r');
            }

            if ($source) {
              // check destination
              if (!is_dir($destDir)) {
                mkdir($destDir, 0777, TRUE);
              }

              // create destination file
              $dotPos = strrpos($item->linkvideo->file, '.');
              $filename = substr($item->linkvideo->file, 0, $dotPos);
              $ext = substr($item->linkvideo->file, $dotPos);

              $destname = str_replace(array('%S%', '%C%'), array($filename, sprintf($sprintf, $i)), $namePattern);
              $destfile = rtrim($destDir, '/') . '/' . $destname . $ext;

              $dest = fopen($destfile, 'w');

              if ($dest) {
                echo sprintf($echoSprintf, $i) . 'copying... "' . $video . '" to "' . $destfile . '"<br />';

                stream_copy_to_stream($source, $dest);
              } else {
                echo sprintf($echoSprintf, $i) . 'destination is not writable.<br />';
              }
            } else {
              echo sprintf($echoSprintf, $i) . 'source was not found.<br />';
            }

            $i++;

            // jump to next page
            break;
          }
        }
      } else {
        echo sprintf($echoSprintf, $i) . 'service was not found.<br />';
        $i++;
      }
    }
  }

  // example
  /*
    $pages = array(
      'http://hobby.idnes.cz/video-na-klavesy-se-naucite-za-par-tydnu-zacnete-s-nami-od-prvni-lekce-1jg-/hobby-domov.aspx?c=A100514_153649_hobby-domov_bma',
      'http://hobby.idnes.cz/video-na-klavir-za-nekolik-tydnu-2-dil-dsk-/hobby-domov.aspx?c=A100522_083145_hobby-domov_bma',
      'chybna url'
    );
    download_idnes_videos($pages, 'test', 'Piano school - Lesson no. %C% (%S%)');
  */
#2
Software / Re: Nefunkční stahování z Idnes.cz
August 20, 2013, 09:59:54 AM
Ahoj, mám stejný problém. Chtěl bych si stáhnout celý seriál těchto videí "Na klavír za několik týdnů", ale YTD píše tutéž chybu, co říkal @151kbar151. Mohl bych tě také přes tvůj formulář požádat o postup? Mockrát děkuji.