Files
middle-server/plugin/NavidromePlaylistSync/sync.py
mol 8ff9869399
All checks were successful
continuous-integration/drone/push Build is passing
test
2023-11-16 15:51:09 +08:00

30 lines
945 B
Python

import os
from webdav3.client import Client
from webdav3.exceptions import LocalResourceNotFound, RemoteResourceNotFound, ResponseErrorCode
def sync():
options = {
'webdav_hostname': 'https://pan.liliyamol.cn:8081/webdav/',
'webdav_login': 'fan@yunying.com',
'webdav_password': 'm%Bn$w5jgiNsNC',
'disable_check': True,
}
client = Client(options)
tempPath = os.path.join(os.path.dirname(__file__), 'temp')
playlists = os.listdir(tempPath)
try:
client.clean('Music/#playlist')
except RemoteResourceNotFound as exception:
print('clean failed!')
except ResponseErrorCode as exception:
print('error')
for fileName in playlists:
path = os.path.join(tempPath, fileName)
try:
client.upload('Music/#playlist/' + fileName, path)
print(fileName + ' upload success!!')
except LocalResourceNotFound as exception:
print(fileName + ' upload failed!!')