diff options
author | Jesús <heckyel@hyperbola.info> | 2019-05-15 21:58:02 -0500 |
---|---|---|
committer | Jesús <heckyel@hyperbola.info> | 2019-05-15 21:58:02 -0500 |
commit | 7e4a223d1c70cb5f32a5946ae125be4d42b3c79e (patch) | |
tree | 6faa936c87cbf2d763f8f38749ac87d2a9f0f9f2 /livie.py | |
download | livie-7e4a223d1c70cb5f32a5946ae125be4d42b3c79e.tar.lz livie-7e4a223d1c70cb5f32a5946ae125be4d42b3c79e.tar.xz livie-7e4a223d1c70cb5f32a5946ae125be4d42b3c79e.zip |
initial import
Diffstat (limited to 'livie.py')
-rw-r--r-- | livie.py | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/livie.py b/livie.py new file mode 100644 index 0000000..c9eacce --- /dev/null +++ b/livie.py @@ -0,0 +1,47 @@ +"""This module does render video""" + +import sys +import requests +from bs4 import BeautifulSoup + +BASE_URL = 'https://www.youtube.com' + +SEARCH_FILTER = '&sp=EgIQAQ%253D%253D' + +URL = BASE_URL + '/results?search_query=' + sys.argv[1] + SEARCH_FILTER + +HTML = requests.get(URL).text + +SOUP = BeautifulSoup(HTML, 'lxml') + +FIRST = True + +for vid in SOUP.find_all(class_='yt-lockup-content'): + try: + link = BASE_URL + vid.h3.a['href'] + title = vid.h3.a.text + description = vid.h3.span.text + author = vid.find(class_='yt-lockup-byline').a.text + meta = vid.find(class_='yt-lockup-meta').ul.contents + time = meta[0].text + views_str = meta[1].text[:-6] + views = int(views_str.replace(',', '')) + + except TypeError: + continue + + if FIRST: + FIRST = False + else: + print() + + print(f' title: {title}') + print(f' url: {link}') + print(f' channel: {author}') + print(f' uploaded: {time}') + print(f' views: {views_str}') + +# test +# f = open('output.xml','w') +# f.write(str(SOUP)) +# f.write(soup.encode('utf-8')) |