Skip to main content

A python3 module to handle YouTube Community Tab

Project description

youtube_community_tab

Python3 interface to YouTube community tab, it handles posts, comments and comment replies.

Community Tab

from youtube_community_tab.community_tab import CommunityTab
import json


def indent_print(text, level=1):
    indent = level * "\t"
    print(indent + ("\n" + indent).join(text.split("\n")))


# Cache expiration
EXPIRATION_TIME = 1 * 60 * 60

ct = CommunityTab("vsauce1")

# Load initial posts
ct.load_posts(expire_after=EXPIRATION_TIME)

# Load more posts
while(ct.posts_continuation_token and len(ct.posts) < 40):
    ct.load_posts(expire_after=EXPIRATION_TIME)
  
post = ct.posts[0]
print(f"[Post {post.post_id}]")
indent_print(post.get_text())

print("\n[Thumbnails]")
print(json.dumps(post.get_thumbnails()[0], indent=4))

# Load initial comments
post.load_comments(expire_after=EXPIRATION_TIME)

# Load more comments
while(post.comments_continuation_token and len(post.comments) < 100):
    post.load_comments(expire_after=EXPIRATION_TIME)
  
comment = post.comments[1]
print(f"\n[Comment {comment.comment_id}]")
indent_print(comment.get_text())

# Load initial comment replies
comment.load_replies(expire_after=EXPIRATION_TIME)

# Load more comment replies
while(comment.replies_continuation_token and len(comment.replies) < 10):
    comment.load_replies(expire_after=EXPIRATION_TIME)
  
reply = comment.replies[0]
print(f"\n[Reply {reply.reply_id}]")
indent_print(reply.get_text())

Output:

[Post UgkxzeM19x_He9LEoerdLOHwZJsqIwamUnTj]
        THANK YOU!

        WE RAISED $20,180 for the Alzheimer's Association!!!
        The winner of this beautiful cube of my beard hairs will be announced November 15th!!

        As you all know, we also donate a portion of all proceeds from the Curiosity Box to Alzheimer's research; and there's never been a better time to do a favor for your brain and everyone else's:

        RIGHT NOW: subscribe with code "BEST" and I'll send you our newest box *and* throw in our BEST-OF BOX completely FREE!!!


        https://www.curiositybox.com

[Thumbnails]
[
    {
        "url": "https://yt3.ggpht.com/DJhBHUy1SyM2XpjC1ObZyrt8llJ-qG6svLapmaZgU-wmo5rVnWR93kJMrtz85XI9EKSt395Cvziu-JE=s288-c-fcrop64=1,1e6d0000e38bffff-nd-v1",
        "width": 288,
        "height": 288
    },
    {
        "url": "https://yt3.ggpht.com/DJhBHUy1SyM2XpjC1ObZyrt8llJ-qG6svLapmaZgU-wmo5rVnWR93kJMrtz85XI9EKSt395Cvziu-JE=s400-c-fcrop64=1,1e6d0000e38bffff-nd-v1",
        "width": 400,
        "height": 400
    },
    {
        "url": "https://yt3.ggpht.com/DJhBHUy1SyM2XpjC1ObZyrt8llJ-qG6svLapmaZgU-wmo5rVnWR93kJMrtz85XI9EKSt395Cvziu-JE=s462-c-fcrop64=1,1e6d0000e38bffff-nd-v1",
        "width": 462,
        "height": 462
    }
]

[Comment UgyTIomDXMuKf3NTo294AaABAg]
        Thank you for doing this. Both my grandparents are affected by alzheimer's disease. It is difficult to watch a highly creative woman and an electrical engineer fade away.

[Reply UgyTIomDXMuKf3NTo294AaABAg.9TtQ3j7qvll9TtqSmVNrJu]
        Hey a heart

Post

from youtube_community_tab.post import Post
import json


def indent_print(text, level=1):
    indent = level * "\t"
    print(indent + ("\n" + indent).join(text.split("\n")))


# Cache expiration
EXPIRATION_TIME = 1 * 60 * 60
  
post = Post.from_post_id("UgkxzeM19x_He9LEoerdLOHwZJsqIwamUnTj")
print(f"[Post {post.post_id}]")
indent_print(post.get_text())

print("\n[Thumbnails]")
print(json.dumps(post.get_thumbnails()[0], indent=4))

# Load initial comments
post.load_comments(expire_after=EXPIRATION_TIME)

# Load more comments
while(post.comments_continuation_token and len(post.comments) < 100):
    post.load_comments(expire_after=EXPIRATION_TIME)
  
comment = post.comments[1]
print(f"\n[Comment {comment.comment_id}]")
indent_print(comment.get_text())

# Load initial comment replies
comment.load_replies(expire_after=EXPIRATION_TIME)

# Load more comment replies
while(comment.replies_continuation_token and len(comment.replies) < 10):
    comment.load_replies(expire_after=EXPIRATION_TIME)
  
reply = comment.replies[0]
print(f"\n[Reply {reply.reply_id}]")
indent_print(reply.get_text())

Output:

[Post UgkxzeM19x_He9LEoerdLOHwZJsqIwamUnTj]
        THANK YOU!

        WE RAISED $20,180 for the Alzheimer's Association!!!
        The winner of this beautiful cube of my beard hairs will be announced November 15th!!

        As you all know, we also donate a portion of all proceeds from the Curiosity Box to Alzheimer's research; and there's never been a better time to do a favor for your brain and everyone else's:

        RIGHT NOW: subscribe with code "BEST" and I'll send you our newest box *and* throw in our BEST-OF BOX completely FREE!!!


        https://www.curiositybox.com

[Thumbnails]
[
    {
        "url": "https://yt3.ggpht.com/DJhBHUy1SyM2XpjC1ObZyrt8llJ-qG6svLapmaZgU-wmo5rVnWR93kJMrtz85XI9EKSt395Cvziu-JE=s288-c-fcrop64=1,1e6d0000e38bffff-nd-v1",
        "width": 288,
        "height": 288
    },
    {
        "url": "https://yt3.ggpht.com/DJhBHUy1SyM2XpjC1ObZyrt8llJ-qG6svLapmaZgU-wmo5rVnWR93kJMrtz85XI9EKSt395Cvziu-JE=s400-c-fcrop64=1,1e6d0000e38bffff-nd-v1",
        "width": 400,
        "height": 400
    },
    {
        "url": "https://yt3.ggpht.com/DJhBHUy1SyM2XpjC1ObZyrt8llJ-qG6svLapmaZgU-wmo5rVnWR93kJMrtz85XI9EKSt395Cvziu-JE=s462-c-fcrop64=1,1e6d0000e38bffff-nd-v1",
        "width": 462,
        "height": 462
    }
]

[Comment UgyTIomDXMuKf3NTo294AaABAg]
        Thank you for doing this. Both my grandparents are affected by alzheimer's disease. It is difficult to watch a highly creative woman and an electrical engineer fade away.

[Reply UgyTIomDXMuKf3NTo294AaABAg.9TtQ3j7qvll9TtqSmVNrJu]
        Hey a heart

Authentication/Membership

To access authenticated posts, like membership only posts, you need to provide cookies to authenticate your requests.

from http import cookiejar
from youtube_community_tab.requests_handler import requests_cache
from youtube_community_tab.community_tab import CommunityTab

cookie_jar = cookiejar.MozillaCookieJar("cookies.txt")
cookie_jar.load()
requests_cache.cookies = cookie_jar

ct = CommunityTab("UCMwGHR0BTZuLsmjY_NT5Pwg")
ct.load_posts()

membership_post = None
while ct.posts_continuation_token:
  for post in ct.posts:
    if post.sponsor_only_badge is not None:
      membership_post = post
      break

  if(membership_post is not None):
      break

  ct.load_posts(expire_after=EXPIRATION_TIME)

assert(membership_post is not None)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

youtube_community_tab-0.2.3.2.1.tar.gz (13.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

youtube_community_tab-0.2.3.2.1-py3-none-any.whl (15.9 kB view details)

Uploaded Python 3

File details

Details for the file youtube_community_tab-0.2.3.2.1.tar.gz.

File metadata

  • Download URL: youtube_community_tab-0.2.3.2.1.tar.gz
  • Upload date:
  • Size: 13.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/33.0 requests/2.22.0 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.61.1 importlib-metadata/4.11.2 keyring/18.0.1 rfc3986/1.4.0 colorama/0.4.3 CPython/3.8.10

File hashes

Hashes for youtube_community_tab-0.2.3.2.1.tar.gz
Algorithm Hash digest
SHA256 343c664b9f3b02814f695648ef59be17909c8cff777b2112f78919b73ffc39b4
MD5 967d127068749b5e3cb28dc30cc17849
BLAKE2b-256 971b890a5671d33a18cba302f2ca40e13566e037bcd7a229648333cf925af2a4

See more details on using hashes here.

File details

Details for the file youtube_community_tab-0.2.3.2.1-py3-none-any.whl.

File metadata

  • Download URL: youtube_community_tab-0.2.3.2.1-py3-none-any.whl
  • Upload date:
  • Size: 15.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/33.0 requests/2.22.0 requests-toolbelt/0.9.1 urllib3/1.26.9 tqdm/4.61.1 importlib-metadata/4.11.2 keyring/18.0.1 rfc3986/1.4.0 colorama/0.4.3 CPython/3.8.10

File hashes

Hashes for youtube_community_tab-0.2.3.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 ff3d8b56789adf2254ac8a9fdbf9f6c8dab35ecd5b78dba911a8d4fedeeac668
MD5 c9f35a37b1d4f6949877fbcf369a2b8c
BLAKE2b-256 c17da9a7a2a38e019329cef1691b0ac4650ad16649bdf41d8a749811e71e7ef2

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page