aboutsummaryrefslogtreecommitdiffstats
path: root/livie.py
blob: 515ed12aeb4b8a9c4fb435cee693f4cecd7c1e1f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
"""This module does render video"""

import sys
import requests
from bs4 import BeautifulSoup

URL = 'https://yt.conocimientoslibres.ga/youtube.com/'
INPUT = sys.argv[1]
FILTER = '&type=1'
SEARCH = '%ssearch?query=%s%s' % (URL, INPUT, FILTER)
REQUEST = requests.get(SEARCH)
SOUP = BeautifulSoup(REQUEST.content, 'lxml', from_encoding=REQUEST.encoding)
# skip line loop
FIRST = True

articles = SOUP.find_all('article', class_="item-box")


def check(label):
    if label is None:
        data = 'Unknown'
    else:
        data = label.text
    return data


for article in articles:
    try:
        title = check(article.h4)
        link = article.a['href'].replace('/', '', 1)
        author = check(article.address)
        time = check(article.p)
        uploaded = check(article.span)
        views = check(article.find('div', class_="views"))

    except TypeError:
        continue

    if FIRST:
        FIRST = False
    else:
        print()  # print skip line

    # prints
    print('    title: %s' % title)
    print('      url: %s' % link)
    print('  channel: %s' % author)
    print(' uploaded: %s' % uploaded)
    print('     time: %s' % time)
    print('    views: %s' % views)