aboutsummaryrefslogtreecommitdiff
path: root/sync.py
blob: 4272340fc0d39ac999f3672c08164cabe6ca7797 (plain)
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
import os
import shutil
import sys

playlist = sys.argv[1]
playlistpath = playlist[:playlist.rfind('/')]

synced = set()
for i in open(playlist).read().split('\n'):
    target = i[i.rfind('/') + 1:i.rfind('.')] + '.mp3'
    synced.add(target)
    if i == '' or os.path.exists(target):
        continue

    print('Syncing', i)
    if i.endswith('.mp3'):
        print('Copying mp3')
        shutil.copy(playlistpath + '/' + i, target)
    else:
        print('Transcoding')
        os.system(f'ffmpeg -i "{playlistpath}/{i}" "{target}"')

for i in os.listdir():
    if i.endswith('.mp3') and i not in synced:
        print('Removing', i)
        os.remove(i)