-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpyMSync.py
More file actions
61 lines (57 loc) · 2.58 KB
/
pyMSync.py
File metadata and controls
61 lines (57 loc) · 2.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/python
# -*- coding: utf-8 -*-
import os
import argparse
import functions as fun
# #############################################################################
# This script copies the files from an m3u playlist into a desired folder,
# along with a new m3u with relative path to the destination. It takes
# the playlist path, output folder (destination), and the base of the
# original library (absolute reference to be deleted from the path
# to make it a relative one).
# #############################################################################
# #############################################################################
# Setup the command line parsing
# #############################################################################
cmdPar = argparse.ArgumentParser(
prog='pyMSync',
description='Copies referenced files from an m3u to a destiny folder.',
epilog='http://chipdelmal.github.io/blog/'
)
# Positional arguments --------------------------------------------------------
cmdPar.add_argument('iPlst', type=str, help='Input playlist.')
cmdPar.add_argument('oFldr', type=str, help='Output folder.')
# Optional arguments ----------------------------------------------------------
cmdPar.add_argument(
'-lRt', '--libraryRoot', action='store',
help='Music library root (for absolute reference removal).'
)
cmdPar.add_argument(
'-o', '--overwrite', action='store_true',
help='Overwrites audio files if they are found in destiny location.'
)
cmdPar.add_argument(
'-l', '--log', action='store_true',
help='Creates a log at the destiny location with a summary of the run.'
)
cmdPar.add_argument(
'-v', '--verbose', action='store_true',
help='Prints the whole process to the terminal.'
)
# Parse arguments -------------------------------------------------------------
args = cmdPar.parse_args()
# #############################################################################
# Copy the playlist
# -----------------------------------------------------------------------------
# PLST: Input playlist file (absolute m3u)
# OPTH: Base output path
# LPTH: Base music library path (original path to be removed from the plst)
# #############################################################################
(PLST, OPTH, LPTH) = (args.iPlst, args.oFldr, args.libraryRoot)
# Original playlist is stored at the library root
if args.libraryRoot is None:
LPTH = os.path.split(PLST)[0]
fun.copyPlaylistToDir(
PLST, OPTH, LPTH,
overwrite=args.overwrite, log=args.log, verbose=args.verbose
)