Created
April 22, 2019 12:24
-
-
Save astrophysik928/91abcdc32159316f93061320fc190ac2 to your computer and use it in GitHub Desktop.
PythonでYouTubeの音楽を複数ダウンロード
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
from pytube import YouTube | |
import openpyxl as px | |
import sys | |
import xlwings as xw | |
youtube_url_list = [] | |
url_list = xw.Book('youtube_url.xlsm') | |
#YouTubeをダウンロード | |
def download_youtube(url, output_path): | |
yt = YouTube(url) | |
# get_by_itagとdownloadでダウンロード | |
yt.streams.get_by_itag(140).download(output_path) | |
#エクセルに記載されたYouTubeのURL取得 | |
def get_youtube_url(cell_address): | |
get_youtube_url = xw.Range(cell_address).value | |
return get_youtube_url | |
#YouTubeのダウンロード先のパス取得 | |
def get_output_path(): | |
get_output_path = xw.Range('B3').value | |
return get_output_path | |
if __name__ == '__main__': | |
print("start!!") | |
count = 3 | |
#エクセルに記載されたYouTubeのURLをリストに格納 | |
while count: | |
cell_address = "A" + str(count) | |
#URLがないセルに到達するとループを抜ける | |
if xw.Range(cell_address).value == None: | |
break | |
#URLをリストに追加 | |
youtube_url_list.append(get_youtube_url(cell_address)) | |
print(youtube_url_list) | |
count += 1 | |
print("/////////") | |
print("Download started!!") | |
print("/////////") | |
#リストに格納したYouTubeのURLを取り出し、ダウンロードする | |
for each_youtube_url in youtube_url_list: | |
download_youtube(each_youtube_url, get_output_path()) | |
print("Downloading is completed!!") | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment