aboutsummaryrefslogtreecommitdiffstats
path: root/livie.py
blob: 50e36468eadd62572bfb397281397d2b2a408c25 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
"""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)