42 lines
1012 B
Python
42 lines
1012 B
Python
"""This module does render video"""
|
|
|
|
import sys
|
|
import json
|
|
import requests
|
|
|
|
URL = 'https://youtube-scrape.herokuapp.com'
|
|
INPUT = sys.argv[1]
|
|
SEARCH = '%s/api/search?q=%s' % (URL, INPUT)
|
|
REQUEST = requests.get(SEARCH)
|
|
FIRST = True
|
|
|
|
data = json.loads(REQUEST.content.decode('utf-8'))
|
|
items = data['results']
|
|
|
|
# with open('output.json', 'w') as json_file:
|
|
# json.dump(items, json_file)
|
|
|
|
for item in items:
|
|
try:
|
|
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:
|
|
FIRST = False
|
|
else:
|
|
print() # print skip line
|
|
|
|
# prints
|
|
print(' title: %s' % title)
|
|
print(' url: %s' % link)
|
|
print(' channel: %s' % author)
|
|
print(' uploaded: %s' % uploaded)
|
|
print(' time: %s' % time)
|
|
print(' views: %s' % views)
|