Fluxbox Pastebin

Paste from Obzolete at Sat, 2 Mar 2013 23:19:29 +0000

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
#  srip.py
#  
#  Copyright 2013 Jared Nomak <obzolete@telfort.nl>
#  
#  This program is free software; you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation; either version 2 of the License, or
#  (at your option) any later version.
#  
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#  
#  You should have received a copy of the GNU General Public License
#  along with this program; if not, write to the Free Software
#  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
#  MA 02110-1301, USA.
#  
#  VERSION 0.2

import socket

# settings:

# dns or ip adress of server
host = "sc3.mystreamserver.com"
# port of stream server (empty for default)
port = "8054"
# path to stream (empty for root folder)
path = "/"
# print binary data to screen?
binprint = "0"
# file name (if not taken from stream info)
fname = "2tfm.mp3"
# stream name is file name?
snameisfname = "1"
# include stream description in file name? (only works with snameisfname = 1)
incsdesc = "1"

# program code:

def grab(string, what):
	if (string.find(what)) != -1:
		p = string.find(what)
		string =string[p:len(string)]
		e = string.find('\n')
		return string[0:e]

def after(string, after):
	string = string[string.find(after):len(string)]
	return string[1:len(string)]
	
def tag(string, tag):
	if (string.find(tag)) != -1:
		nfo = grab(string, tag)
		return after(nfo, ':')
	else:
		return "(no info)"

def htmlstrip(inp):
	inp = inp.strip('<BR>')
	inp = inp.strip('</a>')
	return inp

if (port) == '':
	port = ('80')

if (path) == '':
	path = "/"

s = socket.socket (
	socket.AF_INET, socket.SOCK_STREAM)
	
print "Connecting to: "+host+":"+port+path+"..."

s.connect((host, int(port)))

cmd = "GET " + path + " HTTP/1.1\n"
uag = "User-Agent: VLC/2.0.5 LibVLC/2.0.5\r\n\r\n"

s.sendall(cmd)
s.sendall(uag)

genre = ''
sname = ''
sdesc = ''

def sinfo(string):
	global sname
	string = string.rstrip()
	if (string.find('icy-')) != -1:
		info = string
		if (string.find('icy-notice1:')) != -1:
			print htmlstrip('Server notice: ' + tag(info, 'icy-notice1:'))
		if (string.find('icy-notice2:')) != -1:
			print ('Server notice: ' + tag(info, 'icy-notice2:'))
		genre = tag(info, 'icy-genre:')
		print ('Stream genre: ' + genre)
		global sdesc
		sdesc = tag(info, 'icy-description:')
		sdesc = sdesc.rstrip()
		print ('Stream description: ' + sdesc)
		sname = tag(info, 'icy-name:')
		sname = sname.strip('\r')
		print ('Stream name: ' + sname)
		print ('Stream URL: ' + tag(info, 'icy-url:'))
		if (string.find('Content-Type:')) != -1:
			ct = (tag(info, 'Content-Type:'))
		if (string.find('content-type:')) != -1:
			ct = (tag(info, 'content-type:'))
		ct = ct.strip(' ')
		br = tag(info, 'icy-br:')
		print 'Content Type: '+ct
		print 'Bitrate (kb/s): '+br
		pub = (tag(info, 'icy-pub:'))
		pub = pub[0:1]
		if pub == '1':
			pub = "yes"
		if pub == '0':
			pub = "no"
		print 'Public service: '+pub

info = "-1"
fi = "1"
data = ""

while 1:
	if (data) == "0":
		data = "-1"
	rep = s.recv(4096)
	if (data) != "-1":
		data = (data + rep)
	if (len(info)) < 3000:
		if (info) != "":
			info =(info + rep)
	if (len(info)) >= 3000:
		info = info.strip('\r')
		sinfo(info)
		info = ""
		if (int(snameisfname)) == 1:
			fname = sname
			if (int(incsdesc)) == 1:
				fname = fname+" - "+sdesc
			fname = fname+".mp3"
			fi = open (fname, "ab")
			fi.write(data)
			data = "0"
		else:
			if (int(snameisfname)) == 0:
				fi = open (fname, "ab")
				data = "-1"
		print ('Catching stream to: ' + fname + '...' + ' (press CTRL+C to stop)')
	if (data) == "-1":
		fi.write(rep)
	if (int(binprint)) == 1:
		print rep
	if rep == "":
		print ''
		e = raw_input("Stream ended, press enter key to continue...")
		break
# end