egghelp.org community Forum Index
[ egghelp.org home | forum home ]
egghelp.org community
Discussion of eggdrop bots, shell accounts and tcl scripts.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Spotify artist / song info from URL to text

 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Script Requests
View previous topic :: View next topic  
Author Message
laikabaus
Voice


Joined: 06 Aug 2012
Posts: 3

PostPosted: Mon Aug 06, 2012 3:31 pm    Post subject: Spotify artist / song info from URL to text Reply with quote

Hi,

I've been looking for a script that would get the artist & song from Spotify URL when pasted to channel ( http://open.spotify.com/track/... ) and type them in text to channel by the Bot. So pretty much similar functionality that is present in Youtube script that gets the video information from Youtube URL pasted on channel. Thanks!
Back to top
View user's profile Send private message
doggo
Halfop


Joined: 05 Jan 2010
Posts: 97

PostPosted: Tue Aug 07, 2012 7:52 pm    Post subject: Reply with quote

got an example of a url? i dont use spotify myself but ill have a look Wink
_________________
NON geeky!! http://gotcode4u.com/
Back to top
View user's profile Send private message Visit poster's website
laikabaus
Voice


Joined: 06 Aug 2012
Posts: 3

PostPosted: Wed Aug 08, 2012 9:20 am    Post subject: Reply with quote

Hi,

Sure thing... http://open.spotify.com/track/67vnqJqWWlhSSkBj3wUasJ , the first part till /track/ is always intact, but the rest depends on the song / artist I'm guessing...
Back to top
View user's profile Send private message
doggo
Halfop


Joined: 05 Jan 2010
Posts: 97

PostPosted: Wed Aug 08, 2012 11:29 am    Post subject: Reply with quote

try this Wink


Code:
# spotify.tcl
# by doggo #omgwtfnzbs@EFNET
#############################

set logo "\002\00300,03 Spotify \017"

proc spotify:announce {nick uhost hand chan text} {
global logo

   if {[channel get $chan spotify] != 1 } { return }            

   if {[regexp -nocase {http://open.spotify.com/track/([A-Za-z0-9]+)} $text match spotify]} {

   set html [spotify:getdata "http://open.spotify.com/track/$spotify"]
   
   regexp -nocase {<meta property="og:description" content="(.*?), a song by\s(.*?)\son Spotify." />} $html match title artist

   if {![info exists title]} {
   putlog "\[spotify\] unable to get title/artist info from: http://open.spotify.com/track/$spotify"
   } else {
   putlog "\[spotify\] fetching: http://open.spotify.com/track/$spotify"
   puthelp "privmsg $chan :$logo $artist - $title"
  }
 }
}


proc spotify:getdata {data} {
   ::http::config -useragent "Mozilla/5.0 (X11; U; Linux i686; ru-RU; rv:1.8.1) Gecko/2006101023 Firefox/2.0"
   set url [::http::geturl $data -timeout 5000]
   set source_code [::http::data $url]
   ::http::cleanup $source_code
   return $source_code
}


package require http
setudef flag spotify
bind pubm -|- "% *http://open.spotify.com/track/*" spotify:announce

putlog "spotify.tcl loaded!"


load the script on the bot, then from the partyline for the channels you want the script to work in

Code:
.chanset #chan +spotify


only tested on a few urls.. worked fine Very Happy enjoy
_________________
NON geeky!! http://gotcode4u.com/


Last edited by doggo on Thu Aug 09, 2012 6:31 pm; edited 1 time in total
Back to top
View user's profile Send private message Visit poster's website
laikabaus
Voice


Joined: 06 Aug 2012
Posts: 3

PostPosted: Thu Aug 09, 2012 6:05 am    Post subject: Reply with quote

Hi,

Thank you very much... made my day. Works well! Smile
Back to top
View user's profile Send private message
caesar
Mint Rubber


Joined: 14 Oct 2001
Posts: 3741
Location: Mint Factory

PostPosted: Thu Aug 09, 2012 12:53 pm    Post subject: Reply with quote

What's the point of the regexp if you already match that url in the pubm bind?
_________________
Once the game is over, the king and the pawn go back in the same box.
Back to top
View user's profile Send private message
doggo
Halfop


Joined: 05 Jan 2010
Posts: 97

PostPosted: Thu Aug 09, 2012 6:30 pm    Post subject: Reply with quote

my understanding was

Code:
bind pubm -|- "% *http://open.spotify.com/track/*" spotify:announce


would only trigger the spotify:announce when it was needed.. and the regexp would pick out the part of the url i needed where as

Code:
bind pubm -|- "% *" spotify:announce



would trigger for everything typed in the enabled channel ??
_________________
NON geeky!! http://gotcode4u.com/
Back to top
View user's profile Send private message Visit poster's website
Tommyken
Voice


Joined: 09 Apr 2008
Posts: 11

PostPosted: Wed Jan 09, 2013 12:59 pm    Post subject: Reply with quote

too bad it don't works for me, i got this error
[17:57:23] <SVG> [18:03:21] [spotify] unable to get title/artist info from: http://open.spotify.com/track/6gotN2zpSrFblWw3qz63s1

i had set .chanset #chan +spotify too (offcours the right chan)

do i something wrong ?
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    egghelp.org community Forum Index -> Script Requests All times are GMT - 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Forum hosting provided by Reverse.net

Powered by phpBB © 2001, 2005 phpBB Group
subGreen style by ktauber