domingo, 11 de marzo de 2012

Control Remoto (IR) en Zotac Nano + XBMC (Dharma) + Ubuntu 11.10 (Oneiric)

Para los que tiene un Zotac Nano y montaron un centro multimedia en él y no saben como hacer para que XBMC reconozca el control remoto que viene con el equipo, aquí están los pasos:

1.- Instalar "lirc".

  1. sudo apt-get install lirc

Si pregunta algo durante la instalación, déjenlo en "none" (primera opción), ya que lo configuraremos a mano más adelante.

2.- Configurar hardware.conf

  1. sudo vi /etc/lirc/hardware.conf

Cambiar estos parámetros:

  1. REMOTE_DEVICE="/dev/lirc0"
  2. START_LIRCD="true"

3.- Configurar lircd.conf

  1. sudo vi /etc/lirc/lircd.conf

Pegar el siguiente texto:

  1. # Please make this file available to others
  2. # by sending it to <lirc@bartelmus.de>
  3. #
  4. # this config file was automatically generated
  5. # using lirc-0.9.0(default) on Sat Jan 14 16:23:13 2012
  6. #
  7. # contributed by
  8. #
  9. # brand:                       MyRemote.conf
  10. # model no. of remote control:
  11. # devices being controlled by this remote:
  12. #
  13. begin remote
  14.   name  MyRemote
  15.   bits           37
  16.   flags RC6|CONST_LENGTH
  17.   eps            30
  18.   aeps          100
  19.   header       2661   869
  20.   one           446   437
  21.   zero          446   437
  22.   gap          106433
  23.   toggle_bit_mask 0x8000
  24.   rc6_mask    0x100000000
  25.       begin codes
  26.           KEY_POWER                0x037FCB7B71
  27.           KEY_POWER2               0x037FCB7BC2
  28.           KEY_RECORD               0x037FCB7BC8
  29.           KEY_PAUSE                0x037FCB7BCF
  30.           KEY_STOP                 0x037FCB7BCE
  31.           KEY_REWIND               0x037FCB7BD6
  32.           KEY_PLAY                 0x037FCB7BD3
  33.           KEY_FASTFORWARD          0x037FCB7BD7
  34.           KEY_PREVIOUSSONG         0x037FCB7BDE
  35.           KEY_NEXTSONG             0x037FCB7BDF
  36.           KEY_BACK                 0x037FCB7B7C
  37.           KEY_WIN                  0x037FCB7BA2
  38.           KEY_INFO                 0x037FCB7B34
  39.           KEY_UP                   0x037FCB7BA7
  40.           KEY_LEFT                 0x037FCB7BA5
  41.           KEY_OK                   0x037FCB7BA3
  42.           KEY_RIGHT                0x037FCB7BA4
  43.           KEY_DOWN                 0x037FCB7BA6
  44.           KEY_VOLUMEUP             0x037FCB7BEF
  45.           KEY_VOLUMEDOWN           0x037FCB7BEE
  46.           KEY_MUTE                 0x037FCB7BF2
  47.           KEY_CHANNELUP            0x037FCB7BE1
  48.           KEY_CHANNELDOWN          0x037FCB7BE0
  49.           KEY_NUMERIC_1            0x037FCB7BFE
  50.           KEY_NUMERIC_2            0x037FCB7BFD
  51.           KEY_NUMERIC_3            0x037FCB7BFC
  52.           KEY_NUMERIC_4            0x037FCB7BFB
  53.           KEY_NUMERIC_5            0x037FCB7BFA
  54.           KEY_NUMERIC_6            0x037FCB7BF9
  55.           KEY_NUMERIC_7            0x037FCB7BF8
  56.           KEY_NUMERIC_8            0x037FCB7BF7
  57.           KEY_NUMERIC_9            0x037FCB7BF6
  58.           KEY_NUMERIC_STAR         0x037FCB7BCC
  59.           KEY_NUMERIC_0            0x037FCB7BFF
  60.           KEY_NUMERIC_POUND        0x037FCB7BCD
  61.           KEY_CLEAR                0x037FCB7BC5
  62.           KEY_X                    0x037FCB7BD0
  63.           KEY_Y                    0x037FCB7BC1
  64.           KEY_ENTER                0x037FCB7BCB
  65.           KEY_RED                  0x037FCB7B92
  66.           KEY_GREEN                0x037FCB7B91
  67.           KEY_YELLOW               0x037FCB7B90
  68.           KEY_BLUE                 0x037FCB7B8F
  69.       end codes
  70. end remote

4.- Configurar Lircmap.xml

  1. sudo vi /usr/share/xbmc/system/Lircmap.xml

Pegar el siguiente texto:

  1. <!-- This file contains the mapping of LIRC keys to XBMC keys used in Keymap.xml  -->
  2. <!--                                                                              -->
  3. <!-- How to add remotes                                                           -->
  4. <!-- <remote device="name_Lirc_calls_the_remote">                                 -->
  5. <!--                                                                              -->
  6. <!-- For the commands the layout following layout is used                         -->
  7. <!-- <XBMC_COMMAND>LircButtonName</XBMC_COMMAND>                                  -->
  8. <!--                                                                              -->
  9. <!-- For a list of XBMC_COMMAND's check out the <remote> sections of keymap.xml   -->
  10. <lircmap>
  11.     <remote device="MyRemote">
  12.         <play>KEY_PLAY</play>
  13.         <pause>KEY_PAUSE</pause>
  14.         <stop>KEY_STOP</stop>
  15.         <forward>KEY_FASTFORWARD</forward>
  16.         <reverse>KEY_REWIND</reverse>
  17.         <left>KEY_LEFT</left>
  18.         <right>KEY_RIGHT</right>
  19.         <up>KEY_UP</up>
  20.         <down>KEY_DOWN</down>
  21.         <select>KEY_OK</select>
  22.         <pageplus>KEY_CHANNELUP</pageplus>
  23.         <pageminus>KEY_CHANNELDOWN</pageminus>
  24.         <back>KEY_BACK</back>
  25.         <menu>KEY_Y</menu>
  26.         <title>KEY_X</title>
  27.         <info>KEY_INFO</info>
  28.         <skipplus>KEY_NEXTSONG</skipplus>
  29.         <skipminus>KEY_PREVIOUSSONG</skipminus>
  30.         <display>Display</display>
  31.         <start>KEY_ENTER</start>
  32.         <record>KEY_RECORD</record>
  33.         <volumeplus>KEY_VOLUMEUP</volumeplus>
  34.         <volumeminus>KEY_VOLUMEDOWN</volumeminus>
  35.         <mute>KEY_MUTE</mute>
  36.         <power>KEY_POWER2</power>
  37.         <myvideo>Videos</myvideo>
  38.         <mymusic>Music</mymusic>
  39.         <mypictures>Pictures</mypictures>
  40.         <mytv>TV</mytv>
  41.         <one>KEY_NUMERIC_1</one>
  42.         <two>KEY_NUMERIC_2</two>
  43.         <three>KEY_NUMERIC_3</three>
  44.         <four>KEY_NUMERIC_4</four>
  45.         <five>KEY_NUMERIC_5</five>
  46.         <six>KEY_NUMERIC_6</six>
  47.         <seven>KEY_NUMERIC_7</seven>
  48.         <eight>KEY_NUMERIC_8</eight>
  49.         <nine>KEY_NUMERIC_9</nine>
  50.         <zero>KEY_NUMERIC_0</zero>
  51.         <star>KEY_NUMERIC_STAR</star>
  52.         <hash>KEY_NUMERIC_POUND</hash>
  53.         <clear>KEY_CLEAR</clear>
  54.         <enter>KEY_WIN</enter>
  55.         <red>KEY_RED</red>
  56.         <green>KEY_GREEN</green>
  57.         <yellow>KEY_YELLOW</yellow>
  58.         <blue>KEY_BLUE</blue>
  59.         <teletext>Teletext</teletext>
  60.     </remote>
  61. </lircmap>

El XBMC se debe ejecutar con la opción "-l" por lo que será necesario tener que cambiarlo en el LightDM (o GDM, según versión de Ubuntu)

...enjoy!!

sábado, 17 de septiembre de 2011

YouTube Searcher: Busca Videoclips de Música

Descripción:

Este script lista los videos de artistas (música) que están alojados en YouTube.

El listado de videos contempla el ID, nombre y duración de dichos videos.

Este script se puede complementar con otro script llamado "YouTube Downloader", el cual requiere del ID del video para descargarlo.

Enjoy!

#!/usr/bin/perl
use strict;
use HTTP::Lite;
use HTML::Entities;

#####################################################
#
# Desarrollado por: Zort
# Fecha: 16 de Septiembre de 2011
#
# Descripcion:
#   Este script lista los videos de artistas (musica) que
# estan alojados en YouTube.
#   El listado de videos contempla el ID, nombre y duracion
# de dichos videos.
#   Este script se puede complementar con otro script llamado
# "YouTube Downloader", el cual requiere del ID del video
# para descargarlo.
#
# Anexo:
#   Se omitieron todos los acentos en el codigo, para que no se
# vean caracteres erroneos en el caso de que el equipo donde
# se corra este codigo permita ver solo caracteres gringos.
#
#####################################################

my $artist = $ARGV[0];
$artist =~ s/^ +//;
$artist =~ s/ +$//;
$artist =~ s/ /_/g;

die "Usage: $0 artist\n\n" if ($artist eq '');

my $http = HTTP::Lite->new;
$http->http11_mode(1);

my $req = $http->request('http://www.youtube.com/artist/' . $artist);

if ($http->status() != 200) {
    print "No se pudo traer la pagina\n";
    exit;
}

# Getting the body page
my @body = split(/\n/, $http->body());

my $videos        = '';
my $artist_name   = '';
my $searching     = 0;
my $song_id       = 0;
my $song_duration = 0;
my $song_name     = 0;
foreach my $line (@body) {

    if ($line =~ /<h1>YouTube Mix for ([^<]*)</) {
        $artist_name = $1;
    }
    elsif ($line =~ /<h1>(Released in [0-9]+)/) {
        $videos .= "$1\n";
    }
    elsif ($line =~ / id="artist-videos" /) {
        $searching = 1;
    }
    elsif ($searching) {
        if ($line =~ /<li id="album-track-([^"]*)"/) {
            $song_id = $1;
        }
        elsif ($line =~ /<span class="album-track-duration">([^<]*)</) {
            $song_duration = $1;
        }
        elsif ($line =~ /<span class="description album-track-name">([^<]*)</) {
            $song_name = $1;
            $videos .= "  $song_id - " . decode_entities($song_name) . " ($song_duration)\n";
        }
    }
}

print "\n";
print 'Videos de "' . decode_entities($artist_name) . '":';
print "\n\n";
print $videos;

exit;

YouTube Downloader: Descarga Videos de YouTube

Yap, por fin salió!

Este script sirve para descargar videos de YouTube por CLI ;)

Lo único que tienen que hacer es ejecutar el script y pasarle como argumento el ID del video, luego el script preguntará el formato y resolución y... listo!

Enjoy!

#!/usr/bin/perl
use strict;
use HTTP::Lite;
use Data::Dumper;

#####################################################
#
# Desarrollado por: Zort
# Fecha: 16 de Septiembre de 2011
#
# Descripcion:
#   Este script descarga un video de YouTube especificado por
# el ID, el cual es entregado como parametro en la ejecucion.
#   A su vez, es posible elegir el formato y la resolucion
# del video segun la disponibilidad de YouTube de entregar el
# video con dichas caracteristicas.
#
# Anexo:
#   Se omitieron todos los acentos en el codigo, para que no se
# vean caracteres erroneos en el caso de que el equipo donde
# se corra este codigo permita ver solo caracteres gringos.
#   Se ha detectado que en ciertas ocasiones no se descarga
# el video. En estos casos se debe intentar nuevamente.
#
#####################################################

my $debug = 0;
my $video_id = $ARGV[0];

die "Usage: $0 video_id\n\n" if ($video_id eq '');

my $http = HTTP::Lite->new;
$http->http11_mode(1);

my $req = $http->request("http://www.youtube.com/get_video_info?video_id=$video_id&eurl=http%3A%2F%2Flocalhost%2F&hl=en_US")
    or die "Unable to get document: $!";

&showResponse($http) if ($debug);

if ($http->status() != 200) {
    print "The return code is not valid!\n";
    exit;
}

my $seconds        = 0;
my $fmt_stream_map = '';
my $fmt_list       = '';
my $title          = '';
my $token          = '';
my $formats        = ();

my @infos = split(/&/, $http->body());
foreach my $info (@infos) {

    my ($name, $value) = split(/=/, $info);

    $seconds        = $value            if ($name eq 'length_seconds');
    $fmt_stream_map = urlDecode($value) if ($name eq 'url_encoded_fmt_stream_map');
    $fmt_list       = urlDecode($value) if ($name eq 'fmt_list');
    $title          = urlDecode($value) if ($name eq 'title');
    $token          = $value            if ($name eq 'token');
}

my @formats_list = split(/,/, $fmt_list);
foreach my $format_list (@formats_list) {

    $format_list =~ /^([^\/]+)\/([^\/]+)\//;
    $formats->{$1}->{'resolution'} = $2;
}

my @formats_map = split(/,/, $fmt_stream_map);
foreach my $format_map (@formats_map) {

    my $url           = '';
    my $quality       = '';
    my $fallback_host = '';
    my $type          = '';
    my $itag          = '';

    my @variables = split(/&/, $format_map);
    foreach my $variable (@variables) {

        my ($name, $value) = split(/=/, $variable);

        $url           = urlDecode($value) if ($name eq 'url');
        $quality       = urlDecode($value) if ($name eq 'quality');
        $fallback_host = urlDecode($value) if ($name eq 'fallback_host');
        $type          = urlDecode($value) if ($name eq 'type');
        $itag          = $value            if ($name eq 'itag');
    }

    $formats->{$itag}->{'url'}           = $url;
    $formats->{$itag}->{'quality'}       = $quality;
    $formats->{$itag}->{'fallback_host'} = $fallback_host;
    $formats->{$itag}->{'type'}          = $type;
}

print "Titulo: $title\n";
print "Formatos:\n";
foreach my $format (sort { $formats->{$a}->{'type'} cmp $formats->{$b}->{'type'} } keys %{$formats}) {
    print " - (" . sprintf("%2d", $format) . ") " . $formats->{$format}->{'type'} . " (" . $formats->{$format}->{'quality'} . ") [" . $formats->{$format}->{'resolution'} . "]\n";
}
print "Opcion: ";
my $option = <STDIN>;
chomp($option);
print "Descargando numero $option...\n";
$http->reset();
$req = $http->request($formats->{$option}->{'url'});

my $output = $title;
$output .= '.mp4' if ($formats->{$option}->{'type'} =~ /video\/mp4/);
$output .= '.flv' if ($formats->{$option}->{'type'} =~ /video\/x-flv/);
$output .= '.webm' if ($formats->{$option}->{'type'} =~ /video\/webm/);

open(FH, '>', $output);
binmode(FH);
print FH $http->body();
close(FH);
print "Done!\n";
print "Archivo: '$output'\n";

   


#################
##  FUNCTIONS  ##
#################

sub showResponse() {

    my $http = shift;

    my $status     = $http->status();
    my $status_msg = $http->status_message();
    my @headers    = $http->headers_array();

    $status_msg =~ s/[\n\r]//g;

    print "Return Code:\n";
    print "    $status ($status_msg)\n";
    print "Headers:\n";
    foreach my $header (@headers) {
        print "    $header\n";
    }
    print "---------------------------\n";

    return 0;
}

sub urlDecode() {

    $_ = shift;

    s/\+/ /g;
    s/\%([0-9A-F]{2})/@{[chr hex $1]}/g;

    return $_;
}