Author Topic: Automatic adding Internet Radio streams to LinuxMCE  (Read 48653 times)

Dap-P

  • Veteran
  • ***
  • Posts: 106
    • View Profile
Automatic adding Internet Radio streams to LinuxMCE
« on: October 26, 2013, 12:18:36 am »
Hi all,

I found this nice site that had indexed a whole lot of internet radio stations.
Here you also can find 'Local' radio stations, based on your geolocation (IP based)

so i made a command that downloads the needed information, as this would seem to me like a handy function to have while installing LMCE, or available from the Webadmin

Command:
Code: [Select]
curl --silent http://opml.radiotime.com/Browse.ashx?c=local | grep audio | grep station|  gawk -F'"' '{ print "Station : " $4}{system("curl --silent "$6" |  head -n1")}'
Output:
Code: [Select]
Station : #Station Name# (#Genre#)
#URL#

Now i need some help with putting this info in LinuxMCE
Is there a commandline script i can call, to add media to the LMCE database?
Or should this be done via Mysql?

Anton
« Last Edit: November 16, 2013, 08:22:49 pm by Dap-P »

golgoj4

  • NEEDS to work for LinuxMCE
  • ***
  • Posts: 1193
  • hrumpf!
    • View Profile
    • Mah Website
Re: Need help with automatic adding Internet Radio streams to LinuxMCE
« Reply #1 on: October 26, 2013, 01:34:22 am »
*bump* Sambucca might have a better idea. I would think that if done from the webadmin, setting up in the db would be done in the same command. I dont think there is a facility to do what you describe.

-Langston
Linuxmce - Where everyone is never wrong, but we are always behind xbmc in the media / ui department.

sambuca

  • Guru
  • ****
  • Posts: 462
    • View Profile
Re: Need help with automatic adding Internet Radio streams to LinuxMCE
« Reply #2 on: October 26, 2013, 02:42:52 pm »
Hi,

You can add files and streams of any kind from the web-admin, I think it is the Media File Sync menu. Go to the media file sync page and there should be a "Add new file" or something like that on the left side. I'm not able to double-check right now, but look around in the mentioned places ;)

br,
sambuca

Marie.O

  • Administrator
  • LinuxMCE God
  • *****
  • Posts: 3675
  • Wastes Life On LinuxMCE Since 2007
    • View Profile
    • My Home
Re: Need help with automatic adding Internet Radio streams to LinuxMCE
« Reply #3 on: October 26, 2013, 03:06:05 pm »
and after you've added a single station successfully to the pluto_media database, take a look at the File table, how it was added. After that, you should be able to add a bunch of stations from the commandline.

EDIT: Oh, and look at File_Attribute and Attribute, to see where the details like Title etc are stored.

sambuca

  • Guru
  • ****
  • Posts: 462
    • View Profile
Re: Need help with automatic adding Internet Radio streams to LinuxMCE
« Reply #4 on: October 26, 2013, 10:28:53 pm »
If you create a script to insert(and/or update) stations in lmce, please try to make it generic and available for other LMCE users. I know this has been requested before, so it would be beneficial...

(I know the html scraping part will be different for different sites, but the script to insert/update channels should be the same)

br,
sambuca

Dap-P

  • Veteran
  • ***
  • Posts: 106
    • View Profile
Re: Need help with automatic adding Internet Radio streams to LinuxMCE
« Reply #5 on: October 26, 2013, 11:54:54 pm »
Made a little progress, i can fill pluto_main from the cmdline

Example to add Dutch Radio station 3FM to LMCE. run this in bash, and you should have an extra radio stream
Code: [Select]
Station="3FM 96.5"
Genre="Alternative Rock"
Url="http://icecast.omroep.nl/3fm-bb-mp3"


echo "insert into File (EK_MediaType,DateAdded,Filename,Missing,IsDirectory,IsNew) VALUES(43,NOW(),'$Url',0,0,1);" | mysql pluto_media
PK_File=$(echo "select * from File where Filename='$Url';" | mysql pluto_media | tail -n1 | awk -F" " '{print $1}')
echo "insert into Attribute (FK_AttributeType,Name) VALUES(10,'$Station');" | mysql pluto_media
FK_Attribute=$(echo "select * from Attribute where Name='$Station';" | mysql pluto_media | tail -n1 | awk -F" " '{print $1}')
echo "insert into File_Attribute (FK_File,FK_Attribute,Track,Section) VALUES('$PK_File','$FK_Attribute',0,0);" | mysql pluto_media
echo "insert into LongAttribute (FK_AttributeType,FK_File,Text) VALUES(8,'$PK_File','$Genre');" | mysql pluto_media

But somehow the Stations name does not get linked to the 'File'
Run the code from a commandline, and see for yourself.

What am i not seeing in the database?

Anton

Modified, to correct commands
« Last Edit: October 27, 2013, 12:02:19 am by Dap-P »

sambuca

  • Guru
  • ****
  • Posts: 462
    • View Profile
Re: Need help with automatic adding Internet Radio streams to LinuxMCE
« Reply #6 on: October 26, 2013, 11:58:35 pm »
Well, you have PK_Attribute and FK_Attribute, use one or the other ;-)

Another thing to consider is when to re-use an existing attribute.... You could keep adding attribute with the same name, but that would make duplicate attributes in LMCE, not sure you want that...

br,
sambuca

Dap-P

  • Veteran
  • ***
  • Posts: 106
    • View Profile
Re: Need help with automatic adding Internet Radio streams to LinuxMCE
« Reply #7 on: October 27, 2013, 12:01:27 am »
I just saw it myself... Oops)
Fixed now

Marie.O

  • Administrator
  • LinuxMCE God
  • *****
  • Posts: 3675
  • Wastes Life On LinuxMCE Since 2007
    • View Profile
    • My Home
Re: Need help with automatic adding Internet Radio streams to LinuxMCE
« Reply #8 on: October 27, 2013, 12:06:40 am »
And a quick note on the syntax: use mysql -e instead of echo "", ie.

mysql pluto_media -e "SELECT COUNT(*) FROM File"


instead of

echo "SELECT COUNT(*) FROM File" | mysql pluto_media

Not sure if the variable replacement will still work, but that's how I add stuff into a database. OR, when I create scripts for LinuxMCE, I use the shell lib we already have in LinuxMCE, i.e.

. /usr/pluto/bin/SQL_Ops.sh 2>/dev/null || exit 1
. /usr/pluto/bin/Config_Ops.sh 2>/dev/null || exit 1

Q="SELECT IK_DeviceData FROM Device_DeviceData WHERE FK_Device = '$Device_ID' AND FK_DeviceData='$DD_ONLINE'"
Value=$(RunSQL "$Q")

Dap-P

  • Veteran
  • ***
  • Posts: 106
    • View Profile
Re: Need help with automatic adding Internet Radio streams to LinuxMCE
« Reply #9 on: October 27, 2013, 12:08:59 am »
Another thing to consider is when to re-use an existing attribute.... You could keep adding attribute with the same name, but that would make duplicate attributes in LMCE, not sure you want that...

Sambuca, this would only affect the Genre... Personally, i dont use it, but i wanted to add it anyway.
I am not a database guy... i will try to make it as neat as possible, so your remark has been noted)))

Posde, Thanks, i will try that

Dap-P

  • Veteran
  • ***
  • Posts: 106
    • View Profile
Re: Need help with automatic adding Internet Radio streams to LinuxMCE
« Reply #10 on: October 27, 2013, 01:09:24 am »
Ok, here is a working script,

It will download an indexfile and process it into the LinuxMCE
It does not add Genre's, only the station's name and the url

Can somebody try this out? And yes, it could mess up your whole DB.....
If you only want to see what stations would be added, comment out the Add to Database lines before running the script

Anton
« Last Edit: January 12, 2014, 02:56:33 pm by Dap-P »

Marie.O

  • Administrator
  • LinuxMCE God
  • *****
  • Posts: 3675
  • Wastes Life On LinuxMCE Since 2007
    • View Profile
    • My Home
Re: Need help with automatic adding Internet Radio streams to LinuxMCE
« Reply #11 on: October 27, 2013, 11:11:20 am »
Nice script, and I very much like the fact you added comments to it! One thing that you might want to look into is the last inserted ID http://dev.mysql.com/doc/refman/5.0/en/getting-unique-id.html - instead of relying on the URL to be in the system only once, use LAST_INSERTED_ID() like this:

mysql pluto_media  -e "INSERT INTO File (Filename) VALUES ('my nice file'); SELECT LAST_INSERT()"

It will return the last inserted ID that was created during your connection. Very helpful in my book. (I always have to look the syntax up, as my brain is not very good at remembering things ;) )


EDIT: Instead of hardcoding the temporary file, use tempfile, ile.

NameOfTempFile=`tempfile`
wget --output-document=$NameOfTempFile xxxxxx
« Last Edit: October 27, 2013, 11:14:24 am by posde »

golgoj4

  • NEEDS to work for LinuxMCE
  • ***
  • Posts: 1193
  • hrumpf!
    • View Profile
    • Mah Website
Re: Need help with automatic adding Internet Radio streams to LinuxMCE
« Reply #12 on: October 27, 2013, 02:58:08 pm »
Look, i dont mean to hijack, but let this thread be an example. if you reach out and get your hands a little dirty, people will show up to help

carry on  ;D
Linuxmce - Where everyone is never wrong, but we are always behind xbmc in the media / ui department.

Dap-P

  • Veteran
  • ***
  • Posts: 106
    • View Profile
Re: Need help with automatic adding Internet Radio streams to LinuxMCE
« Reply #13 on: October 27, 2013, 05:37:40 pm »
I want to expand the script with checks to not add duplicates, and to check the genre and reuse that attribute, its still just a simple script.

As I have no experience using mysql, all advise is appreciated. I will try to make to as useable as possible.

@posde Thanks for the tips

Anton

sambuca

  • Guru
  • ****
  • Posts: 462
    • View Profile
Re: Need help with automatic adding Internet Radio streams to LinuxMCE
« Reply #14 on: October 28, 2013, 02:38:42 pm »
Basically, it just involves doing a "select PK_Attribute from Attribute where FK_AttributeType = ? and Name=?", then check if that returned a PK_Attribute value. If it did, reuse that, if not, insert a new item.

br,
sambuca