Commit 0b836a37 authored by Lysander Trischler's avatar Lysander Trischler

s/\t/ /g

parent 818974cf
...@@ -31,15 +31,15 @@ import sys ...@@ -31,15 +31,15 @@ import sys
me = os.path.basename(__file__) me = os.path.basename(__file__)
for arg in sys.argv[1:]: for arg in sys.argv[1:]:
if arg in ("--help", "-h"): if arg in ("--help", "-h"):
print(__doc__.strip()) print(__doc__.strip())
exit(0) exit(0)
elif arg == "--version": elif arg == "--version":
print("%s Version %s" % (me, __version__)) print("%s Version %s" % (me, __version__))
exit(0) exit(0)
else: else:
sys.stderr.write("%s: Unknown argument `%s'!\n" % (me, arg)) sys.stderr.write("%s: Unknown argument `%s'!\n" % (me, arg))
exit(2) exit(2)
import xml.dom.minidom import xml.dom.minidom
import urllib import urllib
...@@ -53,14 +53,14 @@ index_file = os.path.join(os.path.dirname(__file__), "boydl.index") ...@@ -53,14 +53,14 @@ index_file = os.path.join(os.path.dirname(__file__), "boydl.index")
error_file = os.path.join(os.path.dirname(__file__), "boydl.error") error_file = os.path.join(os.path.dirname(__file__), "boydl.error")
if rss_url.startswith(("http://", "https://")): if rss_url.startswith(("http://", "https://")):
rss_stream = urllib.urlopen(rss_url) rss_stream = urllib.urlopen(rss_url)
else: else:
rss_stream = open(rss_url, "rb") rss_stream = open(rss_url, "rb")
tree = xml.dom.minidom.parseString(rss_stream.read() tree = xml.dom.minidom.parseString(rss_stream.read()
.replace("é", "é") .replace("é", "é")
.replace("<br>", "&lt;br&gt;") .replace("<br>", "&lt;br&gt;")
.replace("&ouml;", "ö") .replace("&ouml;", "ö")
.replace("< here >", "here") .replace("< here >", "here")
.replace("<</a>", "</a>")) .replace("<</a>", "</a>"))
rss_stream.close() rss_stream.close()
...@@ -68,58 +68,58 @@ channel = tree.getElementsByTagName("rss")[0].getElementsByTagName("channel")[0] ...@@ -68,58 +68,58 @@ channel = tree.getElementsByTagName("rss")[0].getElementsByTagName("channel")[0]
for item in channel.getElementsByTagName("item"): for item in channel.getElementsByTagName("item"):
# #
# first try to fetch the URL from the description, to bypass feed proxy # first try to fetch the URL from the description, to bypass feed proxy
# #
url = None url = None
m = link_regex.search(item.getElementsByTagName("description")[0].firstChild.data) m = link_regex.search(item.getElementsByTagName("description")[0].firstChild.data)
if m: if m:
url = 'http://www.youtube.com/v/%s' % m.group(1) url = 'http://www.youtube.com/v/%s' % m.group(1)
# #
# if description link cannot be parsed use feed proxy's URL # if description link cannot be parsed use feed proxy's URL
# #
if url is None: if url is None:
print("%s: Cannot extract direct link to Best of YouTube website for '%s'." print("%s: Cannot extract direct link to Best of YouTube website for '%s'."
" Using feed proxy's URL:" % ( " Using feed proxy's URL:" % (
me, item.getElementsByTagName('title')[0].firstChild.data)), me, item.getElementsByTagName('title')[0].firstChild.data)),
url = item.getElementsByTagName("link")[0].firstChild.data url = item.getElementsByTagName("link")[0].firstChild.data
print(url) print(url)
# #
# skip already downloaded videos # skip already downloaded videos
# Always read the index newly so parallel running boydls may # Always read the index newly so parallel running boydls may
# not download the same video multiple times. Please note this # not download the same video multiple times. Please note this
# implementation is not 100% safe: It is possible two or more # implementation is not 100% safe: It is possible two or more
# boydl instances execute this code at the very same time and # boydl instances execute this code at the very same time and
# therefore fetch the video twice or more often. Because this # therefore fetch the video twice or more often. Because this
# scenario is considered to happen only very rarly we don't # scenario is considered to happen only very rarly we don't
# care about it here. Most of the time this holds. # care about it here. Most of the time this holds.
# #
cont = False cont = False
index_stream = open(index_file, "rb") index_stream = open(index_file, "rb")
for line in index_stream.readlines(): for line in index_stream.readlines():
if line.strip() == url: if line.strip() == url:
cont = True cont = True
break break
index_stream.close() index_stream.close()
if cont: continue if cont: continue
# #
# download video # download video
# #
if url is None: if url is None:
sys.stderr.write("%s: Cannot extract YouTube video URL!\n" % me) sys.stderr.write("%s: Cannot extract YouTube video URL!\n" % me)
else: else:
index_stream = open(index_file, "ab") index_stream = open(index_file, "ab")
index_stream.write("%s\n" % url) index_stream.write("%s\n" % url)
index_stream.close() index_stream.close()
cmd = ydl + ' ' + url cmd = ydl + ' ' + url
print('—' * 80) print('—' * 80)
exit_code = os.system(cmd) % 255 exit_code = os.system(cmd) % 255
if exit_code != 0: if exit_code != 0:
sys.stderr.write("'%s' failed with exit code %d\n" % (cmd, exit_code)) sys.stderr.write("'%s' failed with exit code %d\n" % (cmd, exit_code))
error_stream = open(error_file, "ab") error_stream = open(error_file, "ab")
error_stream.write("%s\t%s\t%d\n" % (url, cmd, exit_code)) error_stream.write("%s\t%s\t%d\n" % (url, cmd, exit_code))
error_stream.close() error_stream.close()
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment