pythonでFlaskを利用しpytubeで動画をダウンロードするのをサイト上でやりたく
以下のコードを実行したところ
python
1from flask import Flask, render_template 2from pytube import YouTube 3from flask import request 4 5app = Flask(__name__) 6 7@app.route('/',methods =['POST','GET']) 8def hello(): 9 html = render_template('index.html') 10 return html 11 12@app.route("/send",methods=['POST']) 13def result(): 14 get_value = request.form.getlist("URL") 15 16 yt = YouTube(get_value) 17 18 yt.streams.get_by_itag(137).download(r'c:\test') 19 20 return "ok" 21 22if __name__ == "__main__": 23 app.run() 24
html
1<!doctype html> 2<title>サンプル</title> 3<head> 4 <title></title> 5 <script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" 6 integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" 7 crossorigin="anonymous"></script> 8 <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" 9 integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" 10 crossorigin="anonymous"></script> 11 <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" 12 integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" 13 crossorigin="anonymous"></script> 14 <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" 15 integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous"> 16 <link rel="stylesheet" type=text/css href="{{ url_for('static', filename='style.css') }}"> 17 <meta http-equiv="X-UA-Compatible" content="IE=edge"> 18 19 <meta charset="UTF-8"> 20 <meta http-equiv="Pragma" content="no-cache"> 21 <meta http-equiv="Cache-Control" content="no-cache"> 22 <meta http-equiv="Expires" content="-1"> 23 <meta name="viewport" content="width=device-width"> 24 25</head> 26 27<body> 28 <header> 29 <div class="navbar navbar-dark bg-dark box-shadow"> 30 <div class="container d-flex justify-content-between"> 31 <a href="/" class="navbar-brand d-flex align-items-center"> 32 <strong>Youtube Downloader</strong> 33 </a> 34 </div> 35 </div> 36 </header> 37 <div id="container" class="container theme-showcase"> 38 <div class="page-title jumbotron"> 39 <h1>Please Enter the link of the video you want to Download!</h1> 40 <style type="text/css"> 41 h1 { 42 position: relative; 43 padding-bottom: 0.5em; 44 border-bottom: 4px solid #DDD; 45} 46 47h1::after { 48 position: absolute; 49 content: " "; 50 border-bottom: solid 4px #446689; 51 bottom: -4px; 52 width:10%; 53 display: block; 54} 55</style> 56 <form id="search" class="search-form corner-all search"action="/send" method="POST"> 57 <div class="search search-form-content"> 58 <input type="text" id="keyword" class="corner-all form-control search-keyword" placeholder="URL"name="URL"/> 59 </div> 60 61 <div class="search-form-content"> 62 <form action ="/send" method="POST"> 63 <input type="submit" class="corner-all btn btn-info" value="Download"/> 64 </form> 65 </div> 66 </form> 67 <div class="alert"> 68 <span>WARNING</span> 69 We respect the intellectual property rights of others. You may not infringe the copyright, trademark or other proprietary informational rights of any party. <br> 70</div> 71<style type="text/css"> 72 /* エラー用 */ 73 div.alert { 74 background-color:#FFEFEF; 75 margin:0 0 1em 0; padding:10px; 76 color:#C25338; 77 border:1px solid #D4440D; 78 line-height:1.5; 79 clear:both; 80 background-repeat:no-repeat; 81 background-position:5px 5px; 82 }</style> 83 84</body> 85<div class="urlconverter-section-2"> 86 <div class="container"> 87 <div class="row"> 88 <div class="col-sm-12"> 89 <div class="title"> 90 <h2>YouTubeからMP4への変換ツールNo.1!</h2> 91 <span class="title-border"></span> 92 </div> 93 <p>YouTube動画をMP4動画として、HDの画質でダウンロード&保存できるようになりました。弊社自慢のYouTubeからMP4への変換ツールは、様々なオンライン動画サイトに対応していきます。</p> 94 </div> 95 </div> 96 </div> 97 </div> 98 99 100 101 <div class="urlconverter-section-3"> 102 <div class="container"> 103 <div class="row"> 104 <div class="col-sm-6 col-xs-6 col-xxs-12"> 105 <div class="urlconverter-section-3-left"> 106 <div class="title"> 107 <h3>操作方法</h3> 108 <span class="title-border"></span> 109 </div> 110 <ol> 111 <li>変換したい動画のリンクをコピーして貼り付けます。</li> 112 <li>"Download" ボタンをクリックして、変換処理を開始します。</li> 113 </ol> 114 </div> 115 </div> 116 <div class="col-sm-6 col-xs-6 col-xxs-12"> 117 <div class="urlconverter-section-3-right"> 118 <div class="title"> 119 <h3>特長</h3> 120 <span class="title-border"></span> 121 </div> 122 <ul> 123 <li><span class="arrow"></span>最新のウェブブラウザにも完全対応</li> 124 <li><span class="arrow"></span>超スピード変換</li> 125 <li><span class="arrow"></span>登録不要</li> 126 <li><span class="arrow"></span>変換、ダウンロードする回数に制限なし</li> 127 <li><span class="arrow"></span>ソフトウェアのダウンロードやインストールは不要</li> 128 </ul> 129 </div> 130 </div> 131 </div> 132 </div> 133 </div> 134
サイト上では
[Internal Server Error
The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there is an error in the application.]
コマンドプロンプトでは
[ return self.view_functionsrule.endpoint
File "run.py", line 16, in result
yt = YouTube(request.form/getlist("URL"))
NameError: name 'getlist' is not defined]
といったエラーが出てしまいます。
初心者なので蛇足なコードも多いと思いますが、
pytubeを利用しサイト上でダウンロード処理をする方法をご教授ください。
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。