pinnwand

bpaste has migrated platforms. We now support self removal of pastes and will automatically import pastes from our old software for the following 2 months (that is, until the end of november 2014).

If you have any pastes you'd like to preserve please visit their URLs and they will be automatically imported with no expiry.

This paste never expires. Pasted by import. View raw.

  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
#!/usr/bin/env python

# Create a list of available downloads from Shepherds Chapel Website
# Converts .wmv to .wav with avconv subprocess
# Removes original .wav file

# Note:
# The archived .wmv files located at http://www.shepherdschapel.com/archive.htm
# Folder location is: http://www.shepherdschapel.com/media/sc/ + file.wmv
# Note there is only 1 file daily for 5 days excluding weekends
# However, files are on the server that are not shown on the site which can be retreived 

# To Do
# make progress bar for download
# make progress bar for avconv progress
# experiment with audiotools, but not sure how to use it with wmv or wma files

# easier to install packages that already have a module in them 
# rather then to manually install a module to python FYI
# you may need to install libav-tools from ubuntu software center
import Tkinter
import sys
import time
import datetime
import urllib
import os
from subprocess import call

# creates frame and title label
myGui = Tkinter.Tk()
myGui.geometry('400x400+500+300')
myGui.title('Shepherds Chapel')
mylabel = Tkinter.Label(text='Available Downloads')
mylabel.pack()

# creates listbox
List1 = Tkinter.Listbox(myGui)

# creates date variable and intializes other variables
now = datetime.date.today()
i = 0
filename = 0
url_name = 0
ret = 0
downloads = []

# update label on list selection
def update_label(e):
	update_text = "Downloading... " + str(List1.get(List1.curselection())) + "...Please Wait"
	Lb2.configure(text=update_text)
	Lb2.update()
	time.sleep(2)
	c_selection()
	
# create variables for call to avcon convert to .wav and remove original file	
def c_selection():
	filename = List1.get(List1.curselection())
	url_name = 'http://www.shepherdschapel.com/media/sc/' + filename
	urllib.urlretrieve (url_name, filename, reporthook=dlProgress)	

# convert selected file and remove downloaded original file
def a_avconv():
	filename = List1.get(List1.curselection())
	filename_2 = os.path.splitext(filename)[0] + ".flac" # deals with string exension removal and ads .wav
	#call(["avconv", "-i", filename, "-b", "128k", filename_2]) # .wmv to .wav conversion when list item is selected
	call(["avconv", "-i", filename, "-metadata", "title=", "-metadata", "artist=", "-metadata", "album=", "-metadata", "year=", "-b", "128k", filename_2])
	#-metadata key="value" --- example
	#-metadata title="my title" empty value to delete metadataleave empty to delete
	#-metadata options need to come before -b 128k

def a_remove():
	filename = List1.get(List1.curselection())
	os.remove(filename)
	
# ad available files to the download list (flawed for previous months -i)
for i in range(0,8):
	filename = "%s_%s_%s.wmv" % (now.month, now.day -i, now.year)
	url_name = 'http://www.shepherdschapel.com/media/sc/' + filename
	ret = urllib.urlopen(url_name)
	ret.close() # if I don't .close() app freezes
	if ret.code == 200:
		downloads.append(filename)
	

# my fix for previous months (-1), and (+30 -i) works but perhaps needs a better solution
if len(downloads) < 8:
	for i in range (0,16):
		filename = "%s_%s_%s.wmv" % (now.month -1, now.day + 30 -i, now.year)
		url_name = 'http://www.shepherdschapel.com/media/sc/' + filename
		ret = urllib.urlopen(url_name)
		ret.close()
		if ret.code == 200:
			downloads.append(filename)
			#downloads = list(set(downloads)) # removes duplicates unsorted	
		#elif ret.code != 200:
		#print "File ", filename," Does NOT Exist!", ret.code
		#print downloads

# download progress percent for urllib.retreive 3rd argument is reporthook
def dlProgress(count, blockSize, totalSize):
	percent = int(count*blockSize*100/totalSize)

	if percent >= 0: # while loop doesn't work here one seems to know why
		updated_text = "Downloading... " + str(List1.get(List1.curselection())) + "...." + str(percent) + "%"
		Lb2.configure(text= updated_text)
		Lb2.update()

		
	if percent == 100:
		updated_text = "Download Complete ...please wait"
		Lb2.configure(text= updated_text)
		Lb2.update()
		time.sleep(3)
		
		updated_text = "Converting File to (.flac) ...please wait"
		Lb2.configure(text= updated_text)
		Lb2.update()
		#time.sleep(3)
		a_avconv()
		
		updated_text = "Conversion Completed ...please wait"
		Lb2.configure(text= updated_text)
		Lb2.update()
		time.sleep(4)
		
		updated_text = "Deleting Original (.wmv) file ...please wait"
		Lb2.configure(text= updated_text)
		Lb2.update()
		a_remove()
		time.sleep(3)
		
		updated_text = "Process Complete"
		Lb2.configure(text= updated_text)
		Lb2.update()
		time.sleep(3)
		
		updated_text = "Please Select A Download"		
		Lb2.configure(text= updated_text)
		Lb2.update()		
		
# inserts list to lisbox
for list in downloads:
	List1.insert(Tkinter.END,list)
List1.pack()

List1.bind('<<ListboxSelect>>', update_label)

# creates second label
# label text updates include functions above: label_update and dlProgress
Lb2 = Tkinter.Label(myGui, text="Please Select Your Download")
Lb2.pack()


myGui.mainloop()