livie/livie.py
2021-01-15 20:33:16 -05:00

51 lines
1.2 KiB
Python

"""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)