Monday 15 October 2012

A comic download life

download conan all episodes in once

#author: <>
import os
import re
import subprocess
from BeautifulSoup import BeautifulSoup
last_failed_episode_index = 4 #change it to failed index if last time failed
url = ""
host = ""
def download(folder_name, picture_url):
    file_destination = "/".join([folder_name, picture_url.split("/")[-1]])
    command = "curl -vk -w '%{http_code}' -e '"+picture_url+"' -A 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv: Gecko/20070725 Firefox/' '"+picture_url+"' -o '"+file_destination+"'" #don't follow redirect !!!
    print command
    proc = subprocess.Popen(command, shell=True, bufsize=2048, stdout=subprocess.PIPE, close_fds=True)
    http_code =
        proc.communicate() #wait for complete
    except Exception, e:
        print "proc exception ", e #[Errno 10] No child processe
    if http_code == "302":
        print "302, retrying... :)"
        download(folder_name, picture_url)
def request_url(url):
    command = "curl -vLk -e '"+url+"' -A 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv: Gecko/20070725 Firefox/' '"+url+"'"
    print command
    proc = subprocess.Popen(command, shell=True, bufsize=2048, stdout=subprocess.PIPE, close_fds=True)
    r = proc.stdout
    return r
r = request_url(url)
soup = BeautifulSoup(r)
episode_list = soup.html.findAll('ul')[-1]
full_episode_list = []
for episode in episode_list:
    full_episode_list.append([episode.find("a").get("title"), "".join([host, episode.find("a").get("href")])])
print "full_episode_list is ", full_episode_list
for index, episode in enumerate(full_episode_list):
        if index >= last_failed_episode_index:
            title = episode[0]
            folder_name = title.replace("/", "[]").replace("'", "\"")
            if len(folder_name) > 255:
                print "len(folder_name) > 255"
                folder_name = folder_name[:255]
            if not os.path.exists(folder_name):
            r = request_url(episode[1]).read()
            regex = re.compile(";pic\[.*?\][ \n]=[ \n]'(.*?)'", re.DOTALL | re.UNICODE | re.IGNORECASE)
            print r
            hex_code_list = regex.findall(r)
            print "hex_code_list is ", hex_code_list
            server_list_url = host + "/common/server.js".join([r.split("/common/server.js")[0].split("\"")[-1], r.split("/common/server.js")[1].split("\"")[0]])
            r = request_url(server_list_url).read()
            server_url = r.split("url:'")[1].split("'")[0]
            print "server_url is ", server_url
            picture_list = []
            for hex_code in hex_code_list:
                picture_list.append("".join([server_url, hex_code.decode("hex")]))
            print "picture_list is ", picture_list
            for picture_url in picture_list:
                download(folder_name, picture_url)
    except Exception, e:
        print "failed to download episode ", index
        print "because of ", e

Monday 13 August 2012

A routine linux life 2

Recently I force to cleanup all windows 7 and reinstall bt5, so, this time I try kde 32bits. Let's take a look,
pacman game, sometime confuse with pcmanfm file manager.

quite boring? so let's try another window manager, called fluxbox. Many way can start the fluxbox, for example, type kdm or gdm, then choose the fluxbox.

quite nice, and I love mostly many style available.
Double-click the title bar wouldn't max/min, instead of hide the main screen. And I found terminal called urxvt, I like the name. urxvt can config inside ~/.Xdefaults

I also change my fedora desktop, so

what the hell of those Jack-o'-lantern? Ya, I have to call idesk utility for desktop icon, just create ~/.idesktop directory and put icon .lnk file, example gkrellm.lnk:
table Icon
  Caption: gkrellm
  Icon: /root/Desktop/_start:/icon/Jack-O-Lantern.png
  X: 1000
  Y: 950
  Command[0]: gkrellm
  Command[1]: gkrellm ~/.idesktop/gkrellm.lnk

To make the auto startup apss and locate position permanently, edit the  ~/.xinitrc file, my example here:
dbus-launch usr/libexec/gnome-settings-daemon &
sleep 2
gnome-panel &
sleep 2
gnome-volume-control-applet &
idesk &
gkrellm &
pidgin &
nautilus --no-desktop --browser /root/Desktop/t/tx/youtube/sounds  --geometry=500x500+0+500 &
gnome-terminal --geometry=200x22+500+30 &
gnome-terminal --geometry=200x22+500+430 &
exec /usr/bin/startfluxbox

Ya, I also able to open gnome-panel on the same time, juz hide the bottom bar enough. I also trigger gnome-settings-daemon because I want the scrollbar/directory color appearance remain the same, green theme, GNOME-Colors-Wise. sleep required of course. 
No purpose for gkrellm, currently too empty, juz simply put it.
Just saying, gnome-terminal always have a bug, the copy-paste shortcut problem. Simply go to keyboards shortcuts settings, even though "Shift-Ctrl-C and Shift-Ctrl-V" is here already, but you still required to click a few time(new accelerator...)  again. 

time for ktm.

Saturday 14 July 2012

Manually download baidu song on API way

Manually download baidu song on API way:
1. Open 
, "titles=" change to song title, %24%24 also means $$, the next is singer name.
, if it doesn't work, r= should change to any random number, jsonplink's 1342282653123  can change to current javascript UNIX timestamp. The javascript UNIX timestamp can get via alert(new Date().getTime()). Or as a bash way, command "date +%s" and append any 3 digits. Or as a python geek, using "{0:.0f}".format(time.time()*1000)

2: then we would got something like "

jsonplink1342282653123({"errorCode":"0","data":{"songList":[[{"songID":"0","songName":"poker face",
"artistName":"lady gaga","albumID":"0","albumName":"","lrcLink":"http:\/\/\
{"songID":"0","songName":"poker face","artistName":"lady gaga","albumID":"0","albumName":"","lrcLink":
{"songID":"0","songName":"poker face","artistName":"lady gaga","albumID":"0","albumName":"","lrcLink":
"songName":"poker face","artistName":"lady gaga","albumID":"0","albumName":"","lrcLink":
"598626"},{"songID":"0","songName":"poker face","artistName":"lady gaga","albumID":"0","albumName":"",

, extract the .mp3, .wma,..whatever make sense song extension. example
, remove the back slash "\"
, become

3. Try to download it, if no response or server error, extract "xcode=" value on the end of content we got just now,
Try download it again. Above url and xcode is example only. Normally the xcode would expired.
Chinese song example,
or just在动物园散步才是正经事%24%24my+little+airport&callback=jsonplink1335160684820&r=0.020559488740344856
Unknown singer example, portal song,$$&callback=jsonplink1335160684820&r=0.020559488740344856
First blog to mention it:)

A routine linux life

Sometime application is hang, and you may not enough expertise to analysis under the hood. Although you can command "ps aux", get the pid/name and kill -9 the pid or killall -9 the name, but there's another convenient way to kill certain window locate/click by mouse. That's "xkill" utility. Left-click can kill the window, right-click can cancel it.

I prefer add the command to panel, I didn't want to open terminal and type "xkill" when desktop already on the hang state :) [UPDATE] I use shortcut key <Super+X> nowadays.

So, right-click panel, "Add to Panel..." and Choose "Custom Application Launcher", then insert "xkill" inside both Name and Command text field. Edit the icon, just open "~/.gnome2/panel2.d/default/launchers/xkill.desktop", edit the "Icon[en_US]=IMAGE_LOCATION" part. Default image is "gnome-panel-launcher".