123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- import datetime
- import humanize
- import re
- def getHumanizedTimeString(seconds):
- return humanize.precisedelta(
- datetime.timedelta(seconds=seconds)).upper(). \
- replace(" month".upper(), "m.").replace(" months".upper(), "m.").replace(" days".upper(), "d.").replace(
- " day".upper(), "d.").replace(" hours".upper(), "hrs.").replace(" hour".upper(), "hr.").replace(
- " minutes".upper(), "mins.").replace(" minute".upper(), "min.").replace(
- "and".upper(), "").replace(" seconds".upper(), "secs.").replace(" second".upper(), "sec.").replace(",", "")
- def getVideoIdsStrings(video_ids):
- output = []
- i = 0
- while i < len(video_ids):
- output.append(",".join(video_ids[i:i + 50]))
- i += 50
- return output
- def calculateDuration(vid_durations):
- hours_pattern = re.compile(r'(\d+)H')
- minutes_pattern = re.compile(r'(\d+)M')
- seconds_pattern = re.compile(r'(\d+)S')
- total_seconds = 0
- for duration in vid_durations:
- hours = hours_pattern.search(duration)
- mins = minutes_pattern.search(duration)
- secs = seconds_pattern.search(duration)
- hours = int(hours.group(1)) if hours else 0
- mins = int(mins.group(1)) if mins else 0
- secs = int(secs.group(1)) if secs else 0
- video_seconds = datetime.timedelta(
- hours=hours,
- minutes=mins,
- seconds=secs
- ).total_seconds()
- total_seconds += video_seconds
- return total_seconds
- def getThumbnailURL(thumbnails):
- priority = ("maxres", "standard", "high", "medium", "default")
- for quality in priority:
- if quality in thumbnails:
- return thumbnails[quality]["url"]
- return ''
- def generateWatchingMessage(playlist):
- """
- This is the message that will be seen when a playlist is set to watching.
- Takes in the playlist object and calculates the watch time left by looping over unwatched video
- and using their durations
- """
- pass
|