-
Notifications
You must be signed in to change notification settings - Fork 2
/
app.py
106 lines (67 loc) · 2.3 KB
/
app.py
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import os
from apiclient.discovery import build
from apiclient.errors import HttpError
from oauth2client.tools import argparser
from textblob import TextBlob
import sys
import os
import urllib
from flask import Flask
from flask import render_template
app = Flask(__name__)
#-------------------------------------------------------------------------------
#@app.route('/')
#def hello():
# return "Hello World"
API_KEY = "AIzaSyBdDDnfLMXZ_z43CYWiDpuDteqOiNiHNa8"
YOUTUBE_API_SERVICE_NAME = "youtube"
YOUTUBE_API_VERSION = "v3"
QUERY_TERM = "young princess" ### Search youtube for these ..... and create a playlist
videos_links = []
@app.route('/')
@app.route('/index')
def index():
return render_template('pages/index.html')
@app.route('/tell_me_about_your_movie')
def tell_me_about_your_movie():
return render_template('pages/tell_me_about_your_movie.html')
@app.route('/stanley_is_working')
def stanley_is_working():
return render_template('pages/stanley_is_working.html')
@app.route('/your_trailer')
def your_trailer():
return render_template('pages/your_trailer.html')
###################### ----------------------------------------------########################
def search_by_keyword( input_text):
input_blob = TextBlob (input_text)
search_terms = input_blob.noun_phrases
youtube = build(
YOUTUBE_API_SERVICE_NAME,
YOUTUBE_API_VERSION,
developerKey=API_KEY
)
videos = []
for line in search_terms:
print line
search_response = youtube.search().list(
q=line,
part="id,snippet",
maxResults=10
).execute()
link= "https://www.youtube.com/watch?v="
for search_result in search_response.get("items", []):
if search_result["id"]["kind"] == "youtube#video":
full_link = link+search_result["id"]["videoId"]
videos.append(full_link)
return videos
def download_videos(videos):
#videos = search_by_keyword()
cmd = """ youtube-dl --get-filename -o "%(title)s.%(ext)s" """
for v in videos:
cmd = cmd + v
print cmd
os.system(cmd)
#-------------------------------------------------------------------------------
port = os.getenv('VCAP_APP_PORT', '5000')
if __name__ == "__main__":
app.run(host='0.0.0.0', port=int(port))