Пример #1
0
def test_lookup_album():
    item = itunes.lookup(U2_ACHTUNGBABY_ID)
    assert isinstance(item, itunes.Album)
    assert item.id == U2_ACHTUNGBABY_ID
    assert item.name == U2_ACHTUNGBABY

    assert item.artist.id == U2_ID
Пример #2
0
def readDescriptions(file):
    """
	Get the description and bundle name of all itunes IDs in the given file.
	For each description, build the corresponding bag-of-words along with it tf score.
	In addition, build the later-used dictionary.
    ----------
    file : the file to parse
    """
    with open(file, 'r') as Ids:
        for line in Ids:
            ID = int(line)
            item = itunes.lookup(ID)
            description = item.description.lower(
            )  #avoid counting the same word differntly
            # remove stop words
            description = ' '.join([
                word for word in description.split()
                if word not in cachedStopWords
            ])
            description = re.sub("[^a-zA-Z]", " ", description)
            description = ' '.join(description.split())  #remove white spaces
            corpus.append(description)  #adding to corpus
            wordList = set(description.split())
            dictionary.update(wordList)  #update dictionary with new words

            bagOfWords = collections.Counter(re.findall(
                r'\w+', description))  #create the corresponding bag of words

            #tf scores
            factor = 1.0 / sum(bagOfWords.itervalues())
            for k in bagOfWords.keys():
                bagOfWords[k] = bagOfWords[k] * factor  #standart tf score
            bundleIdToDescriptions[item.json['bundleId']] = bagOfWords
Пример #3
0
def test_lookup_album():
    item = itunes.lookup(U2_ACHTUNGBABY_ID)
    assert_true(isinstance(item, itunes.Album))
    assert_equal(item.get_id(), U2_ACHTUNGBABY_ID)
    assert_equal(item.get_name(), U2_ACHTUNGBABY)

    assert_equal(item.get_artist().get_id(), U2_ID)
Пример #4
0
def test_lookup_album():
    item = itunes.lookup(U2_ACHTUNGBABY_ID)
    assert_true(isinstance(item, itunes.Album))
    assert_equal(item.get_id(), U2_ACHTUNGBABY_ID)
    assert_equal(item.get_name(), U2_ACHTUNGBABY)

    assert_equal(item.get_artist().get_id(), U2_ID)
Пример #5
0
def test_lookup_album():
    item = itunes.lookup(U2_ACHTUNGBABY_ID)
    assert isinstance(item, itunes.Album)
    assert item.id == U2_ACHTUNGBABY_ID
    assert item.name == U2_ACHTUNGBABY

    assert item.artist.id == U2_ID
Пример #6
0
def test_lookup_track():
    item = itunes.lookup(U2_ONE_ID)
    assert isinstance(item, itunes.Track)
    assert item.id == U2_ONE_ID
    assert item.name == U2_ONE

    assert item.album.id == U2_ACHTUNGBABY_ID
    assert item.artist.id == U2_ID
Пример #7
0
def test_lookup_track():
    item = itunes.lookup(U2_ONE_ID)
    assert isinstance(item, itunes.Track)
    assert item.id == U2_ONE_ID
    assert item.name == U2_ONE

    assert item.album.id == U2_ACHTUNGBABY_ID
    assert item.artist.id == U2_ID
Пример #8
0
def get_apple_track(song_url):
    try:
        ind = song_url.index('?i=') + 3 #get index of true ID
        true_id = song_url[ind:]
        track = itunes.lookup(int(true_id))
        return (track.name, str(track.artist)[8:])
    except:
        print ("Oops something went wrong")
Пример #9
0
def getTop200Tracks(artistID):
    artist = artistID
    filename = str(artistID) + '.json'
    counter = 0
    data = {}
    first = True
    channelID = 'itunes_artist'

    sql = "SELECT itunes_connection_artist_track.track_id FROM itunes_connection_artist_track LEFT JOIN itunes_tracks ON itunes_connection_artist_track.track_id = itunes_tracks.track_id WHERE itunes_tracks.track_id IS NULL AND itunes_connection_artist_track.artist_id = " + str(artistID) + ""
    tracksID = SQLRequest(sql)

    if len(tracksID) > 0:

        sql = "SELECT track_id FROM itunes_connection_artist_track WHERE artist_id=" + str(artistID) + " LIMIT 0,1"

        trackID = SQLRequest(sql)[0]

        artistID = itunes.lookup(id=trackID, entity='song', proxy=1)[0].artist_id
        tracks = itunes.lookup(id=artistID, entity='song', limit=200, proxy=1)

        data['artist_id'] = artist
        data['channel_id'] = channelID
        data['created'] = int(datetime.datetime.now().timestamp())
        data['updated'] = int(datetime.datetime.now().timestamp())
        data['status_id'] = 'ok'
        data['filename'] = str(int(datetime.datetime.now().timestamp())) + '_' + str(
            random.randint(1000, 9999)) + channelID + '.json'
        data['data'] = {}

        for track in tracks[1:]:
            if int(track.track_id) in tracksID:
                if first:
                    data['data']['created'] = str(int(datetime.datetime.now().timestamp()))
                    data['data']['updated'] = str(int(datetime.datetime.now().timestamp()))
                    data['data']['tracks'] = {}
                    first = False
                data = setTrackInJSON(track, data, counter)
                counter += 1
        data['data']['track_gauge'] = counter

    if counter > 0:
        with open(filename, 'w') as outfile:
            json.dump(data, outfile)
Пример #10
0
def get_random():
    genre = request.args.get('genre')
    if genre:
        song = query_db(
            'select * from popularities where genre=? order by random() limit 1',
            args=[genre], one=True)
    else:
        song = query_db(
            'select * from popularities order by random() limit 1',
            one=True)

    lookup = itunes.lookup(song['atom_id'])
    fields = ['trackName', 'previewUrl', 'artworkUrl100', 'collectionName',
              'artistName']
    for field in fields:
        if field in lookup:
            song[field] = lookup[field]
    return json_response(song)
Пример #11
0
def detail(artist_name):
    itunes_search = itunes.search(artist_name, limit=1)
    if len(itunes_search):
        itunes_data = itunes.lookup(itunes_search[0]['artistId'])
        lastfm_data = lastfm.get_artist(itunes_data['artistName'])

        song_fields = ['trackName', 'previewUrl', 'artworkUrl100',
            'collectionName', 'trackPrice', 'collectionViewUrl']
        itunes_songs = itunes.search(itunes_data['artistName'])[:3]
        itunes_songs = [dict((k, song[k]) for k in song_fields if k in song)
                        for song in itunes_songs]

        return render_template('detail.html', **{
            'name': itunes_data['artistName'],
            'picture': lastfm_data['image'][2]['#text'],
            'on_tour': True,
            'other_songs': itunes_songs,
            'description': ', '.join(tag['name']
                for tag in lastfm_data['tags']['tag'][:3]),
        })
Пример #12
0
def getTrackByTrackID(artistID):
    filename = str(artistID) + '.json'
    counter = 0
    first = True
    data = {}
    channelID = 'itunes_artist'

    sql = "SELECT itunes_connection_artist_track.track_id FROM itunes_connection_artist_track LEFT JOIN itunes_tracks ON itunes_connection_artist_track.track_id = itunes_tracks.track_id WHERE itunes_tracks.track_id IS NULL AND itunes_connection_artist_track.artist_id = " + str(artistID) + ""
    tracksID = SQLRequest(sql)

    if (len(tracksID) > 0):
        data['artist_id'] = artistID
        data['channel_id'] = channelID
        data['created'] = int(datetime.datetime.now().timestamp())
        data['updated'] = int(datetime.datetime.now().timestamp())
        data['status_id'] = 'ok'
        data['filename'] = str(int(datetime.datetime.now().timestamp())) + '_' + str(
            random.randint(1000, 9999)) + channelID + '.json'
        data['data'] = {}

        for track_id in tracksID:
            track = itunes.lookup(id=track_id, entity='song', proxy=1)

            if first:
                data['data']['created'] = str(int(datetime.datetime.now().timestamp()))
                data['data']['updated'] = str(int(datetime.datetime.now().timestamp()))
                data['data']['tracks'] = {}
                first = False
            data = setTrackInJSON(track[0], data, counter)
            counter += 1

        data['data']['track_gauge'] = counter

    if counter > 0:
        with open(filename, 'w') as outfile:
            json.dump(data, outfile)
Пример #13
0
def test_album_length():
    item = itunes.lookup(U2_ACHTUNGBABY_ID)
    assert isinstance(item.get_tracks(), list)
Пример #14
0
def test_album_url():
    item = itunes.lookup(U2_ACHTUNGBABY_ID)
    assert item.url == U2_ACHTUNGBABY_URL
from .models import Podcast, Category
from datetime import datetime
import requests
import itunes

all_pods = Podcast.objects.all()

counter = 0

podcast = itunes.lookup(1313466221)
_, create = Podcast.objects.update_or_create(
    image_url=podcast.artwork['600'], )

# for podcast in all_pods:
#     id = podcast.itunes_id
#     if not podcast.image_url or not podcast.website or not podcast.category or not podcast.description:
#         pod = itunes.lookup(id)
#         _, create = Podcast.objects.update_or_create(
#             image_url=pod.artwork['600'],
#             description=column[6],
#             website=pod.url,
#             category_id=pod.genre,
#         )
Пример #16
0
 # Escape single quotes using mappings
 xid = x['id']
 tune = x['Buy']
 xartist = x['Artist']
 xtitle = x['Name']
 position = None
 if 'Position' in x:
     position = int(x['Position'])
 song = None
 genre = None
 if tune is not None and len(tune) > 0:
     o = urlparse(tune)
     q = parse_qs(o.query)
     qid = q['i'][0]
     try:
         song = itunes.lookup(qid)
     except:
         # try last part of path instead
         #print "Will try id... ; Not found: " , qid, tune
         q = o.path.split("/")[-1]
         qid = q.split("id")[1]
         try:
             song = itunes.lookup(qid)
         except:
             print "Not found in itunes lookup: ", qid, tune
             pass
     if song is not None:
         genre = song.get_genre()
         try:
             c.execute("INSERT INTO genre (name) VALUES (?)", (genre, ))
         except Exception as e:
Пример #17
0
def test_track_url():
    item = itunes.lookup(U2_ONE_ID)
    assert_equal(item.get_url(), U2_ONE_URL)
Пример #18
0
def test_artist_url():
    item = itunes.lookup(U2_ID)
    assert_equal(item.get_url(), U2_URL)
Пример #19
0
def getDataFromApple(opts, movieName, movieYear):
    """docstring for getDataFromApple"""
    if opts.verbose > 0:
        print "  Retrieving data from Apple for: %s - %s" % (movieName, movieYear)
    #end if verbose

    if opts.verbose == 2:
        print "  Looking up data for: %s - %s" % (movieName, movieYear)
    #end if debug

    movieResults = itunes.search_movie(movieName.decode('utf-8'))
    movies = []
    
    if opts.verbose == 2:
        print "!!Search returned %s hits" % len(movieResults)
    #end if debug
    
    #we got zero hits, try replacing some commonly used replacement-characters due to filename illegality
    #if len(movieResults) < 1:
        #if movieName.count(';'):
            #tempMovieName = movieName.replace(';', ':')
            #return getDataFromApple(opts, tempMovieName, movieYear)
        #elif movieName.count('_'):
            #tempMovieName = movieName.replace('_', ' ')
            #return getDataFromApple(opts, tempMovieName, movieYear)
        #else:
            ##last ditch attempt, search for movies by longest word in movie name as long as more then one word
            #if len(movieName.split()) < 2:
                #return movies
            ##end if len
            #movieNameLongestWord = max(movieName.split(), key=len)
            #longestWordMovies = getDataFromApple(opts, movieNameLongestWord, movieYear)
            #if opts.interactive or len(longestWordMovies) == 1:
                #if opts.verbose == 2:
                    #print "!!Using search result(s) based upon longest word search"
                ##end if debug
                #return longestWordMovies
            ##end if interactive
            #return movies
        ##end if count
    ##end if len
    
    if movieYear != "":
        for movieResult in movieResults:
            #check that the year tag in the file name matches with the release date, otherwise not the movie we are looking for
            if opts.verbose == 2:
                print "!!Potential hit: %s, year: %s" % (movieResult.name, str(movieResult.release_date))
            if movieResult.kind != "feature-movie":
                continue
            if movieResult.release_date:
                if movieResult.release_date.startswith(movieYear) or movieResult.release_date.startswith(str(int(movieYear)+1)):
                    movie = itunes.lookup(movieResult.id)
                    movies.append(movie)
        #end for movie
        if len(movies) < 1:
            print "!!No results were found matching your year: %s" % movieYear
            for movieResult in movieResults:
                if opts.verbose == 2:
                    print "!!Potential hit: %s, year: %s" % (movieResult.name, str(movieResult.release_date))
                if movieResult.kind != "feature-movie":
                    continue
                if movieResult.release_date:
                    movie = itunes.lookup(movieResult.id)
                    movies.append(movie)
            #end for movie
    else:
        for movieResult in movieResults:
            #check that the year tag in the file name matches with the release date, otherwise not the movie we are looking for
            if opts.verbose == 2:
                print "!!Potential hit: %s, year: %s" % (movieResult.name, str(movieResult.release_date))
            if movieResult.kind != "feature-movie":
                continue
            if movieResult.release_date:
                movie = itunes.lookup(movieResult.id)
                movies.append(movie)
        #end for movie

    return movies
Пример #20
0
def test_music_video_kind():
    item = itunes.lookup(U2_ID)
    assert_equal(item.get_music_videos()[0].get_type(), MUSIC_VIDEO_KIND)
Пример #21
0
def test_lookup_artist():
    item = itunes.lookup(U2_ID)
    assert isinstance(item, itunes.Artist)
    assert item.id == U2_ID
    assert item.name == U2
Пример #22
0
def test_lookup_notfound():
    UNKNOWN_ID = 0
    with pytest.raises(itunes.ITunesException):
        itunes.lookup(UNKNOWN_ID)
Пример #23
0
def test_album_length():
    item = itunes.lookup(U2_ACHTUNGBABY_ID)
    assert isinstance(item.get_tracks(), list)
Пример #24
0
def test_track_url():
    item = itunes.lookup(U2_ONE_ID)
    assert item.url == U2_ONE_URL
Пример #25
0
def test_album_url():
    item = itunes.lookup(U2_ACHTUNGBABY_ID)
    url = item.get_url().replace('https','http')
    assert_equal(url, U2_ACHTUNGBABY_URL)
Пример #26
0
def test_track_url():
    item = itunes.lookup(U2_ONE_ID)
    url = item.get_url().replace('https','http')
    assert_equal(url, U2_ONE_URL)
Пример #27
0
def test_artist_url():
    item = itunes.lookup(U2_ID)
    assert_equal(item.get_url(), U2_URL)
Пример #28
0
def test_lookup_artist():
    item = itunes.lookup(U2_ID)
    assert_true(isinstance(item, itunes.Artist))
    assert_equal(item.get_id(), U2_ID)
    assert_equal(item.get_name(), U2)
Пример #29
0
def test_track_url():
    item = itunes.lookup(U2_ONE_ID)
    assert_equal(item.get_url(), U2_ONE_URL)
Пример #30
0
def test_album_url():
    item = itunes.lookup(U2_ACHTUNGBABY_ID)
    assert_equal(item.get_url(), U2_ACHTUNGBABY_URL)
Пример #31
0
def test_music_video_kind():
    item = itunes.lookup(U2_ID)
    assert_equal(item.get_music_videos()[0].get_type(), MUSIC_VIDEO_KIND)
Пример #32
0
def test_album_length():
    item = itunes.lookup(U2_ACHTUNGBABY_ID)
    assert_true(len(item.get_tracks()) == 12)
Пример #33
0
import itunes

# Lookup Achtung Baby album by U2
U2_ACHTUNGBABY_ID = 475390461
album = itunes.lookup(U2_ACHTUNGBABY_ID)

print album.get_url()
print album.get_artwork()

artist = album.get_artist()
tracks = album.get_tracks()

# Lookup song One from Achtung Baby album by U2
U2_ONE_ID = 475391315
track = itunes.lookup(U2_ONE_ID)

artist = track.get_artist()
album = track.get_album()
Пример #34
0
def getDataFromApple(opts, movieName, movieYear):
    """docstring for getDataFromApple"""
    if opts.verbose > 0:
        print "  Retrieving data from Apple for: %s - %s" % (movieName,
                                                             movieYear)
    #end if verbose

    if opts.verbose == 2:
        print "  Looking up data for: %s - %s" % (movieName, movieYear)
    #end if debug

    movieResults = itunes.search_movie(movieName.decode('utf-8'))
    movies = []

    if opts.verbose == 2:
        print "!!Search returned %s hits" % len(movieResults)
    #end if debug

    #we got zero hits, try replacing some commonly used replacement-characters due to filename illegality
    #if len(movieResults) < 1:
    #if movieName.count(';'):
    #tempMovieName = movieName.replace(';', ':')
    #return getDataFromApple(opts, tempMovieName, movieYear)
    #elif movieName.count('_'):
    #tempMovieName = movieName.replace('_', ' ')
    #return getDataFromApple(opts, tempMovieName, movieYear)
    #else:
    ##last ditch attempt, search for movies by longest word in movie name as long as more then one word
    #if len(movieName.split()) < 2:
    #return movies
    ##end if len
    #movieNameLongestWord = max(movieName.split(), key=len)
    #longestWordMovies = getDataFromApple(opts, movieNameLongestWord, movieYear)
    #if opts.interactive or len(longestWordMovies) == 1:
    #if opts.verbose == 2:
    #print "!!Using search result(s) based upon longest word search"
    ##end if debug
    #return longestWordMovies
    ##end if interactive
    #return movies
    ##end if count
    ##end if len

    if movieYear != "":
        for movieResult in movieResults:
            #check that the year tag in the file name matches with the release date, otherwise not the movie we are looking for
            if opts.verbose == 2:
                print "!!Potential hit: %s, year: %s" % (
                    movieResult.name, str(movieResult.release_date))
            if movieResult.kind != "feature-movie":
                continue
            if movieResult.release_date:
                if movieResult.release_date.startswith(
                        movieYear) or movieResult.release_date.startswith(
                            str(int(movieYear) + 1)):
                    movie = itunes.lookup(movieResult.id)
                    movies.append(movie)
        #end for movie
        if len(movies) < 1:
            print "!!No results were found matching your year: %s" % movieYear
            for movieResult in movieResults:
                if opts.verbose == 2:
                    print "!!Potential hit: %s, year: %s" % (
                        movieResult.name, str(movieResult.release_date))
                if movieResult.kind != "feature-movie":
                    continue
                if movieResult.release_date:
                    movie = itunes.lookup(movieResult.id)
                    movies.append(movie)
            #end for movie
    else:
        for movieResult in movieResults:
            #check that the year tag in the file name matches with the release date, otherwise not the movie we are looking for
            if opts.verbose == 2:
                print "!!Potential hit: %s, year: %s" % (
                    movieResult.name, str(movieResult.release_date))
            if movieResult.kind != "feature-movie":
                continue
            if movieResult.release_date:
                movie = itunes.lookup(movieResult.id)
                movies.append(movie)
        #end for movie

    return movies
Пример #35
0
def test_track_url():
    item = itunes.lookup(U2_ONE_ID)
    assert item.url == U2_ONE_URL
Пример #36
0
def test_lookup_artist():
    item = itunes.lookup(U2_ID)
    assert_true(isinstance(item, itunes.Artist))
    assert_equal(item.get_id(), U2_ID)
    assert_equal(item.get_name(), U2)
Пример #37
0
def test_artist_url():
    item = itunes.lookup(U2_ID)
    assert item.url == U2_URL
Пример #38
0
def test_album_url():
    item = itunes.lookup(U2_ACHTUNGBABY_ID)
    assert_equal(item.get_url(), U2_ACHTUNGBABY_URL)
Пример #39
0
def test_lookup_artist():
    item = itunes.lookup(U2_ID)
    assert isinstance(item, itunes.Artist)
    assert item.id == U2_ID
    assert item.name == U2
Пример #40
0
def test_album_length():
    item = itunes.lookup(U2_ACHTUNGBABY_ID)
    assert_true(len(item.get_tracks()) == 26)  # 12)
Пример #41
0
def test_lookup_notfound():
    UNKNOWN_ID = 0
    with pytest.raises(itunes.ITunesException):
        itunes.lookup(UNKNOWN_ID)
Пример #42
0
def test_artist_url():
    item = itunes.lookup(U2_ID)
    assert item.url == U2_URL
Пример #43
0
def test_album_url():
    item = itunes.lookup(U2_ACHTUNGBABY_ID)
    assert item.url == U2_ACHTUNGBABY_URL
Пример #44
0
import glob
import zipfile
import plistlib
import itunes

mobileApps = glob.glob(expanduser("~") + '/Music/iTunes/iTunes Media/Mobile Applications/*.ipa')

output = '<table><tr><th>Icon</th><th>Name</th><th>Genre</th><th>Developer</th><th>Description</th></tr>'

for app in mobileApps:
  currentIPA = file(app)
  ipaContents = zipfile.ZipFile(currentIPA)
  plistFile = ipaContents.read('iTunesMetadata.plist')
  plistContents = plistlib.readPlistFromString(plistFile)
  
  currentApp = itunes.lookup(plistContents['itemId'])
  
  description = currentApp.get_description().replace("\n","<br />\n")

  output += '<tr>'
  output += '<td><img src="' + currentApp.get_artwork()['60'] + '" height="57" width="57"></td>' 
  output += '<td><a href="' + currentApp.get_url() + '">' + currentApp.get_name() + '</a></td>'
  output += '<td>' + currentApp.get_genre() + '</td>'
  output += '<td>' + str(currentApp.get_artist()) + '</td>'
  output += '<td>' + description + '</td>'
  output += '</tr>'

  ipaContents.close()

output += '</table>'
Пример #45
0
 def getTitleInfo(self,itunes_id):
     return itunes.lookup(itunes_id)