Commit 44f145e4 authored by Jean-Marie Favreau's avatar Jean-Marie Favreau
Browse files

First example

parent 01a668c9
examples/config.py
__pycache__
include README.md
include requirements.txt
global-exclude .gitignore
......@@ -2,7 +2,8 @@
A python library to retrieve audio files from a sound library hosted by a webdav server (for example owncloud).
## Install
## Use the test example
* copy ```config.sample.py``` and rename it ```config.py```
* copy ```examples/config.sample.json``` and rename it ```examples/config.json```
* edit authentification information on this new file
* run the example to clone your audio directory
library
config.json
import sys
sys.path.insert(0,'..')
from webdav_audio_library.audio_library import AudioLibrary
import json
# Load config from file
f = open ('config.json', "r")
options = json.loads(f.read())
al = AudioLibrary(options)
al.get_audio_files_recursive("library")
{
"webdav_hostname": "https://example.com",
"webdav_login": "login",
"webdav_password": "password"
}
\ No newline at end of file
from webdav3.client import Client
import lxml.etree as etree
import os
class AudioLibrary:
def __init__(self, options):
self.client = Client(options)
self.audio_library = options["audio_library"]
self.mime_types = ["audio/mpeg"]
def list_audio_files_recursive(self, dir=None):
directory_url = self.audio_library if dir == None else dir
result = []
response = self.client.list(directory_url, get_info=True)
for e in response:
if e["isdir"]:
result += self.list_audio_files_recursive(e["path"])
else:
if e["content_type"] in self.mime_types:
result.append(e["path"].replace(self.audio_library, ""))
return result
def get_audio_files_recursive(self, local_directory):
files = self.list_audio_files_recursive()
os.makedirs(local_directory, exist_ok=True)
for f in files:
os.makedirs(os.path.dirname(local_directory + f), exist_ok=True)
print("Téléchargement de " + f)
self.client.download(self.audio_library + f, local_directory + f)
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment