This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

Spotify artist / song info from URL to text

Requests for complete scripts or modifications/fixes for scripts you didn't write. Response not guaranteed, and no thread bumping!
Post Reply
l
laikabaus
Voice
Posts: 3
Joined: Mon Aug 06, 2012 3:20 pm

Spotify artist / song info from URL to text

Post by laikabaus »

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!
d
doggo
Halfop
Posts: 97
Joined: Tue Jan 05, 2010 7:53 am
Contact:

Post by doggo »

got an example of a url? i dont use spotify myself but ill have a look ;)
l
laikabaus
Voice
Posts: 3
Joined: Mon Aug 06, 2012 3:20 pm

Post by laikabaus »

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...
d
doggo
Halfop
Posts: 97
Joined: Tue Jan 05, 2010 7:53 am
Contact:

Post by doggo »

try this :wink:

Code: Select all

# 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: Select all

.chanset #chan +spotify
only tested on a few urls.. worked fine :D enjoy
Last edited by doggo on Thu Aug 09, 2012 6:31 pm, edited 1 time in total.
l
laikabaus
Voice
Posts: 3
Joined: Mon Aug 06, 2012 3:20 pm

Post by laikabaus »

Hi,

Thank you very much... made my day. Works well! :)
User avatar
caesar
Mint Rubber
Posts: 3778
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

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.
d
doggo
Halfop
Posts: 97
Joined: Tue Jan 05, 2010 7:53 am
Contact:

Post by doggo »

my understanding was

Code: Select all

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: Select all

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

would trigger for everything typed in the enabled channel ??
T
Tommyken
Voice
Posts: 11
Joined: Wed Apr 09, 2008 1:11 pm

Post by Tommyken »

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 ?
Post Reply