Browse Source

Adding Channelate

Fixes #3
master
Alan Hardman 11 months ago
parent
commit
bd98a591eb
1 changed files with 54 additions and 0 deletions
  1. +54
    -0
      channelate.php

+ 54
- 0
channelate.php View File

@@ -0,0 +1,54 @@
<?php
// Channelate
// A fairly simple WordPress site

// Start by navigating to the latest comic
$html = file_get_contents('https://www.channelate.com/');
preg_match('@img src="https://www.channelate.com/wp-content/uploads/(.+\\.png)@', $html, $matches);

if (empty($matches[1])) {
echo "No comic found on home page! :(\n";
return;
}

if (!is_dir('channelate')) {
mkdir('channelate');
}

// Download current page's comic, load previous comic webpage, repeat
while (true) {
$filename = basename($matches[1]);
if (is_file('channelate/' . $filename)) {
return;
}

echo "Downloading {$filename}\n";
$url = "https://www.channelate.com/wp-content/uploads/{$matches[1]}";
$data = @file_get_contents($url);
if ($data) {
file_put_contents("channelate/{$filename}", $data);
}

// Find previous page link
$regex = '@href="(https://www.channelate.com/comic/[0-9a-zA-Z/-]+)" class="navi comic-nav-previous navi-prev"@';
preg_match($regex, $html, $prevMatch);

if (empty($prevMatch[1])) {
echo "No previous URL found!\n";
return;
}

$html = @file_get_contents($prevMatch[1]);
if (!$html) {
echo "Failed to load previous page!\n";
return;
}

preg_match('@img src="https://www.channelate.com/wp-content/uploads/(.+\\.png)@', $html, $matches);
if (empty($matches[1])) {
echo "No image found on page!\n";
return;
}

usleep(5e5);
}

Loading…
Cancel
Save