【问题标题】:Python youtube-upload opens file dialog boxPython youtube-upload 打开文件对话框
【发布时间】:2017-09-12 04:04:25
【问题描述】:

当我在我的 cmd 中键入 youtube-upload --title="The Chain ~ The Guardians Of The Galaxy Vol. 2" The_Chain.mp4 时,它会打开一个文件对话框。我已经正确安装了 youtube-upload。请帮忙

【问题讨论】:

    标签: python youtube-api


    【解决方案1】:

    您可以在此SO post 中关注answer。 一个

    :: == ASSUMPTIONS ==
    :: - this script is in the same directory as your CSV file
    :: - your CSV lines are in the following order:
    ::   file_name;title;description;category;tags;recording_date
    :: - Your descriptions do not contain semicolons
    @echo off
    
    set video_folder="C:\path\to\your\video\folder"
    
    :: If your videos and csv file are in the same directory, you don't need the pushd or popd
    :: Also, I couldn't get line continuation to work inside of the for loop, so everything
    :: MUST be all on the same line.
    pushd %video_folder%
    for /f "tokens=1-6 delims=;" %%A in (vids.csv) do (
        youtube-upload --title="%%~B" --description="%%~C" --category="%%~D" --tags="%%~E" --recording-date="%%~F" --default-language="en" --default-audio-language="en" --client-secrets=client-secrets.json --credentials-file=client_secrets.json "%%~A"
    )
    popd
    pause
    

    second answer 在您使用 python 时也很有用。

    一旦你开始接触 Python,你可能想研究一下YouTube API which can be accessed directly from Python

    首先,我会使用 youtube-upload 实际上可以 加载为 python 模块,而不是调用 subprocess 你 可以导入 youtube-upload 并调用 youtube-upload.main(commandline)。

    核心程序如下:

    import csv
    import subprocess
    
    def upload(csvfile):
        with open(csvfile') as f:
            for info in csv.DictReader(f):
                info.update({'client-secrets':'client_secrets.json', 'credentials-file':'client_secrets.json')
                subprocess.call(['youtube-upload'] + ['--{0}="{1}"'.format(k,v) for k,v in info.items()]}) 
    

    实用程序可能是这样的:

    #!python
    """
    Upload media files specified in a CSV file to YouTube using youtube-upload script.
    
    CSV File exported from Excel (i.e. commas properly quoted)
    First line contains upload parameters as column headers
    Subsequent lines contain per media file values for the corresponding options.
    e.g.
    file,description,category,tags...
    test.mp4,A.S. Mutter,A.S. Mutter plays Beethoven,Music,"mutter, beethoven"
    etc...
    
    """
    import csv
    import subprocess
    
    def upload(csvfile):
        with open(csvfile) as f:
            for info in csv.DictReader(f):
                info.update({'client-secrets':'client_secrets.json', 'credentials-file':'client_secrets.json'})
                commandline = ['youtube-upload'] + ['--{0}="{1}"'.format(k,v) for k,v in info.items()]
                #print commandline
                subprocess.call(commandline) 
    
    def main():
        import argparse
        p = argparse.ArgumentParser(description='youtube upload the media files specified in a CSV file')
        p.add_argument('-f', '--csvfile', default='vids.csv', 
            help='file path of CSV file containing list of media to upload')
        args = p.parse_args()
    
        upload(args.csvfile)
    
    if __name__ == '__main__':
        main()
    

    【讨论】:

      猜你喜欢
      • 2016-10-16
      • 2010-12-11
      • 1970-01-01
      • 2013-05-12
      • 2022-01-23
      • 2011-02-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多