Esempio n. 1
0
def convert_youtube_json_to_bettertube_json(youtube_json):
    def duration_to_string(duration):
        if duration.hours == Decimal(0):
            return f"{duration.minutes}:{duration.seconds}"
        return f"{duration.hours}:{duration.minutes}:{duration.seconds}"

    return {
        "thumbnail":
        youtube_json["snippet"]["thumbnails"]["medium"]["url"],
        "caption":
        youtube_json["snippet"]["title"],
        "link":
        f"https://www.youtube.com/watch?v={youtube_json['id']}",
        "time":
        duration_to_string(
            parse_duration(youtube_json["contentDetails"]["duration"]).time),
        "timeposted":
        dateutil.parser.parse(
            youtube_json["snippet"]["publishedAt"]).strftime('%d %b %Y'),
        "creator":
        youtube_json["snippet"]["channelTitle"]
    }
Esempio n. 2
0
 def is_duration(instance):
     if not isinstance(instance, str):
         return True
     return isoduration.parse_duration(instance)
Esempio n. 3
0
 def is_duration(instance: object) -> bool:
     if not isinstance(instance, str):
         return True
     return bool(isoduration.parse_duration(instance))