User talk:Currentlybiscuit/ScrapCCAnimScript
I finally got the script to work (my fault, I'm working out of very old memory here.. long time i didn't do this stuff..) But I'm back to the same problem I had with firefox some plugins ... I'm getting files alright, but they're named %E4%B8%8D-bw.png %E6%98%AF-bw.png %E7%9A%84-bw.png instead of 豕-order.gif or 豕-red.png or 豕-bw.png which beats the whole purpose of automating the download if I can't get the images names to match the character's names. I checked, and seems my terminal is able to display Chinese characters. Any idea what I'm doing wrong?
- ok, not doing anything wrong, it's just the way the script was written. Script was saving files with their original filename e.g %E6%88%91-order.gif which is not very useful for me. I'd rather they're saved as 我-order.gif same as downloading manually using a browser. My scripting knowledge is really sketchy now, and I've never really worked with PHP, but here's what I did to make it work for me. Replace line 101 with the following
$alt = $img->getAttribute("alt");
if ($type == "bw") $filename = substr($alt, 1) . "-bw" . ".png";
For some reason, the alt attribute was returning 我? instead of 我-order.gif hence the need for separate if statements.
if ($type == "red") $filename = substr($alt, 1) . "-red" . ".png";
if ($type == "order") $filename = substr($alt, 1) . "-order" . ".gif";
Working version downloading human-readable files[edit]
I downloaded the script on the main page, but it didn't work for me. Here is what I did:
- I installed the curl-php package on my ubuntu machine
- I made following changes to the script:
- There are some leading "//" in front of the original url, which have to be removed.
- I inserted "urldecode" twice to obtain 的 as filename instead of %E7%9A%84
- I use curl instead of file_get_contents. To do this, I inserted a new function get_data, which I found on http://www.galuba.net/programmierung/php/file_get_contents-oder-curl.html (german)
Here's the output of diff new.php old.php:
100d99 < $src = str_replace("//", "", $src); 102c101 < $filename = urldecode(basename($src)); --- > $filename = basename($src); 104,105c103,104 < echo "Downloading " . urldecode($src) . "\n"; < $pngData = get_data($src); --- > echo "Downloading " . $src . "\n"; > $pngData = file_get_contents($src); 124,135d122 < function get_data($url) < { < $ch = curl_init(); < $timeout = 5; < curl_setopt($ch,CURLOPT_URL,$url); < curl_setopt($ch,CURLOPT_RETURNTRANSFER,1); < curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,$timeout); < $data = curl_exec($ch); < curl_close($ch); < return $data; < } <