Skip to content

Instantly share code, notes, and snippets.

@wridgers
Created February 6, 2013 16:12

Revisions

  1. wridgers created this gist Feb 6, 2013.
    40 changes: 40 additions & 0 deletions playlists.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,40 @@
    #!/usr/bin/python

    import os, time, sys

    now = time.time()

    errorFiles = open('errors.txt', 'w')
    playlist01days = open('Last 1 day.m3u', 'w')
    playlist07days = open('Last 7 days.m3u', 'w')
    playlist14days = open('Last 14 days.m3u', 'w')
    playlist28days = open('Last 28 days.m3u', 'w')

    for root, dirs, files in os.walk(os.getcwd()):
    for filename in files:
    if filename.endswith(('.mp3', '.flac', '.ogg')):

    try:
    path = os.path.join(root, filename)
    created = os.path.getctime(path);

    if (created > now - 60 * 60 * 24):
    playlist01days.write(path + '\n')

    if (created > now - 7 * 60 * 60 * 24):
    playlist07days.write(path + '\n')

    if (created > now - 14 * 60 * 60 * 24):
    playlist14days.write(path + '\n')

    if (created > now - 28 * 60 * 60 * 24):
    playlist28days.write(path + '\n')

    except:
    errorFiles.write(path + '\n')

    errorFiles.close()
    playlist01days.close()
    playlist07days.close()
    playlist14days.close()
    playlist28days.close()