Change API
This commit is contained in:
parent
5e8e05a8ed
commit
be65320ce6
1
.gitignore
vendored
1
.gitignore
vendored
@ -1 +1,2 @@
|
|||||||
*.xml
|
*.xml
|
||||||
|
*.json
|
||||||
|
@ -10,12 +10,10 @@ Livie allows the user to search youtube.com and play the video from `mpv`.
|
|||||||
|
|
||||||
- `python >= 3.5`
|
- `python >= 3.5`
|
||||||
- `python-requests`
|
- `python-requests`
|
||||||
- `python-beautifulsoup4`
|
- `hypervideo`
|
||||||
- `python-lxml`
|
|
||||||
- `hypervideo` or `youtube-dl`
|
|
||||||
- `mpv`
|
- `mpv`
|
||||||
|
|
||||||
`sudo pacman -S python mpv python-requests python-beautifulsoup4 python-lxml hypervideo`
|
`sudo pacman -S python mpv python-requests hypervideo`
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
|
39
livie.py
39
livie.py
@ -1,39 +1,30 @@
|
|||||||
"""This module does render video"""
|
"""This module does render video"""
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
|
import json
|
||||||
import requests
|
import requests
|
||||||
from bs4 import BeautifulSoup
|
|
||||||
|
|
||||||
URL = 'https://yt.conocimientoslibres.ga/youtube.com/'
|
URL = 'https://youtube-scrape.herokuapp.com'
|
||||||
INPUT = sys.argv[1]
|
INPUT = sys.argv[1]
|
||||||
FILTER = '&type=1'
|
SEARCH = '%s/api/search?q=%s' % (URL, INPUT)
|
||||||
SEARCH = '%ssearch?query=%s%s' % (URL, INPUT, FILTER)
|
|
||||||
REQUEST = requests.get(SEARCH)
|
REQUEST = requests.get(SEARCH)
|
||||||
SOUP = BeautifulSoup(REQUEST.content, 'lxml', from_encoding=REQUEST.encoding)
|
|
||||||
# skip line loop
|
|
||||||
FIRST = True
|
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):
|
for item in items:
|
||||||
if label is None:
|
|
||||||
data = 'Unknown'
|
|
||||||
else:
|
|
||||||
data = label.text
|
|
||||||
return data
|
|
||||||
|
|
||||||
|
|
||||||
for article in articles:
|
|
||||||
try:
|
try:
|
||||||
title = check(article.h4)
|
title = item['video']['title']
|
||||||
link = article.a['href'].replace('/', '', 1)
|
link = item['video']['url']
|
||||||
author = check(article.address)
|
author = item['uploader']['username']
|
||||||
time = check(article.p)
|
time = item['video']['duration']
|
||||||
uploaded = check(article.span)
|
uploaded = item['video']['upload_date']
|
||||||
views = check(article.find('div', class_="views"))
|
views = item['video']['views']
|
||||||
|
except KeyError:
|
||||||
except TypeError:
|
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if FIRST:
|
if FIRST:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user