From 33199f85ca1a55ce6234dff82e1c39a6c43dc4e9 Mon Sep 17 00:00:00 2001
From: 9and3r <9and3r@gmail.com>
Date: Thu, 31 Jul 2014 21:55:25 +0200
Subject: [PATCH] Fixed tracks with no info (name, album, artist)
---
mopidy_touchscreen/.idea/workspace.xml | 111 ++++++++++++++++---------
mopidy_touchscreen/library_screen.py | 32 ++++---
mopidy_touchscreen/list_view.py | 2 +-
mopidy_touchscreen/main_screen.py | 39 ++++++---
mopidy_touchscreen/touch_manager.py | 10 +--
mopidy_touchscreen/touch_screen.py | 5 +-
mopidy_touchscreen/tracklist.py | 4 +-
7 files changed, 132 insertions(+), 71 deletions(-)
diff --git a/mopidy_touchscreen/.idea/workspace.xml b/mopidy_touchscreen/.idea/workspace.xml
index 57cbb9e..263f599 100644
--- a/mopidy_touchscreen/.idea/workspace.xml
+++ b/mopidy_touchscreen/.idea/workspace.xml
@@ -23,13 +23,25 @@
-
-
+
+
-
-
+
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -46,13 +58,14 @@
@@ -435,27 +448,6 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -463,37 +455,78 @@
-
+
-
-
+
+
+
+
+
-
-
+
+
+
-
+
-
-
+
+
+
+
+
+
+
+
+
+
+
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/mopidy_touchscreen/library_screen.py b/mopidy_touchscreen/library_screen.py
index ce68662..212d037 100644
--- a/mopidy_touchscreen/library_screen.py
+++ b/mopidy_touchscreen/library_screen.py
@@ -1,4 +1,5 @@
from .list_view import ListView
+from .touch_manager import TouchManager
import logging
import mopidy.models
@@ -44,19 +45,28 @@ class LibraryScreen():
def touch_event(self, touch_event):
clicked = self.list_view.touch_event(touch_event)
if clicked is not None:
- if self.current_directory is not None:
- if clicked == 0:
- self.go_up_directory()
- else:
- if self.library[clicked-1].type == mopidy.models.Ref.TRACK:
- self.play_uri(self.library[clicked-1].uri)
+ if touch_event.type == TouchManager.long_click:
+ if self.current_directory is not None:
+ if clicked == 0:
+ self.go_up_directory()
else:
- self.go_inside_directory(self.library[clicked-1].uri)
- else:
- if self.library[clicked].type == mopidy.models.Track:
- self.play_uri(self.library[clicked].uri)
+ self.play_uri(self.library[clicked-1].uri)
else:
- self.go_inside_directory(self.library[clicked].uri)
+ self.play_uri(self.library[clicked].uri)
+ else:
+ if self.current_directory is not None:
+ if clicked == 0:
+ self.go_up_directory()
+ else:
+ if self.library[clicked-1].type == mopidy.models.Ref.TRACK:
+ self.play_uri(self.library[clicked-1].uri)
+ else:
+ self.go_inside_directory(self.library[clicked-1].uri)
+ else:
+ if self.library[clicked].type == mopidy.models.Track:
+ self.play_uri(self.library[clicked].uri)
+ else:
+ self.go_inside_directory(self.library[clicked].uri)
def play_uri(self, uri):
self.manager.core.tracklist.clear()
diff --git a/mopidy_touchscreen/list_view.py b/mopidy_touchscreen/list_view.py
index 7065159..1d76297 100644
--- a/mopidy_touchscreen/list_view.py
+++ b/mopidy_touchscreen/list_view.py
@@ -57,7 +57,7 @@ class ListView():
self.screen_objects.render(surface)
def touch_event(self, touch_event):
- if touch_event.type == TouchManager.click:
+ if touch_event.type == TouchManager.click or touch_event.type == TouchManager.long_click:
objects = self.screen_objects.get_touch_objects_in_pos(touch_event.current_pos)
if objects is not None:
for key in objects:
diff --git a/mopidy_touchscreen/main_screen.py b/mopidy_touchscreen/main_screen.py
index 89d7594..eed3c69 100644
--- a/mopidy_touchscreen/main_screen.py
+++ b/mopidy_touchscreen/main_screen.py
@@ -45,11 +45,11 @@ class MainScreen():
self.artists.append(artist)
#Track name
- label = TextItem(self.fonts['base'], track.name, (x, self.base_size * 2), (width, self.size[1]))
+ label = TextItem(self.fonts['base'], MainScreen.get_track_name(track), (x, self.base_size * 2), (width, self.size[1]))
self.touch_text_manager.set_object("track_name", label)
#Album name
- label = TextItem(self.fonts['base'], track.album.name, (x, self.base_size * 3), (width, self.size[1]))
+ label = TextItem(self.fonts['base'], MainScreen.get_track_album_name(track), (x, self.base_size * 3), (width, self.size[1]))
self.touch_text_manager.set_object("album_name", label)
#Artist
@@ -80,15 +80,17 @@ class MainScreen():
self.load_image()
def get_artist_string(self):
- artists_strign = ''
+ artists_string = ''
for artist in self.artists:
- artists_strign += artist.name + ', '
- if len(artists_strign) > 2:
- artists_strign = artists_strign[:-2]
- return artists_strign
+ artists_string += artist.name + ', '
+ if len(artists_string) > 2:
+ artists_string = artists_string[:-2]
+ elif len(artists_string) == 0:
+ artists_string = "Unknow Artist"
+ return artists_string
def get_image_file_name(self):
- name = self.track.album.name + '-' + self.get_artist_string()
+ name = MainScreen.get_track_album_name(self.track) + '-' + self.get_artist_string()
md5name = hashlib.md5(name.encode('utf-8')).hexdigest()
return md5name
@@ -105,7 +107,7 @@ class MainScreen():
if artist_index < len(self.artists):
try:
safe_artist = urllib.quote_plus(self.artists[artist_index].name)
- safe_album = urllib.quote_plus(self.track.album.name)
+ safe_album = urllib.quote_plus(MainScreen.get_track_album_name(self.track))
url = "http://ws.audioscrobbler.com/2.0/?"
params = "method=album.getinfo&api_key=59a04c6a73fb99d6e8996e01db306829&artist=" + safe_artist + "&album=" + safe_album + "&format=json"
response = urllib2.urlopen(url + params)
@@ -122,11 +124,11 @@ class MainScreen():
# There is no cover so it will use all the screen size for the text
width = self.size[0] - self.base_size
- current = TextItem(self.fonts['base'], self.track.name, (self.base_size / 2, self.base_size * 2),
+ current = TextItem(self.fonts['base'], MainScreen.get_track_name(self.track), (self.base_size / 2, self.base_size * 2),
(width, self.base_size))
self.touch_text_manager.set_object("track_name", current)
- current = TextItem(self.fonts['base'], self.track.album.name, (self.base_size / 2, self.base_size * 3),
+ current = TextItem(self.fonts['base'], MainScreen.get_track_album_name(self.track), (self.base_size / 2, self.base_size * 3),
(width, self.base_size))
self.touch_text_manager.set_object("album_name", current)
@@ -168,3 +170,18 @@ class MainScreen():
volume = 0
self.manager.backend.tell({'action': 'volume', 'value': volume})
self.manager.volume_changed(volume)
+
+ @staticmethod
+ def get_track_name(track):
+ if track.name is None:
+ return track.uri
+ else:
+ return track.name
+
+ @staticmethod
+ def get_track_album_name(track):
+ if track.album is not None and track.album.name is not None and len(track.album.name)>0:
+ return track.album.name
+ else:
+ return "Unknow Album"
+
diff --git a/mopidy_touchscreen/touch_manager.py b/mopidy_touchscreen/touch_manager.py
index 1e780eb..61a5b6b 100644
--- a/mopidy_touchscreen/touch_manager.py
+++ b/mopidy_touchscreen/touch_manager.py
@@ -28,7 +28,9 @@ class TouchManager():
self.down_time = -1
def event(self, event):
+
if event.type == pygame.MOUSEBUTTONUP:
+ logger.error(event.button)
if event.button == 4:
touch_event = TouchEvent(TouchManager.swipe, self.down_pos, self.up_pos, True)
touch_event.direction = TouchManager.up
@@ -40,9 +42,9 @@ class TouchManager():
elif event.button == 1 and self.down_button == 1:
touch_event = self.mouse_up(event)
return touch_event
- elif event.button == 2 and self.down_button == 2:
+ elif event.button == 3 and self.down_button == 3:
touch_event = TouchEvent(TouchManager.long_click, self.down_pos, self.up_pos, None)
- return TouchEvent
+ return touch_event
else:
return None
elif event.type == pygame.MOUSEBUTTONDOWN:
@@ -55,13 +57,11 @@ class TouchManager():
self.down_time = time.time()
def mouse_up(self, event):
+ logger.error(event.button)
self.up_pos = event.pos
if abs(self.down_pos[0] - self.up_pos[0]) < self.max_move_margin:
if abs(self.down_pos[1] - self.up_pos[1]) < self.max_move_margin:
- logger.error(time.time())
- logger.error(self.down_time)
if time.time() - TouchManager.long_click_min_time > self.down_time:
- logger.error("longpress")
return TouchEvent(TouchManager.long_click, self.down_pos, self.up_pos, None)
else:
return TouchEvent(TouchManager.click, self.down_pos, self.up_pos, None)
diff --git a/mopidy_touchscreen/touch_screen.py b/mopidy_touchscreen/touch_screen.py
index 37b31e7..b17494f 100644
--- a/mopidy_touchscreen/touch_screen.py
+++ b/mopidy_touchscreen/touch_screen.py
@@ -39,9 +39,10 @@ class TouchScreen(pykka.ThreadingActor, core.CoreListener):
for event in pygame.event.get():
if event.type == pygame.QUIT:
self.running = False
- if event.type == pygame.KEYUP and event.key == pygame.K_q:
+ elif event.type == pygame.KEYUP and event.key == pygame.K_q:
self.running = False
- self.screen_manager.event(event)
+ else:
+ self.screen_manager.event(event)
pygame.quit()
def on_start(self):
diff --git a/mopidy_touchscreen/tracklist.py b/mopidy_touchscreen/tracklist.py
index a5eae91..409ed1e 100644
--- a/mopidy_touchscreen/tracklist.py
+++ b/mopidy_touchscreen/tracklist.py
@@ -1,5 +1,5 @@
from .list_view import ListView
-
+from .main_screen import MainScreen
class Tracklist():
@@ -22,7 +22,7 @@ class Tracklist():
self.tracks = self.manager.core.tracklist.tl_tracks.get()
self.tracks_strings = []
for tl_track in self.tracks:
- self.tracks_strings.append(tl_track.track.name)
+ self.tracks_strings.append(MainScreen.get_track_name(tl_track.track))
self.list_view.set_list(self.tracks_strings)
def touch_event(self, touch_event):