Skip to content

Instantly share code, notes, and snippets.

@akamhy
Created October 11, 2021 05:33
Show Gist options
  • Save akamhy/12699fe91aaed699283593382ca78bd4 to your computer and use it in GitHub Desktop.
Save akamhy/12699fe91aaed699283593382ca78bd4 to your computer and use it in GitHub Desktop.
YouTube PlayList Duration from command-line
import re
import requests
def playlist_data(search_string):
end_point = "https://ytplaylist-len.herokuapp.com"
params = {"search_string": search_string.strip()}
text = requests.post(end_point, data=params).text
number_of_videos = (
re.search(r"<p>No of videos : ([0-9]*?)</p>", text).group(1).strip()
)
average_length_of_video = (
re.search(r"<p>Average length of video :(.*?)</p>", text).group(1).strip()
)
total_length_of_playlist = (
re.search(r"<p>Total length of playlist :(.*?)</p>", text).group(1).strip()
)
return (number_of_videos, average_length_of_video, total_length_of_playlist)
if __name__ == "__main__":
search_string = input("Enter Playlist Id : ").strip()
playlist_data(search_string)
number_of_videos, average_length_of_video, total_length_of_playlist = playlist_data(
search_string
)
print(" TOTAL VIDEOS : ", number_of_videos)
print(" AVERAGE DURATION : ", average_length_of_video)
print(" TOTAL DURATION : ", total_length_of_playlist)
@akamhy
Copy link
Author

akamhy commented Oct 11, 2021

alias plistdur="/home/akamhy/.pyenv/versions/3.9.1/bin/python /home/akamhy/projects/youtube_playlist_duration.py"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment