Spaces:
Sleeping
Sleeping
print("=====Google Drive 上的前10個文件=====")
Browse files
app.py
CHANGED
|
@@ -12,6 +12,30 @@ from moviepy.editor import VideoFileClip
|
|
| 12 |
from pytube import YouTube
|
| 13 |
import os
|
| 14 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
OUTPUT_PATH = 'videos'
|
| 16 |
|
| 17 |
|
|
|
|
| 12 |
from pytube import YouTube
|
| 13 |
import os
|
| 14 |
|
| 15 |
+
from google.oauth2 import service_account
|
| 16 |
+
from googleapiclient.discovery import build
|
| 17 |
+
|
| 18 |
+
# 假设您的环境变量或Secret的名称是GOOGLE_APPLICATION_CREDENTIALS_JSON
|
| 19 |
+
credentials_json_string = os.getenv("GOOGLE_APPLICATION_CREDENTIALS_JSON")
|
| 20 |
+
credentials_dict = json.loads(credentials_json_string)
|
| 21 |
+
SCOPES = ['https://www.googleapis.com/auth/drive']
|
| 22 |
+
credentials = service_account.Credentials.from_service_account_file(
|
| 23 |
+
credentials_dict, scopes=SCOPES)
|
| 24 |
+
service = build('drive', 'v3', credentials=credentials)
|
| 25 |
+
# 列出 Google Drive 上的前10個文件
|
| 26 |
+
results = service.files().list(pageSize=10, fields="nextPageToken, files(id, name)").execute()
|
| 27 |
+
items = results.get('files', [])
|
| 28 |
+
|
| 29 |
+
if not items:
|
| 30 |
+
print('No files found.')
|
| 31 |
+
else:
|
| 32 |
+
print("=====Google Drive 上的前10個文件=====")
|
| 33 |
+
print('Files:')
|
| 34 |
+
for item in items:
|
| 35 |
+
print(u'{0} ({1})'.format(item['name'], item['id']))
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
|
| 39 |
OUTPUT_PATH = 'videos'
|
| 40 |
|
| 41 |
|