Beispiel #1
0
    def testCommit(self):
        """Commit test"""
        # Open and save
        song = songdetails.scan(os.path.join("data", "commit.mp3"))
        random_artist_name = u"Örinä artist%s" % random.random()
        song.artist = random_artist_name
        song.save()
        del song

        # Re-open and read
        opensong = songdetails.scan(os.path.join("data", "commit.mp3"))
        self.assertEqual(opensong.artist, random_artist_name)
Beispiel #2
0
    def testCommit(self):
        """Commit test"""
        # Open and save
        song = songdetails.scan(os.path.join("data", "commit.mp3"))
        random_artist_name = u"Örinä artist%s" % random.random()
        song.artist = random_artist_name
        song.save()
        del song

        # Re-open and read
        opensong = songdetails.scan(os.path.join("data", "commit.mp3"))
        self.assertEqual(opensong.artist, random_artist_name)
Beispiel #3
0
def main(argv):
    try:
        opts, args = getopt.getopt(argv, "ha:l:g:d", ["help", "artist=", "album=", "genre="]) 
    except getopt.GetoptError:
        usage()
        sys.exit(2)
    
    if not args:
        usage()
        sys.exit(2)

    for opt, arg in opts:
        if opt in ("-h", "--help"):
            usage()
            sys.exit()
        elif opt == '-d':
            global _debug
            _debug = 1
        elif opt in ("-a", "--artist"):
            print ("Found artist: ", arg)
            artist = arg
        elif opt in ("-l", "--album"):
            print ("Found album: ", arg)
            album = arg
        elif opt in ("-g", "--genre"):
            print ("Found genre: ", arg)
            genre = arg

    for file in args:
        print "file: ", file
        song = songdetails.scan(file)
        printsong(song)
        print ""
Beispiel #4
0
def set_ID3(filenames):
    '''
    Sets the ID3 title of each file with the filename and removes all other information  
    '''
    import songdetails
    for filename in filenames:
        song_info = songdetails.scan(filename)
        if song_info is None:
	    print("Skipping setting song info on %s" % filename)
            continue

        filename = os.path.basename(filename)

        song_info.title = filename
        song_info.artist = u"Guga"
        song_info.save()
Beispiel #5
0
def getPlaylistTracks(libraryInstance, playlistName): 
    # Get the songs included in the specified Playlist
    if system == "Darwin":
        return libraryInstance.getPlaylist(playlistName).tracks
    
    rtObj = []
    for element in libraryInstance.iter('playlist'):
        if element.get('name') == playlistName:
            for s in element.iter('location'):
                song = songdetails.scan(urllib.unquote(s.text[7:]))
                if verbose: print("\t- Adding Song: {}".format(song.title))
                if song != None:
                    rtObj.append(song)
                else:
                    print("Warning: Couldn't get Metadata for Song at Path: {}".format(element.text))

    return rtObj
    def downloadTrack(self, track):

        title = track["title"].replace(".mp3", "")
        filename = title + ".mp3"
        artist = track["user"]["username"]
        genre = track["genre"]
        year = track["release_year"]

        try:

            # if the song already exsists in the directory do nothing
            if filename in self.alreadyDownloadedTracks:
                print "Song Already Downloaded : " + filename + "\n"
                self.skippedTrackCount += 1
                return

            url = self.getDownloadUrl(track)

            if not url:
                self.failedTracks.append(title)
                print "Unable to get download url for track '{0}', continueing to next track".format(title)
                return

            print "Downloading track '{0}'".format(title)

            try:

                urllib.urlretrieve(url, title)

                # set the ID3 tagging information for the track
                song = songdetails.scan(title)
                if song is not None:
                    song.artist = artist
                    song.title = title
                    song.genre = genre
                    song.year = year
                    song.save()

                os.rename(title, filename)

            except IOError as e:
                self.failedTracks.append(title)
                print "Connection to SoundCloud Failed, unable to download:\n " + title + "\n continuing to next song"

        except UnicodeEncodeError as e:
            print "Could not handle printing the unicode for the track\n"
import os
import re
import eyed3
import pprint
import songdetails
from mpeg1audio import MPEGAudio, MPEGAudioHeaderException

def mp3gen():
	for files in os.listdir('.'):
		if os.path.splitext(files)[1] == '.mp3':
			yield files
				
for mp3file in mp3gen():
	newFile = re.sub(r'\[Songira.com\]\s', '', mp3file)
	newFile = re.sub(r'\s\(Songira.com\)', '', newFile)
	newFile = re.sub(r'[\s]*\[.+\][\s]*', '', newFile)
	os.rename(os.path.join(os.getcwd(), mp3file), os.path.join(os.getcwd(), newFile))

	song = songdetails.scan(os.path.join(os.getcwd(), newFile))
	if song is not None:
		newSongName = re.sub(r' \- Songira\.com', '', song.title)
		song.title = newSongName
		song.save()
			
print('Finished parsing and fixing file!')
Beispiel #8
0
 def testScan(self):
     """Scan test"""
     song = songdetails.scan(os.path.join("data", "song.mp3"))
     self.assertEqual(song.artist, "Rauli Badding Somerjoki")
     self.assertEqual(song.duration.seconds, 192)
Beispiel #9
0
 def testScan(self):
     """Scan test"""
     song = songdetails.scan(os.path.join("data", "song.mp3"))
     self.assertEqual(song.artist, "Rauli Badding Somerjoki")
     self.assertEqual(song.duration.seconds, 192)
Beispiel #10
0
import os, songdetails

location = r'/Users/Mo/Music'
os.chdir(location)

for root, dirs, files in os.walk(location):
    for mp3s in files:
        if mp3s.endswith('.mp3'):
            song = songdetails.scan(mp3s)
            song_name = "{}.mp3".format(song.title)
            print("{} will be renamed to {} ".format(mp3s, song.title))
            os.rename(mp3s, song_name)
Beispiel #11
0
import glob
import songdetails

song = glob.glob('*.mp3')

number = len(song)

for i in range(number):
	print song[i]
	name = songdetails.scan(song[i])
	print name.title
	print name.artist
	print name.duration
	print "\n"
	name.artist = u'Ed Sheeran'
	name.save()