Youtube Module - Printable Version

+- Sinisterly (
+-- Forum: Coding (
+--- Forum: Python (
+--- Thread: Youtube Module (/Thread-Youtube-Module)

Youtube Module - Stocking - 02-01-2014

I did not create this. I merely found it on the internet and cleaned it up a bit. I am also not a professional Python programmer so as far as the cleaning goes there may or may not be tiny errors.

Okay, so I found a Youtube module on the internets but it was a little unorganized. It was fine but needed some cleaning if you will. Probably my OCD talking. Here's my fix:

from urllib.request import urlopen
import re

class YoutubeException(Exception):

def tag_regex_construct(tag):
    return re.compile(r"<%s ?[^>]*>(.*?)</%s>" % (tag,tag), re.IGNORECASE | re.DOTALL )

title_re = tag_regex_construct("title")
desc_re  = tag_regex_construct("content")
auth_re  = tag_regex_construct("name")

class Video:
    def __init__(self,vid,update = True):
        self.vid = vid
        if(update): self.update()

    def update(self):
        resp = urlopen(self.get_api_link())
            data       =
            self.title =
                self.desc =
                self.desc = "No description available."
            self.auth  =
            raise YoutubeException("Video ID seems invalid.")

    def get_api_link(self):
        return "" % (self.vid)

    def get_id(self):
        return self.vid

    def get_title(self):
        return self.title

    def get_desc(self):
        return self.desc

    def get_auth(self):
        return self.auth

Duubz, the fuck is this shit used for?

I don't fucking know, maybe a bot. Intellect uses it. Jump off my dick.