| View previous topic :: View next topic |
| Author |
Message |
laikabaus Voice
Joined: 06 Aug 2012 Posts: 3
|
Posted: Mon Aug 06, 2012 3:31 pm Post subject: Spotify artist / song info from URL to text |
|
|
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 |
|
 |
doggo Halfop
Joined: 05 Jan 2010 Posts: 97
|
Posted: Tue Aug 07, 2012 7:52 pm Post subject: |
|
|
got an example of a url? i dont use spotify myself but ill have a look  _________________ NON geeky!! http://gotcode4u.com/ |
|
| Back to top |
|
 |
laikabaus Voice
Joined: 06 Aug 2012 Posts: 3
|
|
| Back to top |
|
 |
doggo Halfop
Joined: 05 Jan 2010 Posts: 97
|
Posted: Wed Aug 08, 2012 11:29 am Post subject: |
|
|
try this
| 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 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 |
|
 |
laikabaus Voice
Joined: 06 Aug 2012 Posts: 3
|
Posted: Thu Aug 09, 2012 6:05 am Post subject: |
|
|
Hi,
Thank you very much... made my day. Works well!  |
|
| Back to top |
|
 |
caesar Mint Rubber

Joined: 14 Oct 2001 Posts: 3741 Location: Mint Factory
|
Posted: Thu Aug 09, 2012 12:53 pm Post subject: |
|
|
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 |
|
 |
doggo Halfop
Joined: 05 Jan 2010 Posts: 97
|
Posted: Thu Aug 09, 2012 6:30 pm Post subject: |
|
|
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 |
|
 |
Tommyken Voice
Joined: 09 Apr 2008 Posts: 11
|
Posted: Wed Jan 09, 2013 12:59 pm Post subject: |
|
|
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 |
|
 |
|