Python の学習と理解を深める youtube-dl に基づいて、プレイリストをダウンロードし、すべての flv ビデオを特定のディレクトリに移動するスクリプトを作成したいと考えています。
これまでの私のコードは次のとおりです。
import shutil
import os
import sys
import subprocess
# Settings
root_folder = 'C:/Users/Robert/Videos/YouTube/Playlists/$s'
def download():
files = open('Playlists.txt').readlines()
for playlist in files:
p = playlist.split(';')
# Create the directory for the playlist if it does not exist yet
if not os.path.exists (root_folder % p[0]):
os.makedirs(root_folder % p[0])
# Download every single video from the given playlist
download_videos = subprocess.Popen([sys.executable, 'youtube-dl.py', ['-cit'], [p[1]]])
download_videos.wait()
# Move the video into the playlist folder once it is downloaded
shutil.move('*.flv', root_folder % p[0])
download()
Playlists.txt の構造は次のようになります。
Playlist name with spaces;http://www.youtube.com/playlist?list=PLBECF255AE8287C0F&feature=view_all
私は2つの問題に遭遇します。まず、文字列の書式設定が機能しません。
エラーが発生します:
Playlist name with spaces
Traceback (most recent call last):
File ".\downloader.py", line 27, in <module>
download()
File ".\downloader.py", line 16, in download
if not os.path.exists (root_folder % p[0]):
TypeError: not all arguments converted during string formatting
誰か私に理由を説明できますか?p[0] を印刷すると、すべて問題なく表示されます。
次に、ダウンロードしたばかりの flv ビデオのみを移動するように、適切な shutil.move コマンドを設定する方法がわかりません。どうすればそれをフィルタリングできますか?
ありがとうございました!