LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-13-2011, 11:28 AM   #1
supermario3
LQ Newbie
 
Registered: Jul 2011
Location: Italy
Distribution: Raspbian
Posts: 7

Rep: Reputation: Disabled
Cool [Bash] ID3, Youtube, Mp3, Download, Spreadsheet


Hello everyone. I'm Gianluca and I'm from Italy. It's my first time here.
Here's my "problem".
I have a index of songs that I made myself thanks to Google Docs.
An image explain more than a lot of words.
Song Index (imageshack.us)
In column B, I put the songs' names.
In column G, I write the author and in column H, the album.
In column F, I link the official video on youtube.
In other columns I put extra data to remind something to myself.

The index is becoming larger.
My idea is of a bash script that download the .mp3 from youtube and complete the id3 tag by taking the data (Song Name, Author and Album) from the Spreadsheet.
There are a lot of free service to download .mp3 from yt. But from shell?
And how to take the data from the Spreadsheet to write them on the .mp3?

Sorry for any language mistake, I'm still learning english
I hope you can help me.
If you can also link me useful material to accomplish this job, you're welcome.

Edit: I forgot to say: I use Ubuntu

Last edited by supermario3; 07-13-2011 at 12:19 PM. Reason: O.S Specification
 
Old 07-14-2011, 09:48 AM   #2
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Arch + Xfce
Posts: 6,852

Rep: Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037
The kind of script you're describing would be fairly complex; not something that could be quickly written up. It should be doable though.

What you need to do is first determine how to do each individual step independently.

The first requirement should be easy. There are several cli youtube download programs out there. Do a package search and/or Google it.

There are a variety of cli tag editors, as well.

Reading data directly from a spreadsheet file is trickier, so I'd first look into converting it into straight text. A simple field-delimited text file would be much easier to parse in a script.

Once you have all your commands sorted out, then it should be a fairly easy job to wrap it up into a script to process them in bulk.


Here are a few useful bash scripting references:
http://www.linuxcommand.org/index.php
http://tldp.org/LDP/Bash-Beginners-G...tml/index.html
http://www.tldp.org/LDP/abs/html/index.html
http://www.gnu.org/software/bash/manual/bashref.html
http://wiki.bash-hackers.org/start
http://mywiki.wooledge.org/BashFAQ
http://mywiki.wooledge.org/BashPitfalls
 
1 members found this post helpful.
Old 07-14-2011, 10:25 AM   #3
supermario3
LQ Newbie
 
Registered: Jul 2011
Location: Italy
Distribution: Raspbian
Posts: 7

Original Poster
Rep: Reputation: Disabled
I searched for id3tag and yt and I found something.
The problem is the spreadsheet.
With Google Docs I can export it in several format: csv, html, excel, openoffice, pdf and tsv.
But I don't not where to begin to parse information :-(
Is there a library for spreadsheet? I don't know
 
Old 07-15-2011, 08:58 AM   #4
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Arch + Xfce
Posts: 6,852

Rep: Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037
csv is "comma separated values", and I believe tsv is "tab separated values". Either of those should work. Tabs are probably better though, since commas are more likely to appear in your text. It would be even better if there were some way to define your own delimiting character.

As for parsing the text, load a line into an array and you'll be able to access any field by its index number.

We'll be here to help you with any specific problems you have, but it'll do you good to try to figure things out yourself first.

Last edited by David the H.; 07-15-2011 at 09:05 AM. Reason: added a bit
 
Old 07-19-2011, 08:09 AM   #5
supermario3
LQ Newbie
 
Registered: Jul 2011
Location: Italy
Distribution: Raspbian
Posts: 7

Original Poster
Rep: Reputation: Disabled
I'm trying to do it by myself and learn something about shell scripting.
I found id3v2 in Ubuntu repo which is very fast and simple and it does well his job.
But I'm stuck on two big problems:
1) youtube-dl, clive and cclive do not work. I tried with different videos and quality options. I can't get video files.
EDIT: To get youtube-dl working I added two ppa
ppa:gstreamer-developers/ppa
ppa:nilarimogard/webupd8

2) I figured out that csv is the best option to me. I used ";" (In Italy we call it "punto e virgola") to separate value.
So I have this very simple file
http://pastebin.com/gfnJ6DZs (save it as "Musica.csv")
With simple awk commands I can get the information there I want.
For example
awk -F "\"*;\"*" '{print $1 "|" $2}' Musica.csv
The command above shows the first two columns separated by a "|" .

But how I can print only the first row (horizontal) ?

Thanks you very much

Last edited by supermario3; 07-19-2011 at 10:32 AM. Reason: First problem solved
 
Old 07-19-2011, 09:55 AM   #6
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Arch + Xfce
Posts: 6,852

Rep: Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037
I must say you're doing quite well. I'm impressed.

";" is called a semicolon.

To target a specific line (or more accurately a record) in awk, test the "NR" variable.

Also, I wouldn't use that complex field delimiter. Just set it to a single semicolon, and use the gsub function to remove the quotes from the fields you want. It's safer than using a regex that could mismatch data if a field is misquoted.
Code:
awk -F ";" 'NR==1 { gsub(/\"/,"",$1) ; gsub(/\"/,"",$2) ; print $1"|"$2 }' Musica.csv
The gsub regex above simply removes all (") quote-marks from the field. We'll have to alter that if you need something more complex.

You can do pretty much the same thing without awk by using arrays. Use the IFS environment variable to set the separator. A simple loop over every line in the file would look like this:

Code:
file="Musica.csv"
IFS=";"
while read -a fields ; do

     echo "${fields[0]//\"}|${fields[1]//\"}"  #parameter substitution removes
                                               #quote-marks when printing.

done <"$file"
Here read with the -a option sets the array fields to the words of the input line (with "word" breaks being defined by the current IFS setting).

If you want to be able to access specific lines, you can store the lines in another array. Bash v.4 even has a new mapfile command to set an array with lines from a file. Or else use IFS again, this time set to newline, and set the array in a more traditional way.
Code:
file="Musica.csv"

#bash version 4
mapfile -t musiclines <"$file"

#bash version 3
IFS=$'\n'
musiclines=( $(<"$file") )

IFS=";"
read -a fields <<<"${musiclines[0]}"  #reads the first line from the array.
                                    #uses a "here string" for input.

echo "${fields[0]//\"}|${fields[1]//\"}"
 
Old 07-19-2011, 11:14 AM   #7
supermario3
LQ Newbie
 
Registered: Jul 2011
Location: Italy
Distribution: Raspbian
Posts: 7

Original Poster
Rep: Reputation: Disabled
All things I wrote are thanks to Google...
The awk command works for me but I don't completely understand it but I'm still reading a lot to learn about bash scripting.
Tomorrow I will try to understand the commands you wrote above.
In the mean time I wrote myself a interactive script that does what I want to do without Google Docs, with a single shell script.
It's very very simple my it's my first work and needs some adjustement
http://pastebin.com/WVmVDDc1
If you want to try it you must install libavcodec-extra-52 , youtube-dl , id3v2 , ffmpeg and update the programs from the two ppa linked below
ppa:gstreamer-developers/ppa
ppa:nilarimogard/webupd8
and also change line 52 to suit your needs.
Thanks you very much
Gianluca
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Bash script for sorting and renaming multiple mp3 files by id3 tags simonloach Linux - General 8 02-16-2013 09:07 AM
LXer: Youtube-dl - Download videos from Youtube in openSUSE LXer Syndicated Linux News 1 08-14-2008 08:10 AM
Ripping MP3's with ID3 tags... mlissner Fedora 22 08-27-2006 02:12 AM
Updating ID3 (MP3) Tags DJ747 Linux - Software 3 05-15-2005 11:22 AM
Software to rename MP3's according to ID3 Tags? Meowatilla Linux - Newbie 7 01-21-2005 04:26 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:06 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration