This repository has been archived by the owner on Sep 18, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
124 lines (98 loc) · 3.82 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
from kivy.app import App
from kivy.uix.widget import Widget
from kivy.uix.recycleview import RecycleView
from kivy.uix.floatlayout import FloatLayout
from kivy.uix.tabbedpanel import TabbedPanel
from kivy.uix.label import Label
from kivy.uix.button import Button
from kivy.properties import StringProperty
from kivy.uix.screenmanager import ScreenManager, Screen
from lfm import LfmHelper
import os
import time
import utils
#Global Variables
#Screen Manager
sm = None
songscreen = None
lfm = None #LFM helper object- easy interface to Lfm with caching, threading support
class RV(RecycleView):
def __init__(self, **kwargs):
super(RV, self).__init__(**kwargs)
self.data = []
self.getTracks()
def getTracks(self): #See if data exists and use if possible
global lfm
lfm.getTopTracks(self.datafiller)
def datafiller(self,tracks):
print ('Reached here inside datafiller')
#Got the Tracks now get the artist coverartlink
imagepaths = []
for i in range(len(tracks)):
imagepaths.append(lfm.getArtistCoverPath(tracks[i].artist))
self.data =[{'imagelink':imagepaths[i],'trackname':tracks[i].name,'trackartist':tracks[i].artist} for i in range(len(tracks))]
class GridItem(FloatLayout):
trackname = StringProperty()
trackartist = StringProperty()
imagelink = StringProperty()
def on_press_action(self):
global sm
sm.current='song'
songscreen.update(self.trackname,self.trackartist)
class TopTrackScreen(Screen):
pass
class SongScreen(Screen):
trackname = StringProperty()
trackartist = StringProperty()
listeners = StringProperty()
playcount = StringProperty()
imagelink = StringProperty()
wiki = StringProperty()
lyrics = StringProperty()
duration = StringProperty()
trackimage = StringProperty()
def reset(self):
self.listeners = 'Updating'
self.playcount = 'Updating'
self.wiki = 'fetching'
self.lyrics = 'fetching'
self.duration = 'Updating'
self.trackimage = 'test.png'
tagstackitems = [self.ids.tagstack1,self.ids.tagstack2,self.ids.tagstack3,self.ids.tagstack4,self.ids.tagstack5]
for tagstackitem in tagstackitems:
tagstackitem.text = 'Unavailable'
def update(self,trackname, trackartist):
self.reset()
self.trackname = trackname
self.trackartist = trackartist
lfm.getTrackDetails(trackartist,trackname,self.setDetails)
lfm.getTrackLyrics(trackartist,trackname,self.setLyrics)
def setLyrics(self,lyrics): #Callback Function for setting the lyrics
self.lyrics = lyrics
def setDetails(self,track):
global lfm
#TODO ADD More stuff inside this function
self.playcount = utils.easyreadnum(track.playcount)
self.listeners = utils.easyreadnum(track.listeners)
self.wiki = track.wiki
self.duration = str(track.duration)
self.trackimage = lfm.getTrackCoverPath(track)
tagstackitems = [self.ids.tagstack1,self.ids.tagstack2,self.ids.tagstack3,self.ids.tagstack4,self.ids.tagstack5]
for i in range(len(track.tags)):
tagstackitems[i].text = track.tags[i]
class M4AllApp(App):
def build(self):
self.initilize_global_vars()
global sm
global songscreen
sm = ScreenManager()
sm.add_widget(TopTrackScreen(name='toptracks'))
songscreen = SongScreen(name='song')
sm.add_widget(songscreen)
return sm
def initilize_global_vars(self):
global lfm
root_folder = self.user_data_dir
lfm = LfmHelper(root_folder)
if __name__ == '__main__':
M4AllApp().run()