Improve the world

Improve free software, share knowledge…

Ripper l’audio d’une vidéo avec ffmpeg

Publié par geenux le 19 décembre 2011

Bonjour,
Vu que j’ai eu un peu de mal à trouver comment ripper la bande son d’une vidéo (en l’occurence de youtube), j’ai fait un petit script pour le faire simplement :
#!/bin/bash

### libmp3lame required : to install
#sudo apt-get install ffmpeg libavcodec-extra-52

for i in "$*"; do
#mplayer -ao pcm "$i" -ao pcm:file="$(echo "$i"|cut -d'.' -f1).mp3"
# -vn remove the video
ffmpeg -i "$i" -vn -acodec libmp3lame "$(echo "$i"|cut -d'.' -f1).mp3"
done

Très simple à utiliser, faites juste
ripaudio.sh fichier1.flv fichier2.mpeg ...
Et vous obtiendrez des fichiers au format mp3 fichier1.mp3, fichier2.mp3, …

Publié dans Ubuntu | Tagué: , , | Laisser un Commentaire »

Bonnes musiques à jouer à la guitare électrique

Publié par geenux le 14 août 2011

Hello,

Bon, j’ai toujours du mal à trouver des chansons de rock pas trop dures, et intéressantes à jouer seul, ou en groupe. Beaucoup de chansons rock sonnent pauvres quand on enlève les autres instruments, normal, mais c’est toujours moins agréable de jouer un truc qui sonne “pas fini”. Jouer en même temps que la musique est une bonne méthode pour enlever se sentiment, mais on ne peut pas toujours avoir le support musical, ou une bande pour jouer avec nous. Donc voici quelques chansons pas trop dures, et qui sonnent bien en elles-mêmes, comme avec une bande.

Muse – Hysteria

La partie de basse est très intéressante, et peut être jouer sans problème à la guitare si vous n’avez pas de bassiste avec vous. Le riff principal, avec les octaves et le bend est sympa à jouer, et rend super bien. Le solo est un peu plus dur, mais rien d’insurmontable avec un peu de travail.

Bonne chanson pour bosser l’alternate picking :)

The Eagles – Hotel California

Belle intro, magnifique solo. Beaucoup de bend, quelques accords barrés pour l’intro

Publié dans Guitare | Tagué: , | 1 commentaire »

Smith Westerns – Weekends tab

Publié par geenux le 14 août 2011

Bonjour,
J’aime bien l’intro de la chansons Weekends de Smith Westerns (provenant de leur nouvel album Dye It Blonde).

J’ai pas trouvé de tablatures sur Internet, du coup je l’ai faite moi même.
J’ai aussi quelques autres bouts de la chansons…
Je suis bien nul pour trouver les accords, si quelqu’un a les bons accords, merci de corriger ce qui sera probablement faux dans les commentaires.

Smith Westerns - Weekends from their album "Dye it Blonde"

Tabbed by geenux
This is my first tab, thus it is bond to have some mistakes in it.
For the chorus, I couldn’t figure out the rythm guitar chords, so I tabbed the lead guitar part instead. Anyway, it is a much more interesting part to play when you’re not in a band…
When the chords are played by the lead guitar, I put them inside brackets [Am7] …
If you find any mistakes, or have anything to add, please let me know, I’d be glad to have the full version

Live: http://www.youtube.com/watch?v=d-QLYxG1Pvw&feature=related
Chords
Eadube
A : 577655
A7 : 576655
Am : 576655
Dm/F : xx3231
[A] : x02220
[Am7]: x02010
[Em7]: 022033

Intro
e ———————————————————–
b ———————————————————–
g ———-9-11b—(13)–(13)-(13)r 11-9——————–
d –7–9/11——————————–11~—————
a ———————————————————–
e ———————————————————–

e —————————————————————————————–
b —————————————–12b–(14)r 12-10—-10-12b–(14)r 12—-10–12b-
g ———-9-11b (13)–(13)-(13)r-12-9——————-11——————11———
d –7–9/11——————————————————————————–
a —————————————————————————————–
E —————————————————————————————–

e —————————-
b -(14)r 12-10———10—–
g ————-11\9/11——–
d —————————-
a —————————-
E —————————-

Bridge (lead guitar)
Bm Dm
–2—-5—————–
–3—-6—————–
–4—-7—6–4———-
–4—-7———2—7— Then play the intro (and the verses chords are played over it)
–2—-5—————–
–2—-5—————–

Riff1 [lead guitar]
e —————————————————
b —————————————————
g —-15-15-15-15-14-14-14-14-12-12-12-12-10-10-10-10
d —————————————————
a —————————————————
E —————————————————
too… Who ou

Riff2 [lead guitar] (F#m and Am7 are strummed once, strum the A and Em7)
F#m Am7 A Em7
e -2———————–0————————0——3—-
b -2———————–1————————2——3—-
g -3———————–0————————2——0—–
d -4———————–2————————2——2—–
a -4———————–0————————0——2—-
E -2——————————————————-0—-
Weekends are never fun unless you’re around here too oou ou

Riff3 [lead guitar]
e —————————————————
b —————————————————
g —-15-15-15-15-14-14-14-14-12-12-12-12-10-10-10-10
d —————————————————
a —————————————————
E —————————————————
too… Who ou

e ——————————————————–0——
b ——————————————————–2——
g ——-2h4/6\4——-2-2-2/4-4-6—4-6-4~——2-2-4—-2——
d –2h4———–2h4————————2h4———-2——
a ——————————————————–0——
E —————————————————————

A A7 Am
Her tears are never ending
F#m
You run away but stop pretending
D Dm/F
Na na na na na, a girl like you
A A7
What do you think? Is it normal?
A F#m
To go through life oh so formal?
D Dm/F
Na na na na na, a girl like you

CHORUS:
[Dsus4]
Weekends are never fun
[Am7] [Em7]
Unless you’re around here too [Riff1]
[F#m] (riff2)
Weekends are never fun
[Am7] [Am7] [Em7]
Unless you’re around here too ou ou ou
[Riff3]

Bridge

A A7
Head-on stars aligned
Am F#m
All the dreams are on my side
D Dm/F
Na na na na na, a girl like you
A A7
Took her fall, so i felt down
A F#m
Never wanna see anything
D Dm/F
Na na na na na, a girl like you

CHORUS:
[Dsus4]
Weekends are never fun
[Am7] [Em7]
Unless you’re around here too [Riff1]
[F#m] (riff2)
Weekends are never fun
[Am7] [Am7] [Em7] [Riff3]
Unless you’re around here too ou ou ou
[Am7] [Em7] [Riff3]
too ou ou ou
[Am7] [Em7] [Riff3]
too ou ou ou

Notation:
b: bend up
r: bend down
(13) : note to bend to, or from [ for instance (13)r11 : bend down from 13 to 11 ]
/ : slide up
\ : slide down
~ : vibrato

Publié dans Guitare | Laisser un Commentaire »

Créer une image iso d’un CD simplement

Publié par geenux le 13 août 2011

Hello world,
Bon, alors ça vous intéresse de créer une image CD sans vous tracasser, avec une simple petite commande ?
Tout d’abord un petit peu de culture générale pour comprendre ce qu’on fait.
Les données contenues sur un CD sont contenues dans un système de fichier iso9660.
Une image ISO n’est qu’une simple copie du système de fichier complet dans un fichier.

Vu comme ça, la solution pour créer une image apparait naturellement, et oui, il suffit de copier bit par bit le CD dans un fichier…
Et là magie, on a une commande qui fait exactement ça :

dd if=/dev/cdrom of=cd.iso

Si vous désirez tester le résultat, sans avoir à graver de CD, il suffit de faire

sudo mkdir /mnt/iso
sudo mount -t iso9660 -o loop cd.iso /mnt/iso
ls /mnt/iso

Magique, n’est-ce pas !

Publié dans Vrac | Tagué: , , , | Laisser un Commentaire »

Astuces pour gnome3

Publié par geenux le 7 août 2011

Ça faisait longtemps que j’avais pas posté quelque chose ici…
Je suis en plein test de gnome3, et je dois dire que ça me plait pas mal.
Mais il y a quelques défaut que je n’apprécie pas, à chaque fois que je trouverai une solution, je la posterai dans cet article.

Marre de ne plus avoir de bouton pour réduire la fenêtre ? Il est possible de les remettre simplement en faisant :
gconftool-2 -s -t string /desktop/gnome/shell/windows/button_layout “:minimize,maximize,close”
gconftool-2 -s -t string /desktop/gnome/shell/windows/button_layout “menu:minimize,maximize,close”

Pour restaurer le comportement par défaut:
gconftool-2 -s -t string /desktop/gnome/shell/windows/button_layout “:close”
gconftool-2 -s -t string /desktop/gnome/shell/windows/button_layout “menu:close”

Publié dans Non classé | Tagué: | Laisser un Commentaire »

Plugins sympa pour emacs

Publié par geenux le 3 mai 2011

Je viens de me mettre à re-tester emacs. Je suis un utilisateur de vim, que j’aime énormément. Mais en grand curieux incertain que je suis, j’essaye de trouver ce que tant de monde semble trouver si bien avec emacs, notemment pour la programmation.
Je mettrais mes petites découvertes ici, surtout à titre de mémoire pour moi, mais comme ça peut servir à d’autres, je le publie.

yasnippet
Comme son nom l’indique, il s’agit d’un système de templates, qui permet d’avoir des structures pré-remplie. C’est assez efficace.

ido
Il s’agit d’un remplacement au très bon switch-buffer. Cette extension permet de changer aisément de buffer, et de trouver facilement vos fichier, juste en tapant quelques lettres du nom de fichier ! Très pratique :)

Publié dans Logiciels libres | Tagué: | 1 commentaire »

Create frames for Fotowall

Publié par geenux le 27 octobre 2010

This article is a translation of Benoît Bâlon’s article (fr) concerning the frame creation for Fotowall. I’m translating this article to increase the reach of his work, and meet the ever growing reclamations for more frames.

The few frames proposed as default in Fotowall aren’t always enough to fill up the user’s creativity. Luckily, this software uses only standards, namely SVG for the frames realisation. Thus, it is rather simple to create new frames, though… two little constraints must be respected ;-) :

  • Drawing an SVG image require the use of a SVG manipulation software, which is not that complicated, but can certainly repel more than one.
  • Following a certain amount of indications, once again concerning the SVG, for a perfect display in Fotowall… And there, I lost half my readers (which must represent an arm or a foot)…

Before I suggest a solution to avoid these to constraints, and thus make the integration of a “simple drawing” as a frame in Fotowall easier, we will see how these famous frames works.

As said before, the frames are based on SVG drawings. In order to be used in Fotowall, these are cut in 9 pieces, indentified by a label inside the SVG file. The following illustration represents these 9 pieces, the pink area correspond to the position of a canvas’ photo.

The different parts of the SVG frame

The labels displayed on each piece, such as “topleft” or “bottom”, correspond to the different ID on which Fotowall depends on. Without these ID, Fotowall won’t be able to use the frame, and the outline of the photo, be it of your nephew or of Médor, will desperately remains empty. To these 9 pieces, adds up 4 other elements, represented by arrows above. Although they appear while the vectorial drawing is edited, they are invisible inside Fotowall, but are nonetheless necessary. These, identified by the IDs “hint-[...]-margin”, are used to define the width of the visible outline. Thus, if we take the example of the left arrow, here is its impact on the left image:

  • If the object “hint-left-margin” is as long as the image “left”, then this image appears in its whole width
  • If the object “hint-left-margin” is longer than the image “left”, then a space appears between this image and the border of the photo. This space is automatically filled with the background image “center”, which exceed the photo’s from on the left side.
  • If the object “hint-left-margin” is less long than the image “left”, then the latter is partially covered with the photo.

Mathematically, the distance between the space zone and the covered zone, is the difference of length between the element “hint-[...]-margin” and each of the concerned images (the 3 on the left, right, top, bottom): if the frame is 5 pixels and the margin is 10 pixels, there will be a gap of 5 pixels between the frame and the photo.

A little detail that is worth mentioning, the images “top”, “left”, “bottom” and “right” will be automatically stretched according to the photo’s size. From here, we realise that unfortunately it’s hard to come up with a frame composed of pattern supporting to be bent… The following example illustrate rather well this problem. Never mind that ! It’s already possible to do enough to have fun, and these few limitations will probably be lifted with time.

The borders being stretched, the patterns are bent

We saw that a frame is composed of 9 + 4 graphical elements in an SVG file. To avoid entering the IDs of these elements manually inside a SVG file (which is a mere XML structured file), in Inkscape it is possible to enter these after a right click on each of these elements, as illustrated below.

Editing in Inkscape

With the information we just studied, we can see that creating a frame can me done without to much difficulty, but is nonetheless a tedious work, which can really become a bother when you try to use more colour schemes for a single frame. And, of course, not everyone is confortable with vectorial drawing!
In this case, why not created a bitmap (JPG, PNG…) frame with an image software such as Gimp, and then convert it in an SVG frame ready to use in Fotowall?

As we briefly said before, an SVG file is a mere XML file. Luckily enough, there are plenty of linux command line tools, and Bash (or any other *sh, not to be -too- sectarian) is the star when it come to create files automatically!

The temptation to create such a program was way too high. Thus, here come a script which will allow us to free ourselves from the cutting and SVG conversion : fotowall_frame_compiler.zip

Once uncompressed, the use of this script, though requiring the use of a dark and strange screen, the one we call “Terminal”, is really simple to use. Just look:

./fotwall_frame_compiler.sh image.png

This script can work with a unique parameter, namely the image to convert. In this case, the 9 frame’s pieces will be as often as possible of equal height and width. For a better rendering, try to prefer dimensions which are multiple of 3 from the begining. In output, the SVG file is created, using the name of the original picture and replacing the extension with “.svg” (which gives in our example image.png > image.svg).

But we can as well have a frame’s outline as high or wide (or both) different from the one reserved to the photo position. Taking back the example of the first illustration, we clearly see that the height of “top” and “bottom” is not the same as the height of “center”. In this case, it will be necessary to know the exact size we want to give to “center” once transformed into SVG. In Gimp, it is for instance possible to measure this sone with the rectangular selection tool. Once the height and width are known, we just have to add these two parameters to the script:

./fotowall_frame_compiler.sh image.png 150 130

The first number represents the width in pixels, the second represents the height. Considering that the “center” area is perfectly centred, the script is capable of calculating the width and height of each one of the 9 parts, and to place them within the SVG file. In short, there is nothing left to do, the frame is immediately usable within Fotowall! If the rendering is not perfect (a gap of 1 or 2 pixels is always possible), you just have to play directly on the two values of the command line, and reload the frame in Fotowall.

To illustrate all of this, here comes a more concrete example:

However, this script requires one or two programs, which are available within the repository of every good GNU/Linux distribution:

  • base64: it should be installed by default, this software can store each of the 9 images directly inside the SVG file.
  • ImageMagick : the convert and identify commands are overused in this script. A version 6.5.8-9 at least is required for the automatic splitting in 9 images.
  • Inkscape is not really required anymore, but it would be too bad not to use it… :mrgreen:

Warning: this script created temporarily 9 PNG images in the directory. These 9 elements are then stored within the SVG file, after being split and numbered as follow by ImageMagick (using the example above) : image_0.png, image_1.png, … , image_8.png. Please mind not having an important picture named the same, otherwise it will be overwritten. [If someone is motivated to create a proper warning and management of these kind of problems, feel free to do so, it would be greatly appreciated].

After seeing how the frames works, a script allows us to free ourselves from a certain amount of boring steps (labelling, splitting…), and thus we can concentrate on the pure graphical realisation of the image. Save the images in PNG, as it is the only format to benefit from both colour and transparency.

By way of conclusion, we can summarise the main parts adressed here concerning the Fotowall’s frames:

  • They are in SVG format, and can be drawn using one of the vectorial manipulation programs, such as Inkscape.
  • A frame is composed of 9 elements : the 4 corners, the 4 borders, and the center. To these 9 elements, adds up 4 others for the distance between the border of the frame and the border of the photo.
  • Each of the elements is given a precise ID within the SVG file.
  • The borders being stretched, the patterns are bent, which for now put a small limitation on your creativity.
  • It is possible to avoid all the SVG part, and created a frame from bitmaps (once again, favour the PNG format) using the script fotowall_frame_compiler (needs GNU/Linux and a recent version of ImageMagik).
  • A huge thanks to Benoît Bâlon for this article, I hope that my approximative translation didn’t rip too much of the original essence of the article.

Publié dans Fotowall | Tagué: , | 2 Commentaires »

Script de téléchargement pour ourmanga.com

Publié par geenux le 4 septembre 2010

Ourmanga.com ne propose plus la lecture des mangas. Ce script est donc obsolète et ne fonctionnera pas!

J’ai réalisé un petit script python pour télécharger les mangas depuis le site ourmanga.com.
Ce script fonctionne pour tous les mangas que j’ai testé, je suppose qu’il fonctionne pour le reste.
Le code est un peu crade, gestion des exceptions pas très rigoureuse (si il y a une erreur durant le téléchargement, pas de souci, vous serez prévenu), appel de fonctions qui pourraient être évités…
Si je suis pas trop flemmard, je modifierai ça plus tard.

Il n’est probablement pas légal d’utiliser ce script sans être en possession des mangas originaux, pensez à les acheter !

Le script est sous licence GNU GPL, vous êtes libres de le modifier, l’utiliser comme bon vous semble. Si vous l’améliorez, j’apprécierai d’avoir le nouveau script.

Utilisation
Tout d’abord, il faut modifier quelques paramètres dans le script pour l’adapter à vos besoin.
La variable DL_DIR contient le répertoire dans lequel vous souhaitez stocker les mangas, adaptez la à vos besoin.

Pour utiliser le script, il suffit de faire

ourmanga.py "one piece" 199

Cette commande télécharge le chapitre 199 de One Piece.
ourmanga.py "fairy tail" 1-112

Cette commande télécharge les chapitres de 1 à 112 de Fairy Tail
Vous pouvez aussi utiliser
ourmanga.py <manga> --list  #liste des chapitres d'un manga
ourmanga.py --manga-list  #liste des mangas

Le script

#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""A small script that downloads mangas from MangaStream
    Licenced under the GPL >=v2 Licence
    Copyright TANGUY Arnaud <arn.tanguy@gmail.com>"""

import os
import sys
import re
import time
import urllib
from BeautifulSoup import BeautifulSoup

# ================= CONFIGURATION =======================
MAXTRIES = 5
OM = "http://ourmanga.com"

### Put the right download path for your system here
DL_DIR = "/media/data/Images/Mangas"
###

OM_DL = "http://ourmanga.com/manga"
TMP_DOWN = "/tmp/ourmanga"
# Ourmanga seems to have some problems to give you the files if you request them too often.
# This sleep value is used only in case of a download fail, it'a a delay before retrying the download.
# If you put this value to 0, you might have trouble downloading a full chapter, maybe you'll manage to get the 10 first images...
# I think you understood, don't put this one to 0 !
SLEEP_TIME=2 # Delay in seconds


def helper():
    """Gives help about the use of this script"""
    print """Usage:
        - python """+sys.argv[0]+""" manga chapter\t chapter can be a single number like 23 or a range like 23-45
        - python """+sys.argv[0]+""" manga --list\t show all the chapters available
        - python """+sys.argv[0]+""" manga --manga-list\t show all the mangas available
        """
    exit(0)


def retrieve_url(url, save_location):
    "Download URL using wget"
    downloaded=False
    tries=0
    while tries < 5 and downloaded == False:
        print "Retrieving file "+url
        status = os.system("wget "+url+" -O "+save_location.replace(' ','\ ')+" 2>/dev/null")
        if status == 256:
            tries += 1
        else:
            downloaded=True
            return save_location
        if tries < MAXTRIES:
            print "\033[31;1mThe url "+url+" is unreachable... Retrying\033[0m"
        else:
            print "\033[31;1mMax number of tries exeeded, download failed!\033[0m"
            exit(1)
        time.sleep(SLEEP_TIME)

def manga_name(manga):
    namelist = manga.split(" ")
    manga_n = []
    for word in namelist:
       manga_n.append(word.capitalize())
    manga = "_".join(manga_n)
    return manga.replace('/','-').replace('.','')

def make_pretty(name):
    """Returns the chain given, in order to have a normal name"""
    return str(name).capitalize().replace("/", "").replace("_", " ")

def make_n_digits(number, digits):
    """ Returns a n digit number (adds 0 to the begining if not 3 digits) """
    numstr = str(number)
    if len(numstr) >= digits:
        return str(number)
    else:
        toadd = digits-len(numstr)
        i=0
        while i<toadd:
            numstr = "0"+numstr
            i+=1
    return numstr

def chapter_number(manga, chapter):
    manga_n = manga_name(manga)

    retrieve_url(OM+"/"+manga_n, TMP_DOWN)
    f = urllib.urlopen(TMP_DOWN)
    page = f.read()
    f.close()
    page = re.findall('<a href="http://www.ourmanga.com/'+manga_n+'/.+>.+</a>', page);
    if len(page) <= 0:
        print "No chapters !"
        exit(1)
    for link in page:
        chp = re.findall('Chapter [0-9.]+',link)
        if len(chp) > 0:
            chap = chp[0].lstrip("Chapter ")
            if str(chap) == str(chapter):
                return chap
    print "\033[31;1mUnable to find the chapter real number, aborting download\033[0m"
    exit(1)

def chapter_url(manga, chapter):
    return OM+'/'+manga+'/'+str(chapter)

def read_chapter_url(manga, chapter):
    return OM+'/'+manga+'/'+str(chapter)+'/01'

#Image : http://www.ourmanga.com/manga/Fairy_Tail/Chapter-165/02.jpg
#PAge : http://www.ourmanga.com/Fairy_Tail/165/01
def image_url(manga, chapter, image):
    retrieve_url(OM+"/"+manga+"/"+chapter+"/"+image, TMP_DOWN)
    f = urllib.urlopen(TMP_DOWN)
    page = f.read()
    f.close()

#<div class="inner_full_view">\t<h3>     <a href="http://www.ourmanga.com/Soul_Eater/73/1301056_e"><img src="http://www.ourmanga.com/manga/Soul_Eater/Chapter-73/1301054_e.jpg"></a>
    page=re.findall('<div class="inner_full_view">.*<a href=".+"><img src="(.+)"></a>', page.replace('\n',''))
    print page
    if len(page) <= 0:
        print "Image not found, aborting download !"
    return page[0]

def find_manga_list():
    """ Find all the available mangas."""
    retrieve_url(OM+'/directory', TMP_DOWN)
    f = urllib.urlopen(TMP_DOWN)
    # Finds the location where the manga names are
    page = re.findall('<div class="m_s_title">.+</div>', f.read())
    f.close()
    if len(page) <= 0:
        print "No mangas !"
        exit(1)

    manga_list = []
    for linkTag in page:
        try:
            soup = BeautifulSoup(linkTag)
        except:
            continue
        result = soup.findAll('a');
        for tag in result:
            manga_list.append(tag.string)
    return manga_list


def find_chapter_list(read_chapter_url):
    """ Find all the available chapters."""
    retrieve_url(read_chapter_url, TMP_DOWN)
    f = urllib.urlopen(TMP_DOWN)
    page = f.read()
    f.close()
    # Finds the location where the image names are
    page = re.findall('<select name="chapter".+>.+</select>', page);
    if len(page) <= 0:
        print "No images !"
        exit(1)

    soup = BeautifulSoup(page[0])
    result = soup.findAll("option");
    chapter_list = []
    for tag in result:
        chapter_list.append(tag.string.lstrip("Chapter : "))
    return chapter_list

def find_image_list(chapter_url):
    """ Find the images names."""
    retrieve_url(chapter_url, TMP_DOWN)
    f = urllib.urlopen(TMP_DOWN)
    page = f.read()
    f.close()
    # Finds the location where the image names are
    page = re.findall('<select name="page".+>.+</select>', page);
    if len(page) <= 0:
        print "No images !"
        exit(1)

    soup = BeautifulSoup(page[0])
    result = soup.findAll("option");
    images_list = []
    for tag in result:
        images_list.append(tag.string)
    return images_list

def create_folder (path, chapter):
    "Create a folder if it isn't already existing"
    if not os.path.isdir(path):
        os.mkdir(path)
    path = path+'/'+str(chapter)
    if not os.path.isdir(path):
        os.mkdir(path)


def download_chapter(manga, chapter):
    #"Download a chapter"
    print "Downloading manga : "+make_pretty(manga)+" chapter "+str(chapter)

    path=DL_DIR +'/'+ make_pretty(manga)
    chapter = chapter_number(manga, chapter)
    chp_url = read_chapter_url(manga_name(manga), chapter)

    create_folder(path, chapter)
    find_chapter_list(chp_url)
    images_list = find_image_list(chp_url)
    print "Downloading images..."
    i=1
    for image in images_list:
        url = image_url(manga_name(manga), chapter, image)
        retrieve_url(url, path+"/"+str(chapter)+"/"+make_n_digits(i, 2)+os.path.splitext(url)[1])
        print "\033[32mImage "+url+" downloaded.\033[0m"
        i+=1
    print "\n\033[32mChapter downloaded.\033[0m"

if sys.argv[1] == "--manga-list":
    print "Manga list : "
    for i in find_manga_list():
        print i
    exit(0)
if len(sys.argv) == 3:
    if sys.argv[2] == "--list":
        print "Chapter list : "
        for i in find_chapter_list(read_chapter_url(manga_name(sys.argv[1]), 1)):
            print i
    else:
        chapters = sys.argv[2].split('-')
        if len(chapters) > 1:
            for i in range(int(chapters[0]), int(chapters[1])+1):
                download_chapter(sys.argv[1], str(i))
        else:
            download_chapter(sys.argv[1], chapters[0])
else :
    helper()

Publié dans Programmation | Tagué: , | Laisser un Commentaire »

Script pour mangastream

Publié par geenux le 11 août 2010

Je savais pas trop quoi programmer, et comme j’ai remarqué qu’ils avaient enlevé Bleach, One Piece… de onemanga.com, j’ai fait un petit script pour télécharger les mangas à partir du site mangastream.

#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""A small script that downloads mangas from MangaStream
    Licenced under the GPL >=v2 Licence
    Copyright TANGUY Arnaud <arn.tanguy@gmail.com>"""

import os
import sys
import urllib
from BeautifulSoup import BeautifulSoup

def helper():
    """Gives help about the use of this script"""
    print """Usage:
        - python """+sys.argv[0]+""" manga chapter
        """
    exit(0)

# Config
MAXTRIES = 5
MS = "http://www.mangastream.com"
DL_DIR = "/media/data/Images/Mangas"
TMP_DOWN = "/tmp/mangastream"
IMG_BASE_URL = "http://static3.mangastream.com/manga"

def retrieve_url(url, save_location):
    "Download URL using wget"
    downloaded=False
    tries=0
    while tries < 5 and downloaded == False:
        print "Retrieving file "+url
        status = os.system("wget "+url+" -O "+save_location.replace(' ','\ ')+" 2>/dev/null")
        if status == 256:
            tries += 1
            print "\033[31;1mFailed download, retrying…\033[0m"
        else:
            downloaded=True
            return save_location
        if tries < MAXTRIES:
            print "\033[31;1mThe url "+url+" is unreachable...\033[0m"
            exit(1)

def manga_name(manga):
    return manga.lower().replace(' ', '_').replace('.','_').replace('-', '_')

def make_pretty(name):
    """Returns the chain given, in order to have a normal name"""
    return str(name).capitalize().replace("/", "").replace("_", " ")

def find_chapter_url(manga, chapter):
    """Find the chapter url."""
    retrieve_url(MS+"/manga", TMP_DOWN)
    f = urllib.urlopen(TMP_DOWN)
    soup = BeautifulSoup(f.read())
    result=soup.findAll('td')
    mangaUrl=""
    for i in result:
        try:
            mangaUrl =  i.a['href']
        except:
            continue
        if manga in mangaUrl:
            if str(chapter) in i.a.string:
                print "\033[32mFound chapter url : "+mangaUrl+"\033[0m"
                return mangaUrl
    print "\033[31;1mError : manga or chapter not found\033[0m"
    exit(1)

def find_img_page_list(chapter_url):
    print "Retrieving page list..."
    url = retrieve_url(chapter_url, TMP_DOWN+"_img")
    f = urllib.urlopen(url)
    soup = BeautifulSoup(f.read())
    result=soup.findAll('select')[1]
    img_page_url=[]
    soup = BeautifulSoup(str(result))
    result = soup.findAll('option')
    for i in result:
        img_page_url.append(i['value'])
    return img_page_url

def find_img_urls(img_page_list):
    print "Retrieving images urls.."
    image_url_list = []
    for img_page in img_page_list:
        retrieve_url(MS+img_page, TMP_DOWN+"_img")
        f = urllib.urlopen(TMP_DOWN+"_img")
        soup = BeautifulSoup(f.read())
        result=soup.findAll('img')
        for i in result:
            if IMG_BASE_URL in i["src"]:
                print "\033[32mFound image url : " + i["src"]+"\033[0m"
                image_url_list.append(i["src"])
        f.close()
    return image_url_list

def create_folder (path, chapter):
    "Create a folder if it isn't already existing"
    if not os.path.isdir(path):
        os.mkdir(path)
    path = path+'/'+chapter
    if not os.path.isdir(path):
        os.mkdir(path)


def download_chapter(manga, chapter):
    "Download a chapter"
    print "Downloading manga : "+manga+" chapter "+chapter

# problem for this manga, here's a hack to make it work...
    if manga == "Hitory's Strongest Disciple Kenichi" :
        manga = "hsdk"

    manga_n = manga_name(manga)
    path=DL_DIR +'/'+ make_pretty(manga)
    create_folder(path, chapter)
    chapter_url = MS+find_chapter_url(manga_n, chapter)
    i=1
    imgUrls = find_img_urls(find_img_page_list(chapter_url))
    print "Downloading images..."
    for url in imgUrls:
        try:
            retrieve_url(url, path+"/"+chapter+"/"+make_pretty(manga)+"_"+str(i)+os.path.splitext(url)[1])
            i=i+1
        except (socket.error, IOError):
            print "\033[31;1mError downloading image "+url+"\033[0m"
    print "\n\033[32mChapter downloaded.\033[0m"
    exit(0)

for i in sys.argv:
    if len(sys.argv) == 3:
        download_chapter(sys.argv[1], sys.argv[2])
    else :
        helper()

Pour faire fonctionner ce script, il faut installer le module beautiful soup de python.
Sous Ubuntu, il suffit de faire :

sudo apt-get install python-beautifulsoup

Pour l’utiliser, il suffit de faire
mangastream.py manga chapitre

Exemple :
mangastream.py "History's Strongest Disciple Kenichi" 389

Publié dans Programmation | Tagué: , | Laisser un Commentaire »

Problèmes lors des mises à jours de gentoo

Publié par geenux le 20 avril 2010

Ce n’est pas la première fois que j’ai des problèmes lors de mises à jours de gentoo. Maintenant je commence à avoir quelques techniques pour m’en sortir, je vais les présenter ici, en espérant que ça puisse aider quelqu’un à se sortir du pétrin.

Mise à jour

Faire la mise à jour avec la commande

emerge -uDNav world

-u : update
-D : deep
-N : new-use, recompile les paquets pour lesquels les USE flags ne sont plus les mêmes que lors de la dernière compilation
-a : ask, demande confirmation. Profitez de ça pour regarder quels paquets importants du systèmes vont être mis à jour : xorg… Ça peut vous donner une idées des éventuels problèmes que vous pourrez rencontrer.

Une chose importante à faire ensuite, c’est de s’assurer que les libs correspondent bien, pour celà il faut utiliser la commande revdep-rebuild (de l’ebuild gentoolkit)

revdep-rebuild

Cette étape est importante, elle permet d’éviter des problèmes assez embêtant (par exemple une fois wicd ne fonctionnait plus à cause d’une lib).

Problèmes avec xorg

J’ai récemment eu un problème avec xorg : la souris, clavier, touchpad ne fonctionnaient plus :(
La solution était donné dans les messages de la mises à jour, mais comme je fais les mises à jour la nuit, je n’avais pas remarqué.
Pour résoudre ce problème, il faut lancer la commande

emerge $(qlist -I -C x11-drivers/)

Si j’ai d’autres problèmes, je posterai les solutions dans ce billet.

De façon générale, pensez à bien regarder le log de l’installation, souvent il y a des indications concernant la procédure a effectuer en cas de problème.
Pour parcourir les logs, vous pouvez utiliser elogv, ou configurer portage pour qu’il vous prévienne par « mail ».

Publié dans Gentoo | Tagué: | Laisser un Commentaire »

 
Suivre

Get every new post delivered to your Inbox.