Skip to content

Commit

Permalink
misc fix
Browse files Browse the repository at this point in the history
Signed-off-by: cash qian <[email protected]>
  • Loading branch information
jhqian committed May 26, 2015
1 parent bf6732a commit 30f025f
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 22 deletions.
6 changes: 3 additions & 3 deletions batch_get.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#!/bin/bash
#http://easyfm.azurewebsites.net/mod.cri.cn/eng/ez/morning/2014/ezm140620.mp3

for (( i=1; i<12; i++ ))
for (( i=1; i<2; i++ ))
do
mon=$i
for (( j=1; j<32; j++ ))
for (( j=9; j<31; j++ ))
do
day=$j
./ezez.py -o output -y 2014 -m $mon -d $day -a ./thumb.jpg
./ezez.py -o ~/Music/ezmorning/podcast/output -y 2015 -m $mon -d $day -a ~/Music/ezmorning/podcast/thumb.jpg
done
done
54 changes: 35 additions & 19 deletions ezez.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def usage():
sys.exit(1)

try:
opts, args = getopt.getopt(sys.argv[1:], "fhivo:y:m:d:a:", ["help", "output=", "year=", "month=", "day=", "artwork="])
opts, args = getopt.getopt(sys.argv[1:], "fFhivo:y:m:d:a:", ["help", "output=", "year=", "month=", "day=", "artwork="])
except getopt.GetoptError as err:
print err
usage()
Expand All @@ -52,6 +52,14 @@ def usage():
is_current_year = False
is_current_month = False
is_interactive = True
is_forced = False
is_a_cron_task = False

if not os.isatty(sys.stdin.fileno()):
is_a_cron_task = True
work_dir = "/tmp"
else:
work_dir = "."

for o, a in opts:
if o == "-v":
Expand All @@ -68,6 +76,8 @@ def usage():
outdir = re.sub(r'/*$', '', a)
elif o in ("-f"):
is_interactive = False
elif o in ("-F"):
is_forced = True
elif o in ("-y", "--year"):
year = int(a)
if year < ezm_start_year and (year > dt[0]):
Expand All @@ -78,7 +88,7 @@ def usage():
elif o in ("-m", "--month"):
mon = int(a)
if mon > 12 or (is_current_year and mon > dt[1]):
print "Invalid month:", year, "/*", mon, "*/", day
print "Invalid month:", year, "/*", mon
sys.exit(1)
if is_current_year and (mon == dt[1]):
is_current_month = True
Expand Down Expand Up @@ -112,12 +122,6 @@ def usage():
if DEBUG:
print "Default output directory:", outdir

#outdir = re.sub(r'/*$', '', sys.argv[1])
#year = int(sys.argv[2])
#mon = int(sys.argv[3])
#day = int(sys.argv[4])
#artwork = sys.argv[5]

artist = u"小飞 & 喻舟"
album = u"Easy Morning 飞鱼秀"

Expand All @@ -130,14 +134,23 @@ def usage():
day = "%02d" % day

fname = "%s_%s%s_info.html" % (year, mon, day)
fname = os.path.join(work_dir, fname);

info_url = u"%s/%s/%s/%s/" % (siteurl, year, mon, day)
if DEBUG:
print info_url
print info_url, fname

urllib.urlretrieve(info_url.encode("UTF-8"), fname)
if os.path.exists(fname):
if DEBUG:
print "proceed:", fname
soup = BeautifulSoup.BeautifulSoup(open(fname))
divs = soup.findAll("div", attrs={"class":"audio-content"})
if len(divs) < 1:
if not DEBUG and os.path.exists(fname):
os.unlink(fname)
if DEBUG:
print "content not found:", fname
for div in divs:
doit = False
if not div is None and not div.p is None:
Expand All @@ -148,8 +161,8 @@ def usage():
target = div.p.contents[0]
target = trim(target)
title = replace_html_code(target)
if DEBUG:
print title
#if DEBUG:
# print title
try:
m = re.search(r'\d+-(\d+)-(\d+)', title)
if DEBUG:
Expand Down Expand Up @@ -177,13 +190,17 @@ def usage():
os.unlink(fname)

outfile = "ezm_%s%s.mp3" % (mon, day)
if doit and not os.path.exists(("%s/%s") % (outdir, outfile)):
if os.path.exists(os.path.join(outdir, outfile)) and is_forced:
os.unlink(os.path.join(outdir, outfile))
if doit and (not os.path.exists(os.path.join(outdir, outfile))):
down_url = "%s/%s/ezm%s%s%s.mp3" % (mp3url, year, myear, mon, day)
if DEBUG:
print down_url
print down_url, os.path.join(outdir, outfile)

outfile = os.path.join(work_dir, outfile)
if doit:
print "Start: ", title
#print "Start: ", title, outfile
print "Start: ", outfile
urllib.urlretrieve(down_url, outfile)
if os.path.exists(outfile):
mp3 = eyed3.load(outfile)
Expand All @@ -197,11 +214,10 @@ def usage():
image = open(artwork, "rb").read()
mp3.tag.images.set(3, image, "image/jpeg")
mp3.tag.save()
shutil.move(outfile, ("%s/%s") % (outdir, outfile))
print "Done: ", title
elif DEBUG:
print "download link", down_url

shutil.move(outfile, outdir)
print "Done: ", os.path.join(outdir, outfile)
elif DEBUG:
print "download link", down_url, outfile
else:
print "Skip: %s%s%s" % (year, mon, day)
if os.path.exists(outfile):
Expand Down

0 comments on commit 30f025f

Please sign in to comment.