Thanks for translating, Alex!
Here's a quick'n'dirty script I've written several months ago. Still seems to work perfectly:
Code:
$ cat tsr-scan
#!/usr/bin/php
<?php
error_reporting(E_ALL);
$subscriptions = array (
'55', // temps present
'97', // services religieux
'90' // nouvo
);
$fp = fopen('tsrdl.sh', 'w');
fwrite($fp, '#!/bin/sh' . PHP_EOL);
$path = '/mnt/usb/Series';
foreach ($subscriptions as $id) {
$url = "http://search2.tsr.ch/solr/select?q=xobix_program_id:$id;broadcast_date%20desc,%20xobix_broadcast_position%20asc&wt=xml";
$contents = file_get_contents($url);
preg_match('/<str name="source_name">(.*)<\/str>/Umis', $contents, $matches);
if (!$matches[1]) {
echo $id . ' is invalid!';
continue;
}
$title = $matches[1];
fwrite($fp, PHP_EOL);
fwrite($fp, '# ' . $title . PHP_EOL);
fwrite($fp, '# -----------------------------------' . PHP_EOL);
preg_match_all('/<str name="subtitle">(.*)<\/str>/Umis', $contents, $matches2);
preg_match_all('/<arr name="media_file_info">(.*)<\/arr>/Umis', $contents, $matches3);
foreach ($matches2[1] as $key => $subtitle) {
$urls = $matches3[1][$key];
preg_match_all('/<str>(.*)<\/str>/Umis', $urls, $matchesUrls);
for ($i = count($matchesUrls[1]) - 1; $i >= 0; $i--) {
preg_match('/"url" : \'(.*)\'/', $matchesUrls[1][$i], $match);
$url = $match[1];
if (stripos($url, 'real.xobix.ch') !== false) {
continue;
}
fwrite($fp, PHP_EOL);
fwrite($fp, '# ' . $subtitle . PHP_EOL);
$fullpath = $path . '/' . $title . '/' . $subtitle;
$filepath = $fullpath . '/'. substr(basename($url), 0, strrpos(basename($url), '?'));
$comment = '';
if ((stripos($subtitle, 'Version courte') !== false) || file_exists($fullpath)) {
$comment = '# ';
}
fwrite($fp, $comment . 'mkdir -p ' . escapeshellarg($fullpath) . PHP_EOL);
fwrite($fp, $comment . 'wget ' . escapeshellarg($url) . ' -O ' . escapeshellarg($filepath) . ' || exit 1' . PHP_EOL);
break;
}
}
fwrite($fp, PHP_EOL);
sleep(1);
}
shell_exec('chmod +x tsrdl.sh');
Then use ./tsrdl.sh for downloading.
Edit: Oh yeah, and it's Linux-only but porting to Windows should be quite easy since wget is available there too. Only the last command should be changed coz Windows has no executable flag in their file system, as far as I know.