def getTracks(filenames, sortByFilename=False, ignoreHiddenFiles=True):
    """
        Same as getTracksFromFiles(), but works for any kind of filenames (files, playlists, directories)
        If sortByFilename is True, files loaded from directories are sorted by filename instead of tags
        If ignoreHiddenFiles is True, hidden files are ignored when walking directories
    """
    allTracks = []

    # Directories
    for directory in [filename for filename in filenames if os.path.isdir(filename)]:
        mediaFiles, playlists = [], []
        for root, subdirs, files in os.walk(directory):
            for file in files:
               if not ignoreHiddenFiles or file[0] != '.':
                    if isSupported(file):            mediaFiles.append(os.path.join(root, file))
                    elif playlist.isSupported(file): playlists.append(os.path.join(root, file))

        if sortByFilename: allTracks.extend(sorted(getTracksFromFiles(mediaFiles), lambda t1, t2: cmp(t1.getFilePath(), t2.getFilePath())))
        else:              allTracks.extend(sorted(getTracksFromFiles(mediaFiles)))

        for pl in playlists:
            allTracks.extend(getTracksFromFiles(playlist.load(pl)))

    # Files
    tracks = getTracksFromFiles([filename for filename in filenames if os.path.isfile(filename) and isSupported(filename)])

    if sortByFilename: allTracks.extend(sorted(tracks, lambda t1, t2: cmp(t1.getFilePath(), t2.getFilePath())))
    else:              allTracks.extend(sorted(tracks))

    # Playlists
    for pl in [filename for filename in filenames if os.path.isfile(filename) and playlist.isSupported(filename)]:
        allTracks.extend(getTracksFromFiles(playlist.load(pl)))

    return allTracks
Example #2
0
def getTracks(filenames, sortByFilename=False):
    """ Same as getTracksFromFiles(), but works for any kind of filenames (files, playlists, directories) """
    allTracks = []

    # Directories
    for directory in [filename for filename in filenames if os.path.isdir(filename)]:
        mediaFiles, playlists = [], []
        for root, subdirs, files in os.walk(directory):
            for file in files:
                if isSupported(file):            mediaFiles.append(os.path.join(root, file))
                elif playlist.isSupported(file): playlists.append(os.path.join(root, file))


        if sortByFilename: allTracks.extend(sorted(getTracksFromFiles(mediaFiles), lambda t1, t2: cmp(t1.getFilePath(), t2.getFilePath())))
        else:              allTracks.extend(sorted(getTracksFromFiles(mediaFiles)))

        for pl in playlists:
            allTracks.extend(getTracksFromFiles(playlist.load(pl)))

    # Files
    tracks = getTracksFromFiles([filename for filename in filenames if os.path.isfile(filename) and isSupported(filename)])

    if sortByFilename: allTracks.extend(sorted(tracks, lambda t1, t2: cmp(t1.getFilePath(), t2.getFilePath())))
    else:              allTracks.extend(sorted(tracks))

    # Playlists
    for pl in [filename for filename in filenames if os.path.isfile(filename) and playlist.isSupported(filename)]:
        allTracks.extend(getTracksFromFiles(playlist.load(pl)))

    return allTracks
 def test_load_playlist(self):
     self.plist = load('haha.json')
     self.assertIsInstance(self.plist.songs[0], Song)
     self.assertEqual(self.puppy.title, self.plist.songs[0].title)
def menu():
    print("welcome to the best music player ever")
    t = True
    playlist = None
    p = None
    while t:

        print("1. Create new Playlist")
        print("2. Load existing Playlist")
        print("3. Save current playlist")
        print("4. View Playlist")
        print("5. PLay song")
        print("6. Exit")

        choice = input("> ")
        if choice == "1":
            print("Enter name for new Playlist > "),
            name = input()
            print("Enter the filepath to your music > ")
            filepath = input()
            m = MusicCrawler(filepath)
            playlist = m.generate_playlist()
            playlist.name = name
            print("Playlist {}  created".format(playlist.name))

        elif choice == "2":
            print("Enter the filepath to your playlist > ")
            filepath = input()
            playlist = load(filepath)
            if playlist is not None:
                print("Playlist {} loaded".format(playlist.name))

        elif choice == "3":
            if playlist is None:
                print("No playlist loaded")
            else:
                print("Enter filepath to save > ")
                filepath = input()
                playlist.save(filepath)

        elif choice == "4":
            for i, song in enumerate(playlist.songs):
                print("[{}] {}".format(i, song))

        elif choice == "5":
            print("Enter song number > ")
            number = int(input())
            if number < 0 or number >= len(playlist.songs):
                print("song number doesnt exist!")
            else:
                if p is not None:
                    p.terminate()
                    os.system("pkill -9 play")
                p = multiprocessing.Process(target=playSong,
                    args=(playlist.songs, number))
                p.start()
                print()
        elif choice == "6":
            if p is not None:
                p.terminate()
                os.system("pkill -9 play")
            print("Thank you! Come again!")
            sys.exit(0)

        else:
            print("Wrong input! try again")
Example #5
0
app = Flask(__name__)
app.config['UPLOAD_FOLDER'] = "./uploads"
app.config['FAN_PARENT_FOLDER'] = "../led_control/"
app.config['FAN_SEQUENCE_FOLDER'] = "../led_control/incoming_images"
app.config['PLAYLIST_FILE'] = 'playlist.json'
app.config['SCHEDULER_FILE'] = 'scheduler.json'

action_q = Queue.Queue()
response_q = Queue.Queue()
current_action = [
    "stop"
]  # used to communicate main thraed what is worker currently doing

playlist = playlist.Playlist()
playlist.load(app.config['PLAYLIST_FILE'])

schedule = scheduler.Scheduler()
schedule.load(app.config['SCHEDULER_FILE'])


def start_motor():
    mc = MotorController()

    if mc.connect():
        print "in connect"
        mc.set_motor_speed(1700)
        mc.sync_speed(5)
        return mc
    else:
        return None