示例#1
0
    def testToCurrent(self):
        desiredResult = [
            'Test 0-title-6cwBLBCehGg.mp3', 'Test 1-title-6cwBLBCehGg.mp3',
            'Test 2-title-6cwBLBCehGg.mp3', 'Test 3-title-6cwBLBCehGg.mp3',
            'Test 4-title-6cwBLBCehGg.mp3'
        ]
        try:
            print(mht.TestMusicPath)
            musicList = glob.glob(mht.TestMusicPath +
                                  '*.mp3')  # gather list of test music
            for track in musicList:
                if str(track.split(' ')
                       [0])[-4:] == "Test":  # if they are a test file
                    track = track[
                        mht.TestMusicPath.__len__():]  # truncate track name
                    mht.toCurrent(track, -1)  # send track to current

            fileList = glob.glob(
                mht.CurrentMusicPath +
                '*.mp3')  # gather a list of tracks in /Music/Current/
            result = []
            for track in fileList:  # return Test*.mp3 to /Test/
                track = track[mht.CurrentMusicPath.__len__():]
                if track.split(' ')[0] == "Test":
                    result.append(track)
                    os.rename(mht.CurrentMusicPath + track,
                              mht.TestMusicPath + track)
            self.assertEqual(desiredResult, result)
        except TypeError and FileNotFoundError and AttributeError and OSError as e:
            error(str(e))
            pass
示例#2
0
 def testClear(self):
     desiredResult = 0
     try:
         mht.clear()
         results = mht.readData().__len__()
         self.assertEqual(desiredResult, results)
     except ValueError as e:
         error(str(e))
         pass
示例#3
0
 def testReadData(self):
     desiredResult = []
     mht.clear()
     try:
         result = mht.readData()
         self.assertEqual(desiredResult, result,
                          'Failed to read from file' + mht.FileName)
     except TypeError and ValueError and FileNotFoundError as e:
         error(str(e))
         pass
示例#4
0
 def testSaveHeader(self):
     desiredResult = "[\"['ARTIST', 'TITLE', 'URL', 'HASH', 'LIKES', 'DISLIKES', 'VIEWS', 'USED?']\"]"
     try:
         mht.saveHeader(dataList=[
             'ARTIST', 'TITLE', 'URL', 'HASH', 'LIKES', 'DISLIKES', 'VIEWS',
             'USED?'
         ])  # Test
         results = str(mht.readData()[0])  # gather results
         self.assertEqual(desiredResult, results)
     except TypeError and ValueError as e:
         error(str(e))
         pass
示例#5
0
 def testRemoveCommas(self):
     desiredResult = 'Test'
     try:
         results = mht.removeCommas(',T,e,s,t,')
         self.assertEqual(desiredResult, results)
     except TypeError as e:
         error(str(e))
         pass
示例#6
0
 def testGetRatios(self):
     desiredResult = [0.9, 9.0, .09]
     try:
         results = mht.getRatios([9, 1, 100])
         self.assertEqual(desiredResult, results)
     except TypeError as e:
         error(str(e))
         pass
示例#7
0
 def testSaveData(self):
     try:
         desiredResult = "[['Flight of the Conchords,Robots,BNC61-OOPdA,4100,59,559964,False,0,0,0'], " \
                         "['Crush,Tessa Violet,SiAuAJBZuGs,111000,4300,1969889,False,0,0,0'], " \
                         "['gnash,home,6cwBLBCehGg,0,0,0,False,0,0,0'], " \
                         "['alt-j,in cold blood,rP0uuI80wuY,74000,2000,9059467,False,0,0,0']]"
         mht.clear()
         dataList = ht.HashTable()
         dataList.put(testSong12.Artist, testSong12)
         dataList.put(testSong11.Artist, testSong11)
         dataList.put(testSong00.Artist, testSong00)
         dataList.put(testSong13.Artist, testSong13)
         mht.saveData(dataList)
         results = str(mht.readData())  # gather results
         self.assertEqual(desiredResult, results)
     except ValueError and AttributeError as e:
         error(str(e))
         pass
示例#8
0
 def testGetTrackInfo(self):
     desiredResult = ['Test 0', 'Title', '6cwBLBCehGg']
     try:
         results = mht.getTrackInfo(mht.TestMusicPath +
                                    'Test 0-title-6cwBLBCehGg.mp3')
         self.assertEqual(desiredResult, results)
     except TypeError as e:
         error(str(e))
         pass
示例#9
0
 def testGetStats(self):
     desiredResult = [0, 0, 0]
     ytPath = 'https://www.youtube.com/watch?v='
     try:
         results = mht.getStats(ytPath + TEST_VIDEO)
         self.assertEqual(desiredResult, results)
     except TypeError as e:
         error(str(e))
         pass
示例#10
0
 def testAppendData(self):
     desiredResult = "[['alt-j,in cold blood,rP0uuI80wuY,74000,2000,9059467,False,0,0,0']]"
     try:
         mht.clear()
         mht.appendData(
             mht.Data("in cold blood",
                      "alt-j",
                      Url="rP0uuI80wuY",
                      likes=74000,
                      dislikes=2000,
                      views=9059467))
         results = str(mht.readData()[mht.readData().__len__() - 1:])
         mht.music.remove('alt-j')
         self.assertEqual(desiredResult, results)
     except TypeError and ValueError as e:
         error(str(e))
         pass
示例#11
0
 def testUpdateCSV(self):
     desiredResult = [[
         "'ARTIST', 'TITLE', 'URL', 'LIKES', 'DISLIKES', 'VIEWS', 'USED?', 'LIKES to TOTAL RATIO', "
         "'LIKES to DISLIKES RATIO', 'LIKES to VIEWS RATIO'"
     ], ['Test 0,Title,6cwBLBCehGg,0,0,0,False,0,0,0'],
                      ['Test 1,Title,6cwBLBCehGg,0,0,0,False,0,0,0'],
                      ['Test 2,Title,6cwBLBCehGg,0,0,0,False,0,0,0'],
                      ['Test 3,Title,6cwBLBCehGg,0,0,0,False,0,0,0'],
                      ['Test 4,Title,6cwBLBCehGg,0,0,0,False,0,0,0']]
     try:
         mht.clear()
         mht.updateCSV(-1)
         results = mht.readData()
         mht.clear()
         self.assertEqual(desiredResult, results)
     except AttributeError as e:
         error(str(e))
         pass
示例#12
0
from __future__ import unicode_literals

import glob
import os

import youtube_dl
from googleapiclient.discovery import build

from Music import MusicHashTable

# different words to identify mixes and livestreams
liveVidKeyWords = [
    "24/7", "radio", "mix", "live", "2018", "lofi", "lo-fi", "songs", "#",
    'compilation', 'hour'
]
user = MusicHashTable.User('', '')
BASEPATH = user.BASEPATH
# Set DEVELOPER_KEY to the API key value from the APIs & auth > Registered apps
# tab of
#   https://cloud.google.com/console
# Please ensure that you have enabled the YouTube Data API for your project.
DEVELOPER_KEY = "AIzaSyDsEUDbBKzBE6HS96PJ7FQpS5a8qfEV3Sk"
YOUTUBE_API_SERVICE_NAME = "youtube"
YOUTUBE_API_VERSION = "v3"

# A function to check the list to predict if its a live video
# params: list of title words
# returns a Boolean depicting whether it is assumed to be live or not


def isLive(title):
示例#13
0
codes = {
    'mg': 'C:/Users/mjgro/Documents/GitHub/YT-Music-AI/',
    'cd': 'C:/Users/corma/Documents/GitHub/YT-Music-AI/'
}

# user = mh.User('', '')


def error(errorMessage):
    print(">ERROR:\t" + str(errorMessage))


# main's main
if __name__ == "__main__":
    if not os.path.isfile(mh.FileName):
        mh.error("'MusicData.csv' could not be found")
        mh.clear()
        print(">FILE CREATED: 'MusicData.csv' in /Music/")

    argparser.add_argument("--q", help="Search term", default="")
    argparser.add_argument("--max-results", help="Max results", default=25)
    print('Please wait while previous data is saved')
    mh.convertCSVtoDict()
    print('Thank you for your patience, proceed.')
    while True:
        try:
            if mh.user.BASEPATH == '':
                print(
                    'Insert the path to the directory on your computer that '
                    'leads to the directory that contains your \'New\' \n\tand \'Current\' folders, or your initials\n'
                )
示例#14
0
import glob
import os
import unittest as ut

from Music import HashTable as ht
from Music import MusicHashTable as mht
from Music import YT_Bot as yt

TEST_VIDEO = '6cwBLBCehGg'
testSong00 = mht.Data('home', 'gnash')
testSong01 = mht.Data('SWEET', 'BROCKHAMPTON')
testSong02 = mht.Data('Pillow Talk', 'Zayn')
testSong03 = mht.Data('Kiss You', 'One Direction')
testSong04 = mht.Data('Hurricane', 'Halsey')
testSong05 = mht.Data('i hate u, i love u', 'gnash')
testSong06 = mht.Data('Almost Cut My Hair (For Crosby)', 'Milo')
testSong07 = mht.Data('CINEMA 1', 'BROCKHAMPTON')
testSong08 = mht.Data('Black Car', 'Gregory Alan Isakov')
testSong09 = mht.Data('This House', 'Gregory Alan Isakov')
testSong10 = mht.Data('What Makes You Beautiful', 'One Direction')
testSong11 = mht.Data('Tessa Violet', 'Crush', 'SiAuAJBZuGs', 111000, 4300,
                      1969889)
testSong12 = mht.Data('Robots', 'Flight of the Conchords', 'BNC61-OOPdA', 4100,
                      59, 559964)
testSong13 = mht.Data('in cold blood', 'alt-j', 'rP0uuI80wuY', 74000, 2000,
                      9059467)


# prints error message
def error(errorMessage):
    print(">ERROR:\t" + str(errorMessage))