aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesús <heckyel@hyperbola.info>2021-01-16 18:00:52 -0500
committerJesús <heckyel@hyperbola.info>2021-01-16 18:00:52 -0500
commitbe65320ce695a59d427e56f261c4af2c3170a65f (patch)
tree03327d98dd8f6933e52df77184857f54f042f6b7
parent5e8e05a8ed8e05e77b3c3443b7f4c4a6a06c8b99 (diff)
downloadlivie-be65320ce695a59d427e56f261c4af2c3170a65f.tar.lz
livie-be65320ce695a59d427e56f261c4af2c3170a65f.tar.xz
livie-be65320ce695a59d427e56f261c4af2c3170a65f.zip
Change API
-rw-r--r--.gitignore3
-rw-r--r--README.md6
-rw-r--r--livie.py39
3 files changed, 19 insertions, 29 deletions
diff --git a/.gitignore b/.gitignore
index b81c795..67c51fe 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1 +1,2 @@
-*.xml \ No newline at end of file
+*.xml
+*.json
diff --git a/README.md b/README.md
index a4e2b30..62928e0 100644
--- a/README.md
+++ b/README.md
@@ -10,12 +10,10 @@ Livie allows the user to search youtube.com and play the video from `mpv`.
- `python >= 3.5`
- `python-requests`
-- `python-beautifulsoup4`
-- `python-lxml`
-- `hypervideo` or `youtube-dl`
+- `hypervideo`
- `mpv`
- `sudo pacman -S python mpv python-requests python-beautifulsoup4 python-lxml hypervideo`
+ `sudo pacman -S python mpv python-requests hypervideo`
## Installation
diff --git a/livie.py b/livie.py
index 515ed12..50e3646 100644
--- a/livie.py
+++ b/livie.py
@@ -1,39 +1,30 @@
"""This module does render video"""
import sys
+import json
import requests
-from bs4 import BeautifulSoup
-URL = 'https://yt.conocimientoslibres.ga/youtube.com/'
+URL = 'https://youtube-scrape.herokuapp.com'
INPUT = sys.argv[1]
-FILTER = '&type=1'
-SEARCH = '%ssearch?query=%s%s' % (URL, INPUT, FILTER)
+SEARCH = '%s/api/search?q=%s' % (URL, INPUT)
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")
+data = json.loads(REQUEST.content.decode('utf-8'))
+items = data['results']
+# with open('output.json', 'w') as json_file:
+# json.dump(items, json_file)
-def check(label):
- if label is None:
- data = 'Unknown'
- else:
- data = label.text
- return data
-
-
-for article in articles:
+for item in items:
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:
+ title = item['video']['title']
+ link = item['video']['url']
+ author = item['uploader']['username']
+ time = item['video']['duration']
+ uploaded = item['video']['upload_date']
+ views = item['video']['views']
+ except KeyError:
continue
if FIRST: