Beispiel #1
0
def shuffle(plPath):
    '''randomizes playlist order'''
    cfg.logger.info("Shuffling Playlist")
    correctStateCorruption(plPath)

    with shelve.open(f"{plPath}/{cfg.metaDataName}", 'c',writeback=True) as metaData:

        plLen = len(metaData["ids"])
        ids = metaData["ids"]

        avalibleNums = [i for i in range(plLen)]
        newOrder = []
        for _ in range(plLen):
            oldIndex = avalibleNums.pop(randint(0,len(avalibleNums)-1))
            newOrder.append( (ids[oldIndex],oldIndex) )
    
    editPlaylist(plPath, newOrder)
Beispiel #2
0
    def test_1(self):
        cfg.logger.info(
            f"Running {self.__class__.__name__}: {self._testMethodName}")
        name = 'editPl1'

        songs = ['A', 'B', 'C', 'D']

        createFakePlaylist(name, songs)

        newOrder = [('3', 3), ('1', 1), ('2', 2), ('0', 0)]

        correct = [('3', '0_D'), ('1', '1_B'), ('2', '2_C'), ('0', '3_A')]

        editPlaylist(f'{cfg.testPlPath}/{name}', newOrder)

        result = getPlaylistData(name)

        shutil.rmtree(f'{cfg.testPlPath}/{name}')
        self.assertEqual(result, correct)
Beispiel #3
0
    def test_4(self):
        cfg.logger.info(
            f"Running {self.__class__.__name__}: {self._testMethodName}")
        name = 'editPl3'

        songs = ['A', 'B', 'C', 'D', 'E', 'F', 'G']

        createFakePlaylist(name, songs)

        newOrder = [('6', 6), ('3', 3), ('4', 4), ('5', 5), ('2', 2)]

        correct = [('6', '0_G'), ('3', '1_D'), ('4', '2_E'), ('5', '3_F'),
                   ('2', '4_C')]
        editPlaylist(f'{cfg.testPlPath}/{name}', newOrder, True)

        result = getPlaylistData(name)

        shutil.rmtree(f'{cfg.testPlPath}/{name}')
        self.assertEqual(result, correct)
Beispiel #4
0
    def test_3(self):
        cfg.logger.info(
            f"Running {self.__class__.__name__}: {self._testMethodName}")
        name = 'editPl3'

        songs = ['A', 'B', 'C']

        createFakePlaylist(name, songs)

        newOrder = []

        correct = []

        editPlaylist(f'{cfg.testPlPath}/{name}', newOrder, True)

        result = getPlaylistData(name)

        shutil.rmtree(f'{cfg.testPlPath}/{name}')
        self.assertEqual(result, correct)
Beispiel #5
0
def smartSync(plPath):
    '''
    Syncs to remote playlist however will Not delete local songs (will reorder). Songs not in remote (ie ones deleted) 
    will be after the song they are currently after in local
    Example 1
        Local order: A B C D 
        Remote order: A 1 B C 2

        Local becomes: A 1 B C D 2

        notice D was removed from remote but is still after C in Local
    
    Example 2
        Local order: A B C D 
        Remote order: A 1 C B 2

        Local becomes: A 1 C D B 2

        notice C and B where swapped and D was deleted from Remote
    
    see test_smartSyncNewOrder in tests.py for more examples
    '''
    cfg.logger.info("Smart Syncing...")
    correctStateCorruption(plPath)


    with shelve.open(f"{plPath}/{cfg.metaDataName}", 'c',writeback=True) as metaData:
        url = metaData["url"]
        localIds = metaData["ids"]

    remoteIds = getIDs(url)


    newOrder = smartSyncNewOrder(localIds,remoteIds)

    editPlaylist(plPath,newOrder)