lastfm_tags.py
Go to the documentation of this file.
1 
2 import os
3 import sys
4 import pickle
5 
6 from xml.dom import minidom
7 import urllib2 #call url function
8 import time
9 import sqlite3
10 import cPickle
11 
12 import pyechonest # import echonest API
13 import pylast # import last.fm API
14 from pyechonest import artist, catalog, config, playlist # How it works instead of pyechonest
15 
16 
17 #change the path to 7-digital python library
18 sys.path.append("./7digital-python/lib/")
19 import py7digital
20 
21 """ API Key from echonest """
22 #Your API Key: SFXNKMTRAZ3ULHK6U
23 #Your Consumer Key: 54a06c9bd235d47f787d8cf614577a94
24 #Your Shared Secret: aiPUaTToTpixW4Ttaf4O9A
25 
26 """API key from 7 digital"""
27 # oauth_consumer_key=7dbpa63h3y3d
28 # oauth_consumer_secret=zz48d4epsqmrsuvp
29 
30 """API key from last.fm"""
31 # Your API Key is bd1cb09de31188b43aa46f39b8e40614
32 # Your secret is d2537b0ce8bc859a6068833c5e2a72a7
33 
34 """"*********************************************************************************"""
35 
36 # Echo Nest API key
37 config.ECHO_NEST_API_KEY="SFXNKMTRAZ3ULHK6U "
38 
39 # 7 digital API key
40 DIGITAL7_API_KEY = '7dbpa63h3y3d'
41 
42 
43 """The use of last.fm API"""
44 API_KEY = "bd1cb09de31188b43aa46f39b8e40614"
45 API_SECRET = "d2537b0ce8bc859a6068833c5e2a72a7"
46 
47 """Authentication, username and password"""
48 username = "QMYading"
49 password_hash = pylast.md5("123456")
50 network = pylast.LastFMNetwork(api_key = API_KEY, api_secret =
51  API_SECRET, username = username, password_hash = password_hash)
52 
53 # get artist object
54 # artist_object = network.get_artist("System of a Down")
55 
56 # get the mbid for the tracks
57 # print(artist_object.get_mbid())
58 
59 # print(os.getcwd()) #print current working directory
60 # artist_object.shout("Artist object created successful!")
61 
62 # get track object
63 
64 track_object = network.get_track("Adele","Someone like you")
65 
66 print track_object.get_tag()
67 
68 
69 """
70 # track_object.add_tags(("awesome", "favorite")) # add tags to the tracks
71 
72 #get get_album object
73 #album_object = network.get_album("Adele","21")
74 
75 # get tags object
76 #os.chdir('./Resuls/')
77 tag_classification = ["Happy"]
78 
79 
80 # search for similar tag according to the seeds in tag_classification
81 for tags_name in tag_classification:
82 
83  tags = network.search_for_tag(tags_name)
84  print tags
85  tags_info = tags.get_next_page()
86 
87  #print tags_info
88  #print tags_search
89  #tag_file_name = tags_name + "_tags_results.txt"
90 
91  #tag_data = open(tag_file_name, 'wb') # open and write the file for top tags
92 
93  #os.makedirs(str(tags_name))
94  #os.chdir('./' + str(tags_name) + '/')
95 
96 """