Skip to content

Commit e91aa55

Browse files
committed
organizing scripts again after a while
1 parent d657338 commit e91aa55

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

youtube/YTDownloadProgressBadge.py

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# coding: utf-8
2+
3+
# https://forum.omz-software.com/topic/2574/progress-tracker-on-app-badge/2
4+
5+
import requests,bs4,urllib2
6+
import ProgressBadge as pb
7+
8+
#Gets the raw video url for the video using the keepvid service.
9+
vidurl='https://www.youtube.com/watch?v=fzievdlaVIU'
10+
url='http://www.keepvid.com/?url={}'.format(vidurl)
11+
soup = bs4.BeautifulSoup(urllib2.urlopen(url).read())
12+
link=[l.get('href') for l in soup.select('a') if l.get('href') and 'googlevideo.com' in l.get('href')][0]
13+
14+
#Holds the progress bar
15+
c=pb.Container()
16+
try:
17+
with open('vid.mp4', "wb") as f:
18+
response = requests.get(link, stream=True)
19+
#Total length of the video
20+
total_length = response.headers.get('content-length')
21+
#The length of the video is the "top value" for our task
22+
task=pb.Progress(int(total_length))
23+
#Add this task to the container.
24+
c.add(task)
25+
#Update the task as we download and write the video
26+
for data in response.iter_content():
27+
f.write(data)
28+
task.increment(len(data))
29+
c.update()
30+
except:
31+
#Clean up, which means take away the badge from the app.
32+
task.finish()
33+
raise
34+
#clean up
35+
task.finish()

0 commit comments

Comments
 (0)