Convert YouTube to mp3 in Cygwin

Step 1.) Download youtube-dl Windows version from http://rg3.github.com/youtube-dl/download.html Click Here

Step 2.) Download FFmpeg Windows 64 bit version from http://ffmpeg.zeranoe.com/builds/ Click Here

Step 3.)  Optional you can download mpg123-r2888-win64.zip Click Here

Install in your Cygwin Directory put all the exe files in  /cygwin/bin. Then use this script called youtube2mp3.sh to extract music from YouTube video.

#!/bin/bash
#A very simple Bash script to download a YouTube video
# and extract the music file from it.
address=$1
regex='v=(.*)'
if [[ $address =~ $regex ]]; then
video_file="$(youtube-dl --get-filename $address|sed 's/\r//g')"
video_title="$(youtube-dl --get-title $address|sed 's/\s/_/g')"
youtube-dl $address
ffmpeg -i "$video_file" "Music/$video_title".mp3
rm "./$video_file"
echo "done ..."
else
echo "Sorry but the system encountered a problem."
fi

Don’t forget to mkdir Music in your home directory in Cygwin. To execute type

./youtube2mp3.sh  "youryoutubevideolink"

Most conversion take less then 5 min. As you can see I  am replacing all spaces with underscore in title. FFmpeg didn’t like the spaces when automating in script.

Revamp Password Generator

PassGen

I redesigned Password Generator and made it as simple as possible.  The first version did not give you a choice when selecting a password but now you have four choices. This design is much smaller and gives more options then original.

 

Recommended installs for use with CMDCenter

Cygwin             -  http://www.cygwin.com/  Click Here
ActivePerl         -  http://www.activestate.com/activeperl  Click Here
ActivePython       -  http://www.activestate.com/activepython  Click Here
ActiveTcl          -  http://www.activestate.com/activetcl  Click Here
Ruby193            -  http://rubyinstaller.org/  Click Here
Sysinternals Suite - http://technet.microsoft.com/en-us/sysinternals/bb842062.aspxClick Here

To make Windows  more productive and like Linux, install scripting programs. When used with CMDCenter you can run most console based and scripting programs right from the Web-Browser. I am writing a eBook on operating CMDCenter but for now I just wrote this Post. The latest version is 1.0.4 and  I changed the color to gray so it will not be  confused with older versions. If you have a green CMDCenter you should update as soon as possible. Here are a few examples using the above programs in CMDCenter which will be covered in more depth in my eBook..

CMDCenter

 

The above shows the new CMDCenter. We will start with a few Cygwin commands like ls,cat,mkdir,rmdir,man  and awk. First type:

ls

in Command  textbox then press Run button. From now on I will presume you will enter a command and press Run button with the upcoming examples.  Here is results of above command. You should get a directory list.

ls

 

Now enter:

ls > list.txt

Now you will see it does not list file in Web-Browser but will see that it created  a file called  list.txt. View file type:

cat list.txt

As you can see it will display the file list. Everything is based on the current directory,. All commands run from current directory so if you want to edit the list.txt file enter:

notepad list.txt

It will open list.txt in notepad.

notepad

 

Let’s do a few more basic commands, then I’ll move on to running a perl script. You get all your shortcuts in Web-Browser like holding down the <CRTL> key and selecting the next file with the mouse, even skipping files and only selecting the files you want. Then right click, select Copy , then  right click again and select Paste in location of your choice  So to make a Folder you have to right click anywhere on the Web-Browser and select New then select Folder and name it. There are times that Web-Browser shortcuts  are better then typing a command like deleting a Folder in the current directory. With CMDCenter you can enter commands or Web-Browser shortcuts and choose any method you prefer. Now let’s try to make a directory. Enter:

mkdir Backup

You will see the folder Backup get created in your current directory.

Backup

Now to remove the empty Folder just type:

rmdir Backup

Because I am just giving basic commands I will not  show any recursive commands. To view a man page in Cygwin just type:

less

in Command , select the Manpage radiobutton  then press Run. You should see the Manpage of Less in Web-Browser.

Less

 

The last Cygwin command we’ll follow this  awk tutorial. Copy the employee.txt file to the current directory. Then try all the commands from the link provided  in CMDCenter. I will show one command. All examples from the tutorial.should work.  After you copy the employee.txt type:

awk '{print;}' employee.txt

You should see this in your Web-Browser.

employee

 

To keep this short I will display the script file then show it running in CMDCenter. First we’ll start with Perl. Copy this script and call it findalltcl.pl.

#!C:/Perl64/bin/perl.exe

    use strict;
    use warnings;

    my $dir = 'F:\CMDCenter';

    opendir(DIR, $dir) or die $!;

    while (my $file = readdir(DIR)) {

        # We only want files
        next unless (-f "$dir/$file");

        # Use a regular expression to find files ending in .txt
        next unless ($file =~ m/\.tcl$/);

        print "$file\n";
    }

    closedir(DIR);
    exit 0;

Now type:

perl findalltcl.pl

You might not have any Tcl files yet but I am going to give some examples so run it later. Here the results in the Web-Browser.

99bottles.tcl
hello.tcl

Python scripts are basically  run the same. Call this file listfiles.py.

#!python.exe

import os

for root, dirs, files in os.walk('./'):
   for name in files:       
       filename = os.path.join(root, name)
       print filename

Type:

python listfiles.py

Results are:

./99bottles.tcl
./command.sh
./command.txt
./date.php
./employee.txt
./findalltcl.pl
./hello.tcl
./list.txt
./listcolor.php
./listfiles.py

Tcl script is similar and I will test tclsh.exe and wish.exe. Let’s use wish.exe first. Copy this script and call it hello.tcl.

#  Create the main message window
     message .m -text "Hello Tcl!" -background white
     pack .m -expand true -fill both -ipadx 100 -ipady 40

     #  Create the main menu bar with a Help-About entry
     menu .menubar
     menu .menubar.help -tearoff 0
     .menubar add cascade -label "Help" -menu .menubar.help -underline 0
     .menubar.help add command -label "About Hello ..." \
          -accelerator "F1" -underline 0 \
          -command showAbout

     #  Define a procedure - an action for Help-About
     proc showAbout {} {
          tk_messageBox -message "Tcl/Tk\nHello Windows\nVersion 1.0" \
               -title "About Hello"
     }

     #  Configure the main window
     wm title . "Hello Foundation Application"
     . configure -menu .menubar -width 200 -height 150
     bind . "" {showAbout}

Type:

wish hello.tcl

This time you get a pop-up dialog box.

wish

 

Copy the next example and call it 99bottles.tcl.

# Tcl version of 99 bottles of beer on the wall
# Author: Don Libes (libes@nist.gov)
#

proc bottles {i} {
	return "$i bottle[expr $i!=1?"s":""] of beer"
}

proc line123 {i} {
	puts "[bottles $i] on the wall,"
	puts "[bottles $i],"
	puts "take one down, pass it around,"
}

proc line4 {i} {
	puts "[bottles $i] on the wall.\n"
}

for {set i 99} {$i>0} {} {
	line123 $i
	incr i -1
	line4 $i
}

Type:

tclsh 99bottles.tcl

You get this famous drinking song.

99 bottles of beer on the wall,
99 bottles of beer,
take one down, pass it around,
98 bottles of beer on the wall.

98 bottles of beer on the wall,
98 bottles of beer,
take one down, pass it around,
97 bottles of beer on the wall.

97 bottles of beer on the wall,
97 bottles of beer,
take one down, pass it around,
96 bottles of beer on the wall.

96 bottles of beer on the wall,
96 bottles of beer,
take one down, pass it around,
95 bottles of beer on the wall.

Ruby is another scripting program to test the next example call the file fact.rb.

# Program to find the factorial of a number
 # Save this as fact.rb

def fact(n)
   if n == 0
     1
   else
     n * fact(n-1)
   end
 end

puts fact(ARGV[0].to_i)

Now type:

ruby fact.rb 5

Run you get 120 as result.

If any of the above examples don’t run, most likely your PATH is not set for program right. So please set your Windows Environment Variables for the programs to run. From the list above I gave examples of all scripting programs running in CMDCenter the last is pslist.exe from Sysinternals Suite here is a screenshot.

Process information for JAMES-PC:

Name                Pid Pri Thd  Hnd   Priv        CPU Time    Elapsed Time 
Idle                  0   0   1    0      0     4:46:29.734     0:00:00.000
System                4   8 110  783    544     0:00:24.788     5:02:28.463
smss                352  11   2   29    376     0:00:00.062     5:02:28.354
csrss               452  13   9  565   1868     0:00:01.575     5:02:24.142
wininit             508  13   3   74   1304     0:00:00.093     5:02:22.956
csrss               516  13  13  569   6688     0:00:22.838     5:02:22.940
services            564   9   7  236   5400     0:00:01.981     5:02:22.722
lsass               576   9   7  844   5072     0:00:05.460     5:02:22.582
lsm                 584   8  10  199   2720     0:00:00.140     5:02:22.566
winlogon            620  13   3  110   2440     0:00:00.421     5:02:22.332
svchost             740   8  11  359   3544     0:00:03.182     5:02:21.630
svchost             800   8   8  298   4544     0:00:01.388     5:02:21.427
MsMpEng             852   8  23  410  74768     0:00:34.850     5:02:21.365
svchost             992   8  19  498  17032     0:00:03.447     5:02:17.371
svchost             380   8  27  658  85232     0:00:56.160     5:02:17.215
svchost             456   8  28  986  17144     0:00:04.492     5:02:17.122
svchost            1144   8  10  274   5672     0:00:01.310     5:02:15.468
svchost            1324   8  21  541  12428     0:00:03.572     5:02:14.563
dwm                1504  13   5  116  29120     0:01:22.243     5:02:13.658
explorer           1524   8  35 1134  49072     0:00:56.066     5:02:13.596
spoolsv            1572   8  12  327   6596     0:00:00.187     5:02:13.190
svchost            1608   8  18  305  15112     0:00:01.950     5:02:13.144

As a bonus here is a PHP example. Make sure you still have the file list.txt. If not create it by typing ls > list.txt. Type this script and call it listcolor.php. Sorry still getting use to WordPress so this script is an image. I am having trouble with display the PHP code.

PHPscript

Now type:

php listcolor.php

The results are as follows:

<html>
<body>

    <div style="background:#ddffdd;line-height:1px solid #004400;">
    99bottles.tcl
<br>    <div style="background:#ffdddd;line-height:1px solid #880000;">
    employee.txt
<br>
    <div style="background:#ddffdd;line-height:1px solid #004400;">
    findalltcl.pl
<br>    <div style="background:#ffdddd;line-height:1px solid #880000;">
    hello.tcl
<br>
    <div style="background:#ddffdd;line-height:1px solid #004400;">
    list.txt
<br>    <div style="background:#ffdddd;line-height:1px solid #880000;">
    listcolor.php
<br>
    <div style="background:#ddffdd;line-height:1px solid #004400;">
    listfiles.py<br></body>
 </html>

As you can see it’s working but it’s a html file and I am displaying in Web-Browser as text. To see as html file type the same command but pipe to a file called test.html. Enter:

php listcolor.php > test.html

Now double click on test.html that was  just created.. Results:

listcolor

 

Remember CMDCenter is a file manager and it’s great for testing your scripts without leaving your Browser. These examples will be in my eBook. Here is a hint that is not documented. If you entering a command  in the Command textbox and you want to enter your current directory just type %home (set to current directory [Home] button). Remember you can reset Home by selecting a directory that was added in History and press Set Home. Please leave a comment if you have any problems or just to praise the program.