Esempio n. 1
0
def Radios(sender, user):
    dir = MediaContainer(title2=sender.itemTitle)
    name = None
    if LastFm.IsCurrentUser(user):
        name = "your"
    else:
        userName = LastFm.UserDetails(user)[0]
        name = user + "'s"
        if userName != None:
            name = userName + "'s"

    libraryRadio = "user/%s/library" % user
    dir.Append(
        Function(DirectoryItem(PlayRadio, "Play " + name + " Library Radio"),
                 radioName=libraryRadio))
    lovedRadio = "user/%s/loved" % user
    dir.Append(
        Function(DirectoryItem(PlayRadio,
                               "Play " + name + " Loved Tracks Radio"),
                 radioName=lovedRadio))
    recommendedRadio = "user/%s/recommended" % user
    dir.Append(
        Function(DirectoryItem(PlayRadio,
                               "Play " + name + " Recommendations Radio"),
                 radioName=recommendedRadio))
    neighoursRadio = "user/%s/neighbours" % user
    dir.Append(
        Function(DirectoryItem(PlayRadio,
                               "Play " + name + " Neighbourhood Radio"),
                 radioName=neighoursRadio))
    return dir
Esempio n. 2
0
def ArtistDirectory(sender, artist):
    dir = MediaContainer(title2=sender.itemTitle)
    radioTitle = "Play " + artist[0] + " Radio"
    if LastFm.IsSubscriber():
        radioName = "artist/%s/similarartists" % String.Quote(artist[0], True)
        dir.Append(
            Function(DirectoryItem(PlayRadio, radioTitle, thumb=artist[1]),
                     radioName=radioName))
    dir.Append(
        Function(DirectoryItem(SimilarArtists,
                               title="Similar Artists",
                               thumb=artist[1]),
                 artist=artist))
    dir.Append(
        Function(DirectoryItem(Videos,
                               title="Videos",
                               thumb=artist[1],
                               summary=None),
                 artist=artist))
    dir.Append(
        Function(DirectoryItem(ArtistTracks,
                               title="Tracks",
                               thumb=artist[1],
                               summary=None),
                 artist=artist))
    dir.Append(
        Function(DirectoryItem(ArtistAlbums,
                               title="Albums",
                               thumb=artist[1],
                               summary=None),
                 artist=artist))
    return dir
Esempio n. 3
0
def SimilarTags(sender, tag):
    dir = MediaContainer(title2=sender.itemTitle)
    for similarTag in LastFm.SimilarTags(tag):
        dir.Append(
            Function(DirectoryItem(Category, title=similarTag[0].capitalize()),
                     tag=similarTag))
    return dir
class LastFmWallpaperUpdater():

    def __init__(self, username):
        self.username = username
        self.wallpaper_path = ''
        self.total_scrobblings = None
        self.week_artists = None
        self.modified_image = None
        self.new_image_path = ""

    def update_wallpaper(self):
        if not self.wallpaper_path:
            self.obtain_wallpaper_path()

        self.obtain_lastfm_data()
        self.generate_new_image()
        self.generate_new_image_path()
        self.modified_image.save(self.new_image_path,'JPEG')
        self.set_new_wallpaper()

    def obtain_wallpaper_path(self):
        self.background_manager = BackgroundManager()
        self.wallpaper_uri = self.background_manager.getWallpaperUri()
        self.wallpaper_path = urlparse.urlparse(self.wallpaper_uri).path

    def set_new_wallpaper(self):
        self.background_manager = BackgroundManager()
        self.wallpaper_uri = self.background_manager.setWallpaperUri('file://' + self.new_image_path)

    def obtain_lastfm_data(self):
        self.my_lastfm = LastFm(self.username)
        self.total_scrobblings = self.my_lastfm.get_number_scrobblings()
        self.week_artists = self.my_lastfm.get_week_artist(3)

    def generate_new_image(self):
        print 'Base image: ' + self.wallpaper_path
        self.image_updater = ImageUpdater(self.wallpaper_path)
        self.image_updater.add_username(self.username)
        self.image_updater.add_scrobblings(self.total_scrobblings)
        self.image_updater.weekly_chart(self.week_artists)
        self.modified_image = self.image_updater.get_base_image()

    def generate_new_image_path(self):
        self.new_image_path = self.wallpaper_path[:(self.wallpaper_path.rfind('.')-1)]
        self.new_image_path += '$'
        self.new_image_path += self.wallpaper_path[self.wallpaper_path.rfind('.'):]
Esempio n. 5
0
def Library(sender, user):
    dir = MediaContainer(title2=sender.itemTitle)
    if LastFm.IsSubscriber():
        title = None
        if LastFm.IsCurrentUser(user):
            title = "Play your Library"
        else:
            userName = LastFm.UserDetails(user)[0]
            title = "Play " + user + "'s Library"
            if userName != None:
                title = "Play " + userName + "'s Library"
        radioName = "user/%s/library" % user
        dir.Append(
            Function(DirectoryItem(PlayRadio, title), radioName=radioName))
    dir.Append(Function(DirectoryItem(LibraryAlbums, "Albums"), user=user))
    dir.Append(Function(DirectoryItem(LibraryArtists, "Artists"), user=user))
    dir.Append(Function(DirectoryItem(LibraryTracks, "Tracks"), user=user))
    return dir
Esempio n. 6
0
def SearchAlbumsResults(sender, query, page=1):
    results = LastFm.SearchAlbums(query, page)
    dir = AppendAlbums(sender, results[0])
    if results[1]:
        dir.Append(
            Function(DirectoryItem(SearchAlbumsResults, "More ..."),
                     query=query,
                     page=page + 1))
    return dir
Esempio n. 7
0
def LovedTracks(sender, user, page=1):
    tracksTuple = LastFm.LovedTracks(user, page)
    dir = AppendTracks(sender, tracksTuple[0])
    if tracksTuple[1]:
        dir.Append(
            Function(DirectoryItem(LovedTracks, "More ..."),
                     user=user,
                     page=page + 1))
    return dir
Esempio n. 8
0
class LastFmTest(unittest.TestCase):

    def setUp(self):
        self.my_lastfm = LastFm('figarocorso')

    def testConection(self):
       self.assertEqual('figarocorso', self.my_lastfm.get_username())

    def tearDown(self):
        pass
Esempio n. 9
0
def Friends(sender, user):
    dir = MediaContainer(title2=sender.itemTitle)
    friends = LastFm.Friends(user)
    for friend in friends:
        name = friend[0]
        if friend[1] != None:
            name = friend[1]
        dir.Append(
            Function(DirectoryItem(UserDirectory, title=name, thumb=friend[2]),
                     user=friend[0]))
    return dir
Esempio n. 10
0
def MainMenu():
    dir = MediaContainer(mediaType='music', noCache=True)
    if LastFm.IsAuthenticated():
        user = LastFm.CurrentUser()
        if LastFm.IsSubscriber():
            dir.Append(Function(DirectoryItem(Radios, "Radios"), user=user))
        dir.Append(Function(DirectoryItem(Library, "Library"), user=user))
        dir.Append(
            Function(DirectoryItem(RecentTracks, "Recent Tracks"), user=user))
        dir.Append(
            Function(DirectoryItem(LovedTracks, "Loved Tracks"), user=user))
        dir.Append(
            Function(DirectoryItem(RecommendedArtists, "Recommended Artists")))
        dir.Append(Function(DirectoryItem(Friends, "Friends"), user=user))
        dir.Append(Function(DirectoryItem(Neighbours, "Neighbours"),
                            user=user))

        dir.Append(Function(DirectoryItem(GlobalTopTags, "Top Tags")))

        dir.Append(
            Function(
                InputDirectoryItem(SearchTagsResults,
                                   title="Search Tags ...",
                                   prompt="Search Tags",
                                   thumb=S('Search'))))
        dir.Append(
            Function(
                InputDirectoryItem(SearchArtistsResults,
                                   title="Search Artists ...",
                                   prompt="Search Artists",
                                   thumb=S('Search'))))
        dir.Append(
            Function(
                InputDirectoryItem(SearchAlbumsResults,
                                   title="Search Albums ...",
                                   prompt="Search Albums",
                                   thumb=S('Search'))))
    dir.Append(PrefsItem(L("Preferences ..."), thumb=R('icon-prefs.png')))
    return dir
Esempio n. 11
0
def SearchTagsResults(sender, query, page=1):
    dir = MediaContainer(title2=sender.itemTitle)
    results = LastFm.SearchTags(query, page)
    for tag in results[0]:
        dir.Append(
            Function(DirectoryItem(Category, title=tag[0].capitalize()),
                     tag=tag))
    if results[1]:
        dir.Append(
            Function(DirectoryItem(SearchTagsResults, "More ..."),
                     query=query,
                     page=page + 1))
    return dir
Esempio n. 12
0
def Neighbours(sender, user):
    dir = MediaContainer(title2=sender.itemTitle)
    neighbours = LastFm.Neighbours(user)
    for neighbour in neighbours:
        name = neighbour[0]
        if neighbour[1] != None:
            name = neighbour[1]
        dir.Append(
            Function(DirectoryItem(UserDirectory,
                                   title=name,
                                   thumb=neighbour[2]),
                     user=neighbour[0]))
    return dir
Esempio n. 13
0
def Category(sender, tag):
    dir = MediaContainer(title2=sender.itemTitle)
    radioTitle = "Play " + tag[0].capitalize() + " Radio"
    if LastFm.IsSubscriber():
        radioName = "globaltags/%s" % String.Quote(tag[0], True)
        dir.Append(
            Function(DirectoryItem(PlayRadio, radioTitle),
                     radioName=radioName))

    dir.Append(Function(DirectoryItem(TagTopArtists, "Top Artists"), tag=tag))
    dir.Append(Function(DirectoryItem(TagTopAlbums, "Top Albums"), tag=tag))
    dir.Append(Function(DirectoryItem(TagTopTracks, "Top Tracks"), tag=tag))
    dir.Append(Function(DirectoryItem(SimilarTags, "Similar Tags"), tag=tag))
    return dir
Esempio n. 14
0
def Videos(sender, artist, page=1):
    dir = MediaContainer(mediaType='video', title2=sender.itemTitle)
    videos = LastFm.ArtistVideos(artist[0], page)
    for video in videos[0]:

        isYouTube = IsYouTube(video[1])
        if (isYouTube):
            videoUrl = YouTubeVideoUrl(video)
            dir.Append(VideoItem(videoUrl, title=video[0], thumb=video[1]))
        else:
            videoUrl = LastFmVideoUrl(video, artist)
            dir.Append(VideoItem(videoUrl, title=video[0], thumb=video[1]))
    if videos[1]:
        dir.Append(
            Function(DirectoryItem(Videos, title="More ..."),
                     artist=artist,
                     page=page + 1))
    return dir
Esempio n. 15
0
def PlayRadio(sender, radioName):
    if not Dict.HasKey(radioName):
        newRadio = LastFm.Radio(radioName)
        Dict.Set(radioName, newRadio)
    radio = Dict.Get(radioName)
    dir = MediaContainer(title2=sender.itemTitle, noCache=True)

    track = radio.nextTrack()
    title = track[0] + " - " + track[1]
    image = track[2]
    location = track[3]
    duration = track[4]
    dir.Append(
        TrackItem(location,
                  title=title,
                  subtitle=None,
                  thumb=image,
                  duration=duration))
    return dir
Esempio n. 16
0
def ValidatePrefs():
    LastFm.Authenticate()
Esempio n. 17
0
def LibraryArtists(sender, user):
    libraryArtists = LastFm.LibraryArtists(user)
    return AppendArtists(sender, libraryArtists)
 def obtain_lastfm_data(self):
     self.my_lastfm = LastFm(self.username)
     self.total_scrobblings = self.my_lastfm.get_number_scrobblings()
     self.week_artists = self.my_lastfm.get_week_artist(3)
Esempio n. 19
0
def RecentTracks(sender, user):
    recentTracks = LastFm.RecentTracks(user)
    return AppendTracks(sender, recentTracks)
Esempio n. 20
0
def SimilarArtists(sender, artist):
    similarArtists = LastFm.SimilarArtists(artist[0])
    return AppendArtists(sender, similarArtists)
Esempio n. 21
0
def TagTopTracks(sender, tag):
    return AppendTracks(sender, LastFm.TagTopTracks(tag[0]))
Esempio n. 22
0
def TagTopAlbums(sender, tag):
    return AppendAlbums(sender, LastFm.TagTopAlbums(tag[0]))
Esempio n. 23
0
def TagTopArtists(sender, tag):
    return AppendArtists(sender, LastFm.TagTopArtists(tag[0]))
Esempio n. 24
0
def GlobalTopTags(sender):
    return TagList(sender, LastFm.GlobalTopTags())
Esempio n. 25
0
def ArtistAlbums(sender, artist):
    artistAlbums = LastFm.ArtistAlbums(artist[0])
    return AppendAlbums(sender, artistAlbums)
Esempio n. 26
0
def ArtistTracks(sender, artist):
    artistTracks = LastFm.ArtistTracks(artist[0])
    return AppendTracks(sender, artistTracks)
Esempio n. 27
0
 def setUp(self):
     self.my_lastfm = LastFm('figarocorso')
Esempio n. 28
0
def RecommendedArtists(sender):
    return AppendArtists(sender, LastFm.RecommendedArtists())
Esempio n. 29
0
def AlbumDirectory(sender, album):
    trackList = LastFm.AlbumTrackList(album[1], album[0])
    return AppendTracks(sender, trackList)
Esempio n. 30
0
def LibraryAlbums(sender, user):
    libraryAlbums = LastFm.LibraryAlbums(user)
    return AppendAlbums(sender, libraryAlbums)