Created
April 16, 2020 07:52
-
-
Save theshubhagrwl/e3f9b411bfe497cd479d31081607371d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This script will calculate the time needed to watch a youtube playlist. | |
# The only condition is that the playlist should be public | |
import requests | |
import html5lib | |
from bs4 import BeautifulSoup | |
str = input("Enter a link of a public youtube playlist: ") | |
URL = str | |
r = requests.get(URL) | |
soup = BeautifulSoup(r.content, 'html5lib') | |
time = soup.find_all('div', attrs={'class': 'timestamp'}) | |
i = 0 | |
j = 0 | |
k = 0 | |
hours = 0 | |
minutes = 0 | |
seconds = 0 | |
def min_and_sec(i, j): | |
global minutes, seconds | |
minutes = i + j//60 | |
seconds = j % 60 | |
hours = minutes // 60 | |
minutes = minutes % 60 | |
def hr_min_sec(i, j, k): | |
global minutes, seconds, hours | |
minutes = j + k//60 | |
seconds = k % 60 | |
hours = i + minutes//60 | |
minutes = minutes % 60 | |
for t in time: | |
n = t.get_text() | |
time_list = n.split(':') | |
list_length = len(time_list) | |
if list_length <= 2: | |
i = i + int(time_list[0]) | |
j = j + int(time_list[1]) | |
min_and_sec(i, j) | |
elif list_length > 2: | |
i = i + int(time_list[0]) | |
j = j + int(time_list[1]) | |
k = k + int(time_list[2]) | |
hr_min_sec(i, j, k) | |
print("This will take {} Hours {} Min and {} sec to complete".format( | |
hours, minutes, seconds)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment