commit 3d0f86659c0642f60b856269d4ac91af4ea135db
parent ddb55dce90939a8fe1a3da65d0640bc5ec9570ca
Author: Christoph Lohmann <20h@r-36.net>
Date:   Sun, 10 May 2015 19:55:46 +0200
Update the files to 2015.
Diffstat:
| LICENSE | | | 2 | +- | 
| ddg | | | 14 | ++++++++++---- | 
| di-p | | | 63 | +++++++++++++++++++++++++++++++++++---------------------------- | 
| google | | | 12 | +++++------- | 
| sky-p | | | 1 | - | 
| xpath | | | 31 | ++++++++++++++++++++----------- | 
| ydl | | | 4 | ++-- | 
| ypl | | | 12 | ++++-------- | 
8 files changed, 77 insertions(+), 62 deletions(-)
diff --git a/LICENSE b/LICENSE
@@ -1,6 +1,6 @@
 This software is
 
-	© 2013 Christoph Lohmann <20h@r-36.net>
+	© 2013-15 Christoph Lohmann <20h@r-36.net>
 
 See the following part of this file for the license details:
 
diff --git a/ddg b/ddg
@@ -1,14 +1,15 @@
 #!/bin/sh
-# See the LICENSE file for copyright and license details.
 
 if [ $# -lt 1 ];
 then
-	echo "usage: `basename $0` search terms ..."
+	printf "usage: %s search terms ...\n" "$(basename "$0")" >&2
 	exit 1
 fi
 
-search=`echo -n "$*" \
-	| perl -p -e 's/([^A-Za-z0-9])/sprintf("%%%02X", ord($1))/seg'`
+[ -z "$PAGER" -o ! -t 1 ] && PAGER="cat"
+
+search="$(printf "%s" "$*" \
+	| perl -p -e 's/([^A-Za-z0-9])/sprintf("%%%02X", ord($1))/seg')"
 
 curl -s --user-agent \
 	"Lynx/2.8.8dev.3 libwww-FM/2.14 SSL-MM/1.4.1" \
@@ -16,6 +17,11 @@ curl -s --user-agent \
 	"https://duckduckgo.com/html/" \
 	| xpath -a href "//a[@href]" \
 	| grep "^.*://" \
+	| grep -v "https://duckduckgo.com" \
+	| grep -v "http://r.duckduckgo.com" \
+	| grep -v "http://ad.ddg.gg" \
+	| grep -v ".r.msn.com" \
+	| grep -v "^$" \
 	| uniq \
 	| head -n -7
 
diff --git a/di-p b/di-p
@@ -1,6 +1,9 @@
-#!/usr/bin/env python2
+#!/usr/bin/python
 # coding=utf-8
-# See the LICENSE file for copyright and license details.
+#
+# Copy me if you can.
+# by 20h
+#
 
 import sys
 import json
@@ -10,7 +13,7 @@ import datetime
 import random
 import signal
 from subprocess import Popen
-from urllib2 import urlopen, HTTPError
+import requests
 from getopt import getopt, GetoptError
 
 def runstream(player, stream):
@@ -22,24 +25,21 @@ def loadplaylistall():
 			"callback=_API_TrackHistory_getAll&_=%s"
 
 	utim = time.mktime(datetime.datetime.now().timetuple())
-	fd = urlopen(pluri % (utim))
-	playlists = unicode(fd.read(), "iso-8859-1")
+	fd = requests.get(pluri % (utim))
+	playlists = str(fd.read(), "iso-8859-1")
 	fd.close()
 	playlists = playlists[playlists.index("(")+1:\
 			playlists.rindex(");")]
 	playlist = json.loads(playlists)
 
-	return playlist
-
 def loadplaylist(ids):
 	pluri = "http://api.v2.audioaddict.com/v1/di/track_history/"\
 			"channel/%s.jsonp?callback=_API_Track"\
 			"History_getChannel&_=%s"
 
 	utim = time.mktime(datetime.datetime.now().timetuple())
-	fd = urlopen(pluri % (ids, utim))
-	playlists = unicode(fd.read(), "iso-8859-1")
-	fd.close()
+	fd = requests.get(pluri % (ids, utim))
+	playlists = fd.text
 	playlists = playlists[playlists.index("[{"):\
 			playlists.rindex(");")]
 	playlist = json.loads(playlists)
@@ -56,14 +56,14 @@ def usage(app):
 def main(args):
 	try:
 		opts, largs = getopt(args[1:], "hai:p:dlnrs:uwy")
-	except GetoptError, err:
-		print str(err)
+	except GetoptError as err:
+		print(str(err))
 		usage(args[0])
 		sys.exit(1)
 	
 	uri = "http://listen.di.fm/public3"
 
-	player = "mplayer -quiet -cache 512 -playlist"
+	player = "mpv -quiet -cache 512 -playlist"
 	debug = False
 	listen = False
 	plainlist = False
@@ -100,20 +100,20 @@ def main(args):
 		elif o == "-y":
 			playlist = True
 		elif o == "-w":
-			whatson = True
+			whatson = True 
 		else:
 			assert False, "unhandled option"
 	
 	if len(largs) < 1 and listen != True and dorandom != True and \
-			doplaylist != True and whatson != True:
+			doplaylist != True and whatson != True and \
+			playlist != True:
 		sys.stderr.write("You need to specify the to be played "
 				"stream. Please see -l for all available "
 				"streams.\n")
 		usage(args[0])
 
-	fd = urlopen(uri)
-	streams = json.load(fd)
-	fd.close()
+	fd = requests.get(uri)
+	streams = fd.json()
 
 	streams = sorted(streams, key = lambda k: k["key"])
 
@@ -135,41 +135,44 @@ def main(args):
 
 	if whatson == True:
 		recentdata = loadplaylistall()
-
 		for i in streams:
 			cplay = recentdata[str(i["id"])]
 			sys.stdout.write("%s\t%s\n" % (i["key"],\
 				cplay["track"]))
+
 		return 0
 
 	if playlist == True:
-		for i in streams:
-			if i["key"] != largs[0]:
-				continue
-
-			playlist = loadplaylist(i["id"])
+		def displayplaylist(playlist):
 			for song in playlist[::-1]:
 				dates = datetime.datetime.fromtimestamp(
 						int(song["started"])).\
 					strftime("%H:%M:%S")
 				sys.stdout.write("[%s] %s\n" % (dates,\
 					song["track"]))
+
+		for i in streams:
+			if i["key"] != largs[0]:
+				continue
+
+			cplaylist = loadplaylist(i["id"])
+			displayplaylist(cplaylist)
 		return 0
 
 	if listen == True:
 		if plainlist == True:
 			for i in streams:
-				print i["key"] 
+				print(i["key"]) 
 			return 0
 
 		if showuri == True:
 			for i in streams:
-				print i["playlist"]
+				print(i["playlist"])
 			return 0
 
 		for i in streams:
-			print "%s\t%s" % (i["key"], 
-					i["description"])
+			print("%30s %s" % (i["key"], 
+					i["name"]))
 		return 0
 
 	stream = None
@@ -186,6 +189,10 @@ def main(args):
 			" Please use -l for all available streams.\n")
 		return 1
 
+	if showuri == True:
+		print(("%s" % (stream["playlist"])))
+		return 0
+
 	while 1:
 		p = runstream(player, stream)
 		sts = os.waitpid(p.pid, os.P_NOWAIT)[1]
diff --git a/google b/google
@@ -1,21 +1,19 @@
 #!/bin/sh
-# See the LICENSE file for copyright and license details.
-
-printf "You need to make this script work on your own. Google is"
-printf " forbidding to scrape their website. You are doing this on"
-printf " your own. One important detail is missing in this script.\n"
-exit 1
 
 if [ $# -lt 1 ];
 then
 	echo "usage: `basename $0` search terms ..."
+	echo "Beware, that Google could filter the User-Agent!" \
+		"Be prepared to change it!"
 	exit 1
 fi
 
 search=`echo -n "$*" \
 	| perl -p -e 's/([^A-Za-z0-9])/sprintf("%%%02X", ord($1))/seg'`
 
-curl -s "https://encrypted.google.com/search?safe=off&q=${search}" \
+curl -s --user-agent \
+	"Lynx/2.8.8dev.3 libwww-FM/2.14 SSL-MM/1.4.1" \
+	"https://encrypted.google.com/search?safe=off&q=${search}" \
 	| xpath -a href "//a[@href]" \
 	| grep "^/url" \
 	| sed 's,/url?q=,,' \
diff --git a/sky-p b/sky-p
@@ -1,5 +1,4 @@
 #!/bin/sh
-# See the LICENSE file for copyright and license details.
 
 di-p -i "http://listen.sky.fm/public3" "$@"
 
diff --git a/xpath b/xpath
@@ -1,5 +1,8 @@
-#!/usr/bin/env python2
-# See the LICENSE file for copyright and license details.
+#!/usr/bin/env python
+#
+# Copy me if you can.
+# by 20h
+#
 
 import os
 import sys
@@ -7,14 +10,17 @@ import getopt
 from lxml import etree
 
 def getxpath(fd, xpath, attribute=None, encoding=None):
-	parser = etree.HTMLParser(encoding=encoding)
-	xml = etree.parse(fd, parser)
-	sels = xml.xpath(xpath)
+	try:
+		parser = etree.HTMLParser(encoding=encoding)
+		xml = etree.parse(fd, parser)
+		sels = xml.xpath(xpath)
+	except AssertionError:
+		return None
 
 	if attribute != None:
 		return "\n".join(["".join(i.attrib[attribute]) for i in sels])
 
-	return "".join(["".join(i.itertext()) for i in sels])
+	return "".join([("".join(i.itertext())).strip() for i in sels])
 
 def usage(app):
 	app = os.path.basename(app)
@@ -25,8 +31,8 @@ def usage(app):
 def main(args):
 	try:
 		opts, largs = getopt.getopt(args[1:], "he:a:")
-	except getopt.GetoptError, err:
-		print str(err)
+	except getopt.GetoptError as err:
+		print(str(err))
 		usage(args[0])
 
 	encoding = None 
@@ -43,9 +49,12 @@ def main(args):
 	
 	if len(largs) < 1:
 		usage(args[0])
-	
-	sys.stdout.write(getxpath(sys.stdin, largs[0], attribute,
-		encoding))
+
+	rpath = getxpath(sys.stdin, largs[0], attribute, encoding)
+	if rpath == None:
+		return 1
+
+	sys.stdout.write(rpath)
 
 	return 0
 
diff --git a/ydl b/ydl
@@ -1,5 +1,5 @@
 #!/bin/sh
-# See the LICENSE file for copyright and license details.
 
-cclive -f best "$1"
+cd $HOME/search/youtube
+yt -d "$@"
 
diff --git a/ypl b/ypl
@@ -1,11 +1,7 @@
 #!/bin/sh
-# See the LICENSE file for copyright and license details.
 
-MCMD="mplayer %u"
-if [ -z "$CACA_DRIVER" -a -z "$DISPLAY" ];
-then
-	export CACA_DRIVER=ncurses
-	MCMD="mplayer -vo caca %u"
-fi
-quvi --exec "$MCMD" "$1"
+[ -z "$MEDIAPLAYER" ] && MEDIAPLAYER=mpv
+mkdir -p $HOME/tmp/ytcache
+cd $HOME/tmp/ytcache
+youtube-dl --exec "${MEDIAPLAYER} {}" "$@"