Posts Tagged 'howto'

DVD to video sharing under Linux howto

I have some DVD to publish on a popular video sharing service on the web. How to do that on Linux? Here a simple howto to achieve this.

First, get some useful software for this task. To do this you should sometimes add the Debian Multimedia repository to your /etc/apt/sources.list:

deb http://www.debian-multimedia.org etch main

Where “etch” is your distribution. Then run:

apt-get update

On sudo / superuser shell run:

  1. apt-get install avidemux acidrip lame x264 mplayer vorbis-tools dvdbackup
    Avidemux is a simple cut-and-paste non-linear editor and encoding software, acidrip a DVD-to-file ripper. X264 is a video encoder for the H.264/MPEG-4 AVC standard, lame an MP3 encoder and vorbis-tools contains OGG Vorbis encoders (a libre audio library).
  2. If you want to rip directly a DVD, encoding it as you wish without changes (cut and paste) from chapters, then use acidrip. For video use X264, for audio choose MP3 or Ogg Vorbis. (howto ends here)
  3. If you want to apply some changes, then first backup your dvd with dvdbackup:
    dvdbackup -i /dev/dvd -o my_destination_directory/ -n myDVDtitle -M
  4. Open the first huge .VOB file (eg. VTS_01_1.vob) with avidemux, then choose YES for indexing it
  5. Now you can export the whole file or part of it: choose x264 as video codec and Vorbis or Lame (MP3) as audio codec. Leave AVI as Format (or choose another).
  6. If you want to extract a portion of the video, move cursor to first frame of the selection and click A (Selection Start). Then go to last frame of the selection and click B (Selection End)
  7. Click to File -> Save Video to export the selected portion (read Avidemux wiki to more and detailed options). If files are compatible in width x height you can also use the “Append” function to queue more files generating and exporting a bigger one.

Now you can upload your video to popular online file sharing services. Enjoy!

Add to Bookmark / Favorites on Drupal

Tested on:

  • Drupal 5.x
  • Zen theme

On your page.tpl.php, change default node links rendering with this:

<?php if ($links): ?>
<div class=”links”>
<?php
# add to favorites / bookmarks link
$node->links['add2fav'] = Array(
‘title’=>trim(t(”Add to favorites”)),
‘href’=>$_GET['q'],
‘attributes’=>Array(
‘class’=>”add2fav”,
‘onclick’=>’bookmark()’,
)
);
# intercept and theme node links
print theme_links($node->links);
print ‘<script type=”text/javascript”>// <![CDATA[
function bookmark(){
var url = window.document.location;
var title = window.document.title;
if ((navigator.appName == "Microsoft Internet Explorer") && (parseInt(navigator.appVersion) >= 4)) {
window.external.AddFavorite(url,title);
} else if (navigator.appName == "Netscape") {
window.sidebar.addPanel(title,url,"");
} else {
alert("Press CTRL-D (Netscape) or CTRL-T (Opera) to bookmark");
}
}
// ]]></script>’;
?>
</div>
<?php endif; ?>

Now any node has your “Add to favorites” link, try to click it.

If you wrap alert message in a t() function, you can also translate displayed message.

See also:

Netgear WG111 on Debian Lenny with ndiswrapper

Tested on: Debian Etch, Lenny/Sid (Testing), kernel 2.6

  1. Plug WG111 and type lsusb to verify hardware is plugged. You should get something like:
    Bus 003 Device 002: ID 0000:0000 NetGear, Inc. WG111 WiFi (v2)
    Bus 003 Device 001: ID 0000:0000
    Bus 001 Device 001: ID 0000:0000
    Bus 002 Device 001: ID 0000:0000
  2. On root shell, type:
    m-a prepare
    m-a a-i ndiswrapper
    modprobe ndiswrapper

    Now ndiswrapper module is loaded. (if you got a FATAL: Module ndiswrapper not found fatal error, repeat these steps)
  3. If interface is successfully modprobed, then type
    update-modules
    To create ndiswrapper module config files.
  4. Add
    ndiswrapper
    to /etc/modules to load this module on boot.

  5. apt-get install module-assistant wlassistant ndisgtk ndiswrapper-utils
    Install some utilities to configure wireless interface.
  6. Run ndisgtk (or type ndiswrapper -i /media/cdrom0/ndis5/netwg111.inf, where cdrom0 is Netgear driver disc)
  7. Select Netgear driver from CD-ROM (netwg111.inf): it’ll be copied automatically to /etc/ndiswrapper
  8. Copy other files under /media/cdrom0/ndis5 in /etc/ndiswrapper/netwg111/
  9. If interface is not detected, type ndiswrapper -m to write modprobe config files for it.
  10. Use gksu network-admin or gksu wlassistant to configure your wireless connection.

Tip: If after system upgrading you cannot access to wireless network, repeat step (2).

See also:

Translate Drupal block titles

A simple snippet based on theme_block() and t() functions. (Tested on Drupal 5.x, Zen subtheme).

  1. Copy and paste this code into your template.php:

    function zen_block($block) {
    $output = “<div class=\”block block-$block->module\” id=\”block-$block->module-$block->delta\”>\n”;
    $output .= ” <h2 class=\”title\”>”.t($block->subject).”</h2>\n”;
    $output .= ” <div class=\”content\”>$block->content</div>\n”;
    $output .= “</div>\n”;
    return $output;
    }

  2. Go to admin/settings/locale/string/search and search the title to translate from English to your localization language.

Add CSS class to drupal form fieldset

Tested on:

  • Drupal 5.x
  • Zen custom subtheme

Customizing Drupal form appearance may sound difficult. But to add a CSS class is (surprisingly!) simple using theme_fieldset themeable function.

  • Copy theme_fieldset code from Drupal manual page
  • Paste to your template.php:
    • If you’re using a Zen theme, change theme_fieldset to zen_fieldset. You can try to use this method with your theme prefix.
    • If you’re using a theme based on phptemplate engine, you can change theme_fieldset to zen_fieldset to have the same effect of above (try one of this, not both).
  • Change the resultant code as you wish.

I’ve attached an example to generate CSS class from fieldset title: Add CSS class to drupal form fieldset.

# custom fieldset CSS class from element #title
$css_class = “my-custom-class-”;
$css_class .= str_replace(” “,”-”,strtolower($element['#title']));
# using transliteration module to transliterate/strip non-ASCII character where available
if(module_exists(’transliteration’)){
# including Transliteration functions
require_once(drupal_get_path(’module’, ‘transliteration’) .’/transliteration.inc’);
$css_class = transliteration_clean_filename($css_class);
}

Adding this code to your template:

  • Take all Drupal generated fieldset title
    • e.g. “Impostazioni del menù”
  • Transform it in a CSS class using Transliteration module
    • e.g. “my-custom-class-impostazioni-del-menu”
  • Queue it with other CSS classes (where available)
    • e.g “collapsible my-custom-class-impostazioni-del-menu”

I apply a previous substitution of whitespace using “-” (transliteration module use underscore “_”) and you can do the same, but later remember to use transliteration_clean_filename to safely sanitize class name for any other case you’ve not contemplated (accents, special characters).

Customize links menu in Drupal

Tested on: Zen theme, Drupal 5.7

  1. Copy function theme_links from includes/themes.inc
  2. Paste it into your template.php
  3. Rename it in theme_primarylinks (or anything you want)
  4. In your page.tpl.php, change
    1. print theme(’links’, $primary_links);
    2. to print theme(’primarylinks’, $primary_links);
  5. Apply some changes to theme_primarylinks to customize your primary links.

According to theme manual, for any first argument passed to theme function a theme_functionname function is called.

Contemplate and views: create a link without $node->path

In contemplate and views, $node->path return current page path. But this variable is only available to users with “administer alias” permission, so as administrator you can view links, but as normal user you cannot use them.

Here a $node->path alternative:

l(strip_tags($node->title),"node/".$node->nid)

Since $node->title is raw input, strip_tags strips all HTML tags.
A node/$node->nid links to article. Drupal link function returns the (in case) aliased path.

Enable user profile field token on Drupal

Tested on:

  1. In token module directory, rename token_user.inc to token_user.inc.orig
  2. Copy pmail/patches/token_user.inc in  Token module directory
  3. Go to Personalized E-mails setting and watch your profile fields as tokens.

Optimize Amarok collection indexing using MySQL

By default, Amarok use SQLite to store collection informations. If you’ve a running MySQL or Postgre server on your machine, you can optimize Amarok collection indexing reducing retrieval time.
Amarok MySQL configuration

  1. Open a root shell (sudo bash) and run mysql
    mysql> create database amarok;
    Query OK, 1 row affected (0.00 sec)
    
    mysql> grant all privileges on amarok.* to 'amarok'@'localhost'\
    identified by 'type_here_your_password';
    Query OK, 0 rows affected (0.00 sec)
  2. Open Amarok and go to Settings > Amarok configuration > Collection and fill the database fields (watch screenshow)
  3. If you got an error don’t worry, simply force collection re-scan (Tools)

Now your music collection run on an efficient MySQL database.

Make JCarousel and Contemplate work together

Drupal modules needed:

* = tested on latest official release
Howto subject: How to use JCarousel within a Contemplate modified node body

JCarousel is a nice JQuery plugin to render a vertical or horizontal bar containing some custom HTML code elements. Every element is within a list item of an unordered list. On page load a JQuery event trigger the simple unordered list to show as a bar.

Let’s start

To use Contemplate more smoothly (and without cut/paste from your preferred code editor, i.e. Quanta), you can create a file-based contemplate instead a database based.

  1. Create a sites/all/contemplates folder (or sites/mysitename/contemplates)
  2. According to Contemplate help (admin/help/contemplate), put there your node-mynodetype-body.tpl.php file, where “mynodetype” is the machine name of the type you want to modify (that one that appears like node/add/mynodetype when you create a new node of that type).
  3. Visit admin/content/templates to update the contemplate list. Now, if you go to admin/content/templates/mynodetype you can read:

    This template is being read fromsites/all/contemplates/node-mynodetype-body.tpl.php
    Please make changes to this file or remove it to continue editing here.

This is your contemplate file for this how-to. You’ve only to modify it, upload it and watch your mynodetype body growing up with JCarousel.

Call JCarousel

On the top of your content template, write:

if(module_exists(”jcarousel”)){
jcarousel_add(”tango”);
$js = “#function to add a Bouncing Effect on your JCarousel: you can add another custom effect function
// Credits: Robert Penners easing equations (http://www.robertpenner.com/easing/).
jQuery.easing['BounceEaseOut'] = function(p, t, b, c, d) {
if ((t/=d) < (1/2.75)) {
return c*(7.5625*t*t) + b;
} else if (t < (2/2.75)) {
return c*(7.5625*(t-=(1.5/2.75))*t + .75) + b;
} else if (t < (2.5/2.75)) {
return c*(7.5625*(t-=(2.25/2.75))*t + .9375) + b;
} else {
return c*(7.5625*(t-=(2.625/2.75))*t + .984375) + b;
}
};

# Call JCarousel when page is ready for the element mycarousel
# Read http://sorgalla.com/projects/jcarousel/#Configuration
jQuery(document).ready(function() {
jQuery(’#mycarousel’).jcarousel({
vertical: false,
animation: 3000,
easing: ‘BounceEaseOut’,
visible: 5,
scroll: 4
});
});”;

#add to HTML page HEAD this JavaScript code
drupal_add_js($js, ‘inline’, ‘header’);
}
?>

Styling

Using latest official release of JCarousel, tango theme skin.css file returns a buggy appearance. You can switch to the original tango skin.css file on sorgalla.com. Simply copy that file to your module skin folder.
In order to make your JCarousel works better, you have to write some additional CSS lines on your theme CSS file:

/* JCarousel custom CSS for horizontal bars */
/* DO NOT USE margin or padding for item elements
(auto-adjusted with visible/scroll JCarousel options) */
.jcarousel-item-horizontal{
width: 100px;
}
/* Bar total width for 5 elements
(100×5)px + 10px horizontal padding */
.jcarousel-container-horizontal,
.jcarousel-clip-horizontal{
width: 550px;
}

/* center jcarousel within a block element */
..jcarousel-container-horizontal{
margin: auto;
}

/* item height = bar height */
.char .jcarousel-item-horizontal,
.char .jcarousel-clip-horizontal{
height: 150px;
}

Contemplate JCarousel

A simple but useful way to test JCarousel is to display attached image files on your mynodetype. Assuming that all attached files are image files, that you want tango theme and you want to render an imagecache picture with preset named “my_thumbnail_preset”, add to your contemplate file these lines:

<?php
/* UPLOADED FILE CAROUSEL */
$attached_files_carousel = TRUE;

if($attached_files_carousel): ?>
<ul id=”mycarousel” class=”jcarousel-skin-tango”>
<?php
$preview_imagecache_preset = ‘character_picture’;
if(!empty($node->files)){
foreach($node->files as $uploaded_file){
/* if imagecache is present, build the thumbnail */
if(module_exists(’imagecache’))
$uploaded_file_preview = theme(’imagecache’,$preview_imagecache_preset,$uploaded_file->filepath);
else
$uploaded_file_preview = l($uploaded_file->filename,$uploaded_file->filepath);
/* Print the List Item */
print “<li>” . ‘<a title=”‘.$uploaded_file->filename.’” rel=”lightbox” href=”‘. base_path() . $uploaded_file->filepath . ‘”>’. $uploaded_file_preview . ‘</a>’ . “</li>”;
}
}
?>
</ul>
<?php # END CAROUSEL
endif; ?>

Fantastic Attachments

This method simply write the UL#mycarousel via PHP (static JCarousel method). Using rel=”lightbox” enable image file zoom via JavaScript, if lightbox v2 module is enabled. If you want to implement complex AJAX loading or to experiment more JCarousel effects, options and customizations, see also:

Next Page »