You are not logged in.
Hi everyone...
Well.. I made this script to get Mp3 fast and easy
It uses
lynx
youtube-dl
ffmpeg
lame
mp3gain (it doesn use it, but its great for normalize the volume on the tracks)
(you can go sudo apt-get install any of this programs easy... )
you save this bash script (something like "GetTrack"...) then do
chmod +x GetTrack
then
sudo mv GetTrack /usr/bin/
and then you can run it anywhere with just typing GetTrack , then it will ask you to put an artist name and song... and then the script uses lynx to get youtube links... then it download one, then extract the audio, then convert it to mp3...
#!/bin/bash
#*********************
#
# Variables
#
#*********************
artista="artista"
cancion="cancion"
archivo="archivo"
#*********************
#
# Searching Downloading and converting
#
#*********************
#artista + cancion + archivo = archivo.l
function getList() {
lynx -dump -listonly http://www.youtube.com/results?search_query="${1}"+"${2}">>${3}.rl
grep http://www.youtube.com/watch?v= ${3}.rl >> ${3}.rl1
rm ${3}.rl
cut -b 1-6 --complement ${3}.rl1 >> ${3}.rl2
rm ${3}.rl1
uniq ${3}.rl2 >> ${3}.rl3
rm ${3}.rl2
grep -v \& ${3}.rl3 >> ${3}.l
rm ${3}.rl3
}
#link + archivo = archivo.ytb
function download() {
youtube-dl ${1} -o ${2}.ytb
}
#archivo = archivo.wav
function extractAudio() {
ffmpeg -i ${1}.ytb -ac 2 ${1}.wav
}
#archivo = archivo.mp3
function toMp3() {
lame -b 320 ${1}.wav ${1}.mp3
}
#*********************
#
# MAIN
#
#*********************
index=`expr index "${lista}" \|`
read -p "Band: " artista
read -p "Song: " cancion
archivo=$(echo "${artista} ${cancion}" | sed -e 's/ /_/g')
if [ -f "${archivo}".mp3 ]
then
echo "Ya existe!"
break
fi
getList "$artista" "$cancion" "$archivo"
for link in $(cat ${archivo}.l)
do
download $link $archivo
if [ -f "${archivo}.ytb" ]
then
extractAudio $archivo
if [ -f "${archivo}.wav" ]
then
toMp3 $archivo
if [ -f "${archivo}.mp3" ]
then
rm ${archivo}.l
rm ${archivo}.ytb
rm ${archivo}.wav
break
else
rm ${archivo}.ytb
rm ${archivo}.wav
fi
else
rm ${archivo}.ytb
fi
fi
donethen i recommend using mp3gain -r -T *.mp3 on your music folder..
Last edited by Superchompu (2012-08-19 19:22:01)
What we wanted to preserve was not just a good environment in which to do programming, but a system around which fellowship could form. We knew from experience that the essence of communal computing, as supplied by remote-access, time-shared machines, is not just to type programs into a terminal instead of a keypunch, but to encourage close communication. -Dennis Ritchie
Offline
^ Great idea! I've been using youtube-dl to download tracks, and always found it annoying to open a web browser and search blabla....
Anyway thanks for taking the code out of my brain and making it happen I guess! 
Punch all your friends.
Offline
Let's test this out...
Run the script on it's own and it will ask for an Artist and Song?
Or run it with the artist name and song with it?
Please provide an example on how it should run
I have installed everything and saved this file, made it an executable as muzic.sh
When I run it as
sh muzic.shI get this error
muzic.sh: 18: muzic.sh: Syntax error: "(" unexpectedI get the same error if I run it as
sh muzic.sh Artist Songand as
sh muzic.sh "Cheap Trick" "Flame"Offline
Let's test this out...
Run the script on it's own and it will ask for an Artist and Song?
Or run it with the artist name and song with it?
Please provide an example on how it should run
I have installed everything and saved this file, made it an executable as muzic.sh
When I run it as
sh muzic.shI get this error
muzic.sh: 18: muzic.sh: Syntax error: "(" unexpectedI get the same error if I run it as
sh muzic.sh Artist Songand as
sh muzic.sh "Cheap Trick" "Flame"
hi, you should run it like this
bash nameOfFilethen it shouldn't be any problems
What we wanted to preserve was not just a good environment in which to do programming, but a system around which fellowship could form. We knew from experience that the essence of communal computing, as supplied by remote-access, time-shared machines, is not just to type programs into a terminal instead of a keypunch, but to encourage close communication. -Dennis Ritchie
Offline
^ Haven't tried this script yet, but since it declares /usr/bin/bash in the hashbang, shouldn't you be able to run it with just `nameofscript "artist" "title"`? 
while ( ! ( succeed = try() ) );
We've earned a reputation as a nice, friendly community; please help us keep it that way.
Offline
hi, you should run it like this
bash nameOfFilethen it shouldn't be any problems
Interesting... I have always been able to use sh filename instead of bash filename.
For those listening it is
bash muzic.sh
and the script then asks you for Band and Title to fill in..
Very nice script Superchompu! 
Offline
the error in Line 18 seems to be 'function getList()'
so i looked up differences between bash and sh, and it seems this has to do with the way of declaring a function (i think).
on many system /bin/sh is symlinked to /bin/bash. however, if i check my crunchbang, i see it is symlinked to /bin/dash. i remember seeing a thread about this somewhere around here, but okay.
so, trying to run 'sh <script>' doesn't work because you are calling dash, which seems to be a lightweight implementation of 'sh'. sh seems to have trouble with declaring functions, so it errors on the first function, Line 18.
still, should be possible to run
./muzic.shright?
i think the confusion stems from the weird habit to program in bash then give your file a .sh extension. lots and lots of people do that but i never really saw the point, as it is misleading and not necessary. when i add an extension i make it .bash but often i'll just leave out the extension altogether.
(no offense with this stuff to you Superchompu. still a great script)
Offline
I also tend to leave off the extension when I do my own shell scripts; it's just fewer characters to type, and I'm lazy like dat.
And this does look like a great, useful script.
while ( ! ( succeed = try() ) );
We've earned a reputation as a nice, friendly community; please help us keep it that way.
Offline
Hi, im glad people are enjoying it
I hace crunchbang statler, I have that script saved as "GetTrack" and I did chmod +x to it, and then i moved it to /usr/bin/
So i can just type GetTrack anywhere on the terminal and run it...
What we wanted to preserve was not just a good environment in which to do programming, but a system around which fellowship could form. We knew from experience that the essence of communal computing, as supplied by remote-access, time-shared machines, is not just to type programs into a terminal instead of a keypunch, but to encourage close communication. -Dennis Ritchie
Offline
Offline
I have that script saved as "GetTrack" and I did chmod +x to it, and then i moved it to /usr/bin/
So i can just type GetTrack anywhere on the terminal and run it...
I would suggest putting this information in the first post by editing it. This way everyone will have just what they need from the first post.
Offline
Superchompu wrote:I have that script saved as "GetTrack" and I did chmod +x to it, and then i moved it to /usr/bin/
So i can just type GetTrack anywhere on the terminal and run it...
I would suggest putting this information in the first post by editing it. This way everyone will have just what they need from the first post.
Done it... I also made two other scripts..... (one that let you choose the qualiity and shows the title of the youtube videos so you can choose.... and other one that when you call it you give it a file name, and then it uses that file to search download and extract that songs.... )
I will make them pretty and I'll post them...
Actually im thinking of putting that 3 scripts together, make it pretty, and then post it..
Last edited by Superchompu (2012-08-19 19:27:05)
What we wanted to preserve was not just a good environment in which to do programming, but a system around which fellowship could form. We knew from experience that the essence of communal computing, as supplied by remote-access, time-shared machines, is not just to type programs into a terminal instead of a keypunch, but to encourage close communication. -Dennis Ritchie
Offline
if you really want to make an mp3 out of anything, i recommend this
... and a kind word. -Duke
Offline
Thanks for the idea.
Inspired me to write one for my own needs that takes the artist, title, and YT URL (I want to give it a specific video).
Encodes to .ogg and tags it with the artitst/title info.
brother mouse
new to crunchbang.
my first linux kernel build was on a 386-16sx with 6MB SIPP RAM ($50/MB!)
Offline
Thanks for the idea.
Inspired me to write one for my own needs that takes the artist, title, and YT URL (I want to give it a specific video).
Encodes to .ogg and tags it with the artitst/title info.
Mind sharing it?
Offline
fratermus wrote:Thanks for the idea.
Inspired me to write one for my own needs that takes the artist, title, and YT URL (I want to give it a specific video).
Encodes to .ogg and tags it with the artitst/title info.Mind sharing it?
first draft. More useful as a something to get the juices flowing rather than for actual use. But it does appear to work.
#!/bin/bash
# based on a script by superchompu
# http://crunchbanglinux.org/forums/post/252894
# requires: vorbistools ffmpeg youtube-dl
# sanity check
if [ -f ripit.ytb ]
then
echo "ripit.ytb exists. Aborting."
ls -l ripit.*
exit
fi
# input
echo ARTIST name:
read ARTIST
echo
echo Song name:
read TITLE
echo
echo Youtube URL:
read YTURL
#download it
youtube-dl ${YTURL} -o ripit.ytb
#extract nicely
nice ffmpeg -i ripit.ytb -ac 2 ripit.wav
#encode
nice oggenc ripit.wav
#rename
#this is poorly thought out - FIXME
NEWNAME="$ARTIST - $TITLE - yt"
mv -v ripit.ogg "${NEWNAME}.ogg"
mv -v ripit.ytb "${NEWNAME}.ytb"
#tag
nice vorbiscomment -w -t "ARTIST=$ARTIST" -t "TITLE=$TITLE" "${NEWNAME}.ogg"
# show'em what they've won, Don Pardo
echo
ogginfo "${NEWNAME}.ogg"
# cleanup
rm ripit.wav
# keep the video
#mv -v *.ytb ~/videosBN: one can use
sh -x /path/to/scriptor
bash -x /path/to/script to get the shell to output useful info, depending on one's chosen poison^H^H^H^ shell.. Not a debugger in the normal sense (gdb, etc) but better than nothing.
brother mouse
new to crunchbang.
my first linux kernel build was on a 386-16sx with 6MB SIPP RAM ($50/MB!)
Offline
i think the confusion stems from the weird habit to program in bash then give your file a .sh extension. lots and lots of people do that but i never really saw the point, as it is misleading and not necessary.
I think the big problem is when people write a script that needs bash but give it a #!/bin/sh hashbang. If you want bash you should specifically call for it with #!/bin/bash.
About the extension, though, without being an expert, I'm not sure if using a .sh extension for bash scripts is any problem. bash is a shell too, after all. Could be wrong though, and of course any extension, or none, ought to be OK...
PS Superchompu thank you for this thread! A topic dear to my heart. 
John
--------------------
( a boring Japan blog , and idle twitterings )
Offline
Offline
YT has been seeking takedown orders against sites that provide the service; that was the source of my interest in making a local solution.
brother mouse
new to crunchbang.
my first linux kernel build was on a 386-16sx with 6MB SIPP RAM ($50/MB!)
Offline
a local solution.
Clipgrap is a local solution. A quick and easy download manager for youtube and all other online servives. 
Offline
@johnraff: the extension itself indeed doesn't influence anything - where not on Windows anymore 
however, i noticed VastOne attempting to execute the script by invoking 'sh', which was probably due to that extension.
so, it doesn't do harm, but it does add confusion, which is why i say 'stop making bashscripts and giving them a .sh name'.
also, while we're on the subject of naming conventions, people should stop making python scripts and naming them 'py-<something>' 
Offline
This one i like alot, very simple!
Iam just running:
bash mp3
And it ask me for band, and song! Then done! Thank you very much, finaly i dont need to use my webbrowser and use a addon to do this. 
Ofc i cd myself to the directory i want the music to be in, or make a folder.
Crunchy feeling #!
Offline
I think the big problem is when people write a script that needs bash but give it a #!/bin/sh hashbang. If you want bash you should specifically call for it with #!/bin/bash.
This was exactly the issue I had and did not realize it until looking closer at the code...
Assumptions are always at a cost, yes... It is all good now.
Offline
@vastone - you have a pm
all your Base are belong to us
Offline
Copyright © 2012 CrunchBang Linux.
Proudly powered by Debian. Hosted by Linode.
Debian is a registered trademark of Software in the Public Interest, Inc.