aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesús <heckyel@hyperbola.info>2021-01-15 19:25:40 -0500
committerJesús <heckyel@hyperbola.info>2021-01-15 19:25:40 -0500
commit1dbd4a11e3a4f5a27ad7465caeff7ba8d274fa38 (patch)
treebc0cce84f8a995cf479fddd06cdc5cbaa2a1b2ca
parent938265700a2a9361dd78325e6c3143b20473df25 (diff)
downloadlivie-1dbd4a11e3a4f5a27ad7465caeff7ba8d274fa38.tar.lz
livie-1dbd4a11e3a4f5a27ad7465caeff7ba8d274fa38.tar.xz
livie-1dbd4a11e3a4f5a27ad7465caeff7ba8d274fa38.zip
Usage yt-local as scrapping
-rw-r--r--.gitignore1
-rw-r--r--README.md5
-rw-r--r--livie.el5
-rw-r--r--livie.py47
4 files changed, 27 insertions, 31 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..b81c795
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+*.xml \ No newline at end of file
diff --git a/README.md b/README.md
index ca14748..a8e2adf 100644
--- a/README.md
+++ b/README.md
@@ -10,9 +10,12 @@ Livie allows the user to search youtube.com and play the video from `mpv`.
- `python >= 3.5`
- `python-requests`
+- `python-beautifulsoup4`
+- `python-lxml`
+- `hypervideo`
- `mpv`
- `sudo pacman -S python mpv python-requests`
+ `sudo pacman -S python mpv python-requests python-beautifulsoup4 python-lxml hypervideo`
## Installation
diff --git a/livie.el b/livie.el
index ee3a261..226d3f7 100644
--- a/livie.el
+++ b/livie.el
@@ -47,10 +47,7 @@
:group 'livie
:type 'string)
-
-(defvar livie-youtube-regexp
- "https://\\<\\(invidious.snopyta.org\\|invidio.us\\)[df]?\\>/latest_version\\?id=[A-Za-z0-9_\\-]\\{11\\}&itag=\\<\\([0-9]*\\.[0-9]+\\|[0-9]+\\)[df]?\\>&local=true"
- )
+(defvar livie-youtube-regexp "https://www.youtube.com/watch\\?v=[A-Za-z0-9_\\-]\\{11\\}")
(define-derived-mode livie-mode
special-mode "livie"
diff --git a/livie.py b/livie.py
index b03d1c4..9f21ed3 100644
--- a/livie.py
+++ b/livie.py
@@ -1,34 +1,29 @@
"""This module does render video"""
import sys
-import datetime
-import json
import requests
+from bs4 import BeautifulSoup
-URL = 'https://invidio.us'
+URL = 'https://yt.conocimientoslibres.ga/youtube.com/'
INPUT = sys.argv[1]
-SEARCH = '%s/api/v1/search?q=%s' % (URL, INPUT)
+FILTER = '&type=1'
+SEARCH = '%ssearch?query=%s%s' % (URL, INPUT, FILTER)
REQUEST = requests.get(SEARCH)
-SD = '&itag=18&local=true'
-HD = '&itag=22&local=true'
+SOUP = BeautifulSoup(REQUEST.content, 'lxml', from_encoding=REQUEST.encoding)
+# skip line loop
+FIRST = True
-FIRST = True # skip line loop
+articles = SOUP.find_all('article', class_="item-box")
-VIDEOS = json.loads(REQUEST.content.decode('utf-8'))
-
-for video in VIDEOS:
+for article in articles:
try:
- title = video.get('title', '')
- videoid = video.get('videoId', '')
- author = video.get('author', '')
-
- # Make URL
- sd = '%s/latest_version?id=%s%s' % (URL, videoid, SD)
- hd = '%s/latest_version?id=%s%s' % (URL, videoid, HD)
+ title = article.h4.text
+ link = article.a['href'].replace('/', '', 1)
+ author = article.address.text
+ time = article.p.text
+ uploaded = article.span.text
+ views = article.find('div', class_="views").text
- timer = video.get('lengthSeconds', '')
- time = str(datetime.timedelta(seconds=timer))
- publish = video.get('publishedText', '')
except TypeError:
continue
@@ -38,9 +33,9 @@ for video in VIDEOS:
print() # print skip line
# prints
- print(' title: %s' % (title))
- print(' SD: %s' % (sd))
- print(' HD: %s' % (hd))
- print(' HD ^ Only some videos available caused by DRM')
- print(' channel: %s' % (author))
- print(' time: %s' % (time))
+ print(' title: %s' % title)
+ print(' url: %s' % link)
+ print(' channel: %s' % author)
+ print(' uploaded: %s' % uploaded)
+ print(' time: %s' % time)
+ print(' views: %s' % views)