コード例 #1
0
def is_video_url(url):
    """
    If the URL represents a video file, this function returns True.

    1) It checks the extension to see if it's in VIDEO_EXTENSIONS
    2) It performs an HTTP HEAD request and checks the MIME type with
       is_accepted_type()
    """
    if is_accepted_filename(url):
        return True

    parsed = urlparse.urlparse(url)
    if parsed.scheme == 'http':
        conn = httplib.HTTPConnection(parsed.netloc)
    elif parsed.scheme == 'https':
        conn = httplib.HTTPSConnection(parsed.netloc)
    else:
        return False

    try:
        conn.request('HEAD', parsed.path)
    except IOError:
        # can't connect to the server.
        return False

    response = conn.getresponse()

    mimetype = response.getheader('Content-Type', '')
    return is_accepted_type(mimetype)
コード例 #2
0
ファイル: utils.py プロジェクト: bluezone/mirocommunity
def is_video_url(url):
    """
    If the URL represents a video file, this function returns True.

    1) It checks the extension to see if it's in VIDEO_EXTENSIONS
    2) It performs an HTTP HEAD request and checks the MIME type with
       is_accepted_type()
    """
    if is_accepted_filename(url):
        return True

    parsed = urlparse.urlparse(url)
    if parsed.scheme == 'http':
        conn = httplib.HTTPConnection(parsed.netloc)
    elif parsed.scheme == 'https':
        conn = httplib.HTTPSConnection(parsed.netloc)
    else:
        return False

    try:
        conn.request('HEAD', parsed.path)
    except IOError:
        # can't connect to the server.
        return False

    response = conn.getresponse()

    mimetype = response.getheader('Content-Type', '')
    return is_accepted_type(mimetype)
コード例 #3
0
ファイル: feedparser.py プロジェクト: msabramo/vidscraper
def get_first_accepted_enclosure(entry):
    """
    Returns the first accepted enclosure in a feedparser entry, or ``None`` if
    no such enclosure is found. An enclosure is accepted if it contains a file
    which passes the :func:`.is_accepted_filename` or :func:`.is_accepted_type`
    checks.

    """
    enclosures = get_entry_enclosures(entry)
    if not enclosures:
        return None
    best_enclosure = None
    for enclosure in enclosures:
        if (is_accepted_type(enclosure.get('type', '')) or
                is_accepted_filename(enclosure.get('url', ''))):
            if enclosure.get('isdefault'):
                return enclosure
            elif best_enclosure is None:
                best_enclosure = enclosure
    return best_enclosure
コード例 #4
0
ファイル: utils.py プロジェクト: jdragojevic/mirocommunity-1
def is_video_url(url):
    """
    If the URL represents a video file, this function returns True.

    1) It checks the extension to see if it's in VIDEO_EXTENSIONS
    2) It performs an HTTP HEAD request and checks the MIME type with
       is_accepted_type()
    """
    if is_accepted_filename(url):
        return True

    parsed = urlparse.urlparse(url)
    if parsed.scheme == "http":
        conn = httplib.HTTPConnection(parsed.netloc)
    elif parsed.scheme == "https":
        conn = httplib.HTTPSConnection(parsed.netloc)
    else:
        return False
    conn.request("HEAD", parsed.path)
    response = conn.getresponse()

    mimetype = response.getheader("Content-Type", "")
    return is_accepted_type(mimetype)
コード例 #5
0
def _is_accepted_enclosure(enclosure):
    return (is_accepted_type(enclosure.get('type', '')) or
            is_accepted_filename(enclosure.get('url', '')))