Revert "Use BeautifulSoup to extract information from YT searches"

This reverts commit 8dbd0685240518f255603d3d86ac07e20460b862.

(closes #7)
This commit is contained in:
Jesús 2020-07-17 16:52:56 -05:00
parent cc0df81f19
commit 938265700a
No known key found for this signature in database
GPG Key ID: F6EE7BC59A315766
3 changed files with 30 additions and 35 deletions

View File

@ -10,12 +10,9 @@ 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`
- `python-lxml`
- `hypervideo`
- `mpv` - `mpv`
`sudo pacman -S python mpv python-requests python-beautifulsoup4 python-lxml hypervideo` `sudo pacman -S python mpv python-requests`
## Installation ## Installation

View File

@ -47,7 +47,10 @@
:group 'livie :group 'livie
:type 'string) :type 'string)
(defvar livie-youtube-regexp "https://invidio.us/watch\\?v=[A-Za-z0-9_\\-]\\{11\\}")
(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"
)
(define-derived-mode livie-mode (define-derived-mode livie-mode
special-mode "livie" special-mode "livie"

View File

@ -1,39 +1,34 @@
"""This module does render video""" """This module does render video"""
import sys import sys
import datetime
import json
import requests import requests
from bs4 import BeautifulSoup
URL = 'https://www.youtube.com' URL = 'https://invidio.us'
FILTER = '&sp=EgIQAQ%253D%253D'
INPUT = sys.argv[1] INPUT = sys.argv[1]
SEARCH = '%s/results?search_query=%s%s' % (URL, INPUT, FILTER) SEARCH = '%s/api/v1/search?q=%s' % (URL, INPUT)
REQUEST = requests.get(SEARCH) REQUEST = requests.get(SEARCH)
SOUP = BeautifulSoup(REQUEST.content, 'lxml', from_encoding=REQUEST.encoding) SD = '&itag=18&local=true'
FIRST = True HD = '&itag=22&local=true'
FIRST = True # skip line loop
def replace(string): VIDEOS = json.loads(REQUEST.content.decode('utf-8'))
"""Remove unnecessary characters"""
string = string.replace(' - Duration: ', '')
string = string.replace('.', '')
string = string.replace(' views', '')
return string
for video in VIDEOS:
for vid in SOUP.find_all(class_='yt-lockup-content'):
try: try:
link = 'https://invidio.us%s' % vid.h3.a['href'] title = video.get('title', '')
title = vid.h3.a.text videoid = video.get('videoId', '')
description = vid.h3.span.text author = video.get('author', '')
author = vid.find(class_='yt-lockup-byline').a.text
meta = vid.find(class_='yt-lockup-meta').ul.contents
time_srt = vid.find(class_='yt-lockup-title').span.text
time = replace(time_srt)
uploaded = meta[0].text
views_str = vid.find(class_='yt-lockup-meta').ul.li.find_next()
views = replace(views_str.text)
# Make URL
sd = '%s/latest_version?id=%s%s' % (URL, videoid, SD)
hd = '%s/latest_version?id=%s%s' % (URL, videoid, HD)
timer = video.get('lengthSeconds', '')
time = str(datetime.timedelta(seconds=timer))
publish = video.get('publishedText', '')
except TypeError: except TypeError:
continue continue
@ -43,9 +38,9 @@ for vid in SOUP.find_all(class_='yt-lockup-content'):
print() # print skip line print() # print skip line
# prints # prints
print(' title: %s' % title) print(' title: %s' % (title))
print(' url: %s' % link) print(' SD: %s' % (sd))
print(' channel: %s' % author) print(' HD: %s' % (hd))
print(' uploaded: %s' % uploaded) print(' HD ^ Only some videos available caused by DRM')
print(' time: %s' % time) print(' channel: %s' % (author))
print(' views: %s' % views) print(' time: %s' % (time))