Skip to content

Instantly share code, notes, and snippets.

@hedgeven
Last active January 3, 2016 08:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hedgeven/8434857 to your computer and use it in GitHub Desktop.
Save hedgeven/8434857 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3.3
#
# hedgeven@linux.com, 2014
#
# Distributed under the MIT License.
# (See accompanying file LICENSE or copy at
# http://opensource.org/licenses/MIT)
#
#
# Script for downloading Aerostat podcasts (and maybe other podcasts)
# To fill the ID3 tag need the eyeD3
# Usage:
# ./aerostat_downloader.py [start:end]
#
from urllib.request import urlopen
from xml.etree import ElementTree as ET
import re, os, sys
work_dir = "Downloads/Aerostat"
xml_url = "http://aerostat.rpod.ru/rss.xml"
def download(url,file_name):
u = urlopen(url)
f = open(file_name, 'wb')
meta = u.info()
file_size = int(meta.get("Content-Length"))
print("Downloading: "+file_name, end="\t")
file_size_dl = 0
block_sz = 8192
while True:
buffer = u.read(block_sz)
if not buffer:
break
file_size_dl += len(buffer)
f.write(buffer)
status = r"[%3.2f%%]" % (file_size_dl * 100. / file_size)
status = status + chr(8)*(len(status)+1)
print(status, end=" ")
f.close()
print()
def main(argv):
pod_min=1
pod_max=0
if len(argv)>0:
args = re.findall('\d+', argv[0])
try:
pod_min=int(args[0])
pod_max=int(args[1])
except:
pass
root = ET.parse(urlopen(xml_url)).getroot()
items = root.findall('channel')[0].findall('item')
pod_list={}
for item in items:
index=int(re.findall('\d+', item.find('title').text)[0])
pod_list[index] ={}
pod_list[index]['title'] = item.find('title').text
pod_list[index]['author'] = item.find('author').text
pod_list[index]['url'] = item.find('enclosure').attrib['url']
if pod_max==0 or pod_min>pod_max:
pod_max=len(pod_list)
if not os.path.exists(work_dir):
os.mkdir(work_dir)
for item in sorted(pod_list)[pod_min-1:pod_max]:
author=pod_list[item]['author']
title=re.sub('"', '', pod_list[item]['title'])
filename=title+'.mp3'
url=pod_list[item]['url']
download(url,work_dir+'/'+filename)
os.system("eyeD3 --set-encoding=utf8 --to-v2.4 --remove-v1 --remove-comments -a "\
+author+" -A "+author+" -t '"+title+"' -n "+str(item)+" '"+work_dir+"/"\
+filename+"' >/dev/null")
if __name__ == "__main__":
main(sys.argv[1:])
@mega-narwhal
Copy link

for item in items:
index = int(re.findall('\d+', item.find('title').text)[0])
pod_list[index] ={}
pod_list[index]['title'] = item.find('title').text
pod_list[index]['author'] = item.find('author').text
pod_list[index]['url'] = item.find('enclosure').attrib['url']

@hedgeven
Copy link
Author

Спасибо, поправил.

@hedgeven
Copy link
Author

Для автоматической корректировки тегов нужно наличие программы eyeD3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment