Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 7091d61

Browse files
implemented progress bar
1 parent 39cc121 commit 7091d61

File tree

2 files changed

+58
-22
lines changed

2 files changed

+58
-22
lines changed

‎Linkedin_Video_Downloader/script.py

Lines changed: 58 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,22 @@
33
import tkinter as tk
44
import requests as req
55
import html
6+
import time
7+
from tkinter.ttk import *
8+
from threading import Thread
9+
import queue
10+
from queue import Empty
611

712

813
def Invalid_Url():
914
""" Sets Status bar label to error message """
10-
Download_Window.insert(tk.END,f"Invalid URL")
1115
Status["text"] = "Invalid URL..."
1216
Status["fg"] = "red"
1317

1418

1519
def Download_vid():
1620

1721
# Validates Link and download Video
18-
Download_Window.delete("0.0", "end")
1922
global Url_Val
2023
url=Url_Val.get()
2124

@@ -44,38 +47,72 @@ def Download_vid():
4447
if "dms.licdn.com" in source:
4548

4649
videourl = source.split(',')[0].split('"src":')[1][1:-1]
50+
start_downloading()
4751

48-
r = req.get(videourl, stream=True)
52+
download_thread=VideoDownload(videourl)
53+
download_thread.start()
54+
monitor(download_thread)
55+
break
4956

50-
total_size = int(r.headers.get('content-length', 0))
5157

52-
block_size = 1024
58+
class VideoDownload(Thread):
59+
60+
def __init__(self, url):
61+
super().__init__()
5362

54-
with open('video.mp4', 'wb') as file:
55-
totaldata=0;
56-
for data in r.iter_content(block_size):
57-
totaldata+=len(data)
58-
per_downloaded=totaldata*100/total_size
59-
Download_Window.delete("1.0","end")
60-
Download_Window.insert(tk.END,f"Dowloaded.... {per_downloaded}%")
61-
file.write(data)
62-
print("Download Finished")
63-
break
63+
self.url = url
64+
65+
def run(self):
66+
""" download video"""
67+
68+
# save the picture to a file
69+
block_size = 1024 # 1kB
70+
r = req.get(self.url, stream=True)
71+
total_size = int(r.headers.get("content-length"))
72+
73+
with open('video.mp4', 'wb') as file:
74+
totaldata=0;
75+
for data in r.iter_content(block_size):
76+
totaldata+=len(data)
77+
per_downloaded=totaldata*100/total_size
78+
queue.put(per_downloaded)
79+
bar['value'] = per_downloaded
80+
file.write(data)
81+
time.sleep(0.01)
82+
file.close()
83+
print("Download Finished")
6484

65-
Status["text"] = "Finished!!"
66-
Status["fg"] = "green"
85+
print("Download Complete !!!")
86+
Status["text"] = "Finished!!"
87+
Status["fg"] = "green"
6788

6889

90+
#start download
91+
def start_downloading():
92+
bar["value"]=0;
93+
94+
def monitor( download_thread):
95+
""" Monitor the download thread """
96+
if download_thread.is_alive():
97+
98+
try:
99+
bar["value"]=queue.get(0)
100+
ld_window.after(10, lambda: monitor(download_thread))
101+
except Empty:
102+
pass
103+
69104
# GUI
70105

71106
ld_window=tk.Tk()
72107
ld_window.title("Linkedin Video Downloader")
73-
ld_window.geometry("400x400")
108+
ld_window.geometry("400x300")
74109

75110
# Label for URL Input
76111
input_label= tk.Label(ld_window,text="Enter Linkedin Video URL:")
77112
input_label.pack()
78113

114+
queue=queue.Queue()
115+
79116
# Input of URL
80117
Url_Val = tk.StringVar()
81118
Url_Input = tk.Entry(ld_window, textvariable=Url_Val, font=("Calibri", 9))
@@ -85,11 +122,10 @@ def Download_vid():
85122
Download_button = tk.Button(ld_window, text="Download", font=("Calibri", 9), command=Download_vid)
86123
Download_button.place(x=100, y=100, width=200)
87124

88-
# Download Window
125+
# Progress Bar
126+
bar = Progressbar(ld_window, length=350, style='grey.Horizontal.TProgressbar',mode='determinate')
127+
bar.place(y=200,width=350,x=25)
89128

90-
Download_Window = tk.Text(ld_window, font=("Calibri", 9), bg="black", fg="white", bd=1, relief=tk.SUNKEN, wrap=tk.WORD)
91-
Download_Window.insert(tk.END, "Welcome to Linkedin Video Downloader, Provide a Linkedin post link in the above box and click download to start the process. :D")
92-
Download_Window.place(x=25, y=200, width=350, height=250)
93129

94130
# Text for Status of Downloading
95131
Status = tk.Label(ld_window, text="Hello!! :D", fg="blue", font=("Calibri", 9), bd=1, relief=tk.SUNKEN, anchor=tk.W, padx=3)

‎Linkedin_Video_Downloader/video.mp4

409 KB
Binary file not shown.

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /