public static LinkedList<String> listaConsigliDaSingoloTag(String tag) {
   LinkedList<String> result = new LinkedList<>();
   for (Track track : AusiliariParte1.consigliDaSingoloTag(tag)) {
     result.add(track.getName());
   }
   return result;
 }
Example #2
0
  public String searchCover(String track, String artist) {
    String urlResult = null;
    String key = "49175f0086374abc087b4774bc075343";

    Caller.getInstance().setCache(null);

    int limit = 30;
    // track="Spirit Indestructible";
    // artist="Nelly Furtado";

    Collection<Track> chart1 = Track.search(artist, track, limit, key);

    if (chart1.isEmpty()) {
      Collection<Artist> artists = Artist.search(artist, key);
      for (Artist artist2 : artists) {
        urlResult = artist2.getImageURL(ImageSize.EXTRALARGE);
        if (urlResult != null) {
          break;
        }
      }
    } else {
      for (Track track2 : chart1) {
        urlResult = track2.getImageURL(ImageSize.EXTRALARGE);
        if (urlResult != null) {
          break;
        }
      }
    }

    if (urlResult == null) {
      urlResult = "http://www.drs3.ch/static/global/logo.gif";
    }

    return urlResult;
  }
 public static Collection<Track> consigliDaSingoloTag(String tag) {
   Collection<Track> completeResult = Tag.getTopTracks(tag, codice);
   LinkedList<String> result = new LinkedList<>();
   for (Track track : completeResult) {
     result.add(track.getName());
   }
   return completeResult;
 }
 public static HashSet<String> ottieniCanzoniAscoltate(String utente) {
   HashSet<String> result = new HashSet<>();
   PaginatedResult<Track> canzoniAscoltate = Library.getTracks(utente, 50, 50, codice);
   for (Track track : canzoniAscoltate) {
     result.add(track.getName());
   }
   return result;
 }
 public static HashMap<String, HashMap<String, Float>> associaPunteggioACanzoni(
     Map<String, Float> mappaPunteggioTag) {
   HashMap<String, HashMap<String, Float>> result = new HashMap<>();
   for (String currentTag : mappaPunteggioTag.keySet()) {
     HashMap<String, Float> canzoniConsigliateDaSingoloTag = new HashMap<>();
     Collection<Track> canzoniConsPaginatedResult = Tag.getTopTracks(currentTag, codice);
     for (Track track : canzoniConsPaginatedResult) {
       canzoniConsigliateDaSingoloTag.put(track.getName(), (mappaPunteggioTag.get(currentTag)));
     }
   }
   return result;
 }
  public static Map<Tripla, HashSet<String>> costruisciMappa(
      Collection<Track> risultatiTop, int numSongInt) throws FileNotFoundException {

    FileOutputStream out;
    PrintStream ps;
    out = new FileOutputStream("myfile.txt");
    ps = new PrintStream(out);

    Map<Tripla, HashSet<String>> result = new HashMap<Tripla, HashSet<String>>();
    Iterator<Track> it = risultatiTop.iterator();
    int i = 0;
    while (it.hasNext() && i < numSongInt) {
      Track currentTrack = it.next();
      String currentArtist = currentTrack.getArtist();
      String currentTitle = currentTrack.getName();
      // .replace(',',' ').toUpperCase();
      // String currentAlbum = currentTrack.getAlbum();
      // int currentPlayCount = 0;
      int currentPlayCount = currentTrack.getPlaycount();
      System.out.println(currentArtist + currentTitle + currentPlayCount);
      Tripla currentTripla = new Tripla(currentArtist, currentTitle, currentPlayCount);
      HashSet<String> currentTotalTags = new HashSet<String>();
      Iterator<Tag> itTag = Track.getTopTags(currentArtist, currentTitle, codice).iterator();

      // TODO metti la macro per il numero di tag da prendere

      while (itTag.hasNext() && currentTotalTags.size() < 5) {
        Tag currentTag = itTag.next();
        int currentTagCount = currentTag.getCount();
        String currentTagName = currentTag.getName().toLowerCase();
        currentTotalTags.add(currentTagName);
      }

      result.put(currentTripla, currentTotalTags);
      i++;
    }

    /*
    System.out.println(result.size());
    for(Entry<Tripla, HashSet<String>> currentEntry : result.entrySet()){
    	System.out.println(currentEntry.getKey().getTitolo());
    	System.out.println(currentEntry.getValue().toString());
    }
    */
    return result;
  }
  /** Create the panel. */
  public ArtistInfoPanel(final ArtistNode a) {
    super();
    NumberFormat nf1 = NumberFormat.getInstance();

    // Own settings
    setBorder(new MatteBorder(1, 1, 1, 1, (Color) new Color(0, 0, 0)));
    setBackground(Color.DARK_GRAY);
    setLayout(new BorderLayout(0, 0));
    Utils.fixSize(this, size);

    // COMPONENTS

    // listener
    MouseListener ML_CLOSE =
        new MouseAdapter() {
          public void mouseClicked(MouseEvent e) {
            GroovesharkConnector.getInstance().stop();
            NavigationPanel.getInstance().hideArtistInfoBox();
          }
        };

    MouseListener ML_CONFIRM =
        new MouseAdapter() {
          public void mouseClicked(MouseEvent e) {
            GroovesharkConnector.getInstance().stop();
            GUI.getInstance().search(a);
            NavigationPanel.getInstance().hideArtistInfoBox();
          }
        };

    // Name panel
    // =========================================================================================
    JPanel namePanel = new JPanel();
    namePanel.setBackground(Color.DARK_GRAY);

    // Name panel / Scrobble label

    this.add(namePanel, BorderLayout.NORTH);
    namePanel.setLayout(new GridLayout(0, 2, 0, 0));

    JPanel upperleftPanel = new JPanel();
    upperleftPanel.setBackground(Color.DARK_GRAY);
    namePanel.add(upperleftPanel);
    upperleftPanel.setLayout(new BorderLayout(0, 0));

    // Name panel / Name label

    JLabel nameTxt = new JLabel(a.getName());
    upperleftPanel.add(nameTxt, BorderLayout.NORTH);
    nameTxt.setForeground(Color.WHITE);
    nameTxt.setHorizontalAlignment(SwingConstants.LEFT);
    nameTxt.setFont(new Font("Tahoma", Font.BOLD, 16));
    JLabel playTxt =
        new JLabel(
            "("
                + nf1.format(a.getScrobbles())
                + " scrobbled tracks, "
                + nf1.format(a.getListener())
                + " listeners)");
    upperleftPanel.add(playTxt, BorderLayout.SOUTH);
    playTxt.setForeground(Color.WHITE);
    playTxt.setHorizontalAlignment(SwingConstants.LEFT);
    playTxt.setFont(new Font("Tahoma", Font.ITALIC, 13));

    JPanel closePanel = new JPanel();
    closePanel.setBackground(Color.DARK_GRAY);
    namePanel.add(closePanel);
    closePanel.setLayout(null);

    CloseButton btnX = new CloseButton("x");
    btnX.resizeButton(20, 20);
    btnX.setBounds(429, 0, 20, 20);
    btnX.addMouseListener(ML_CLOSE);
    closePanel.add(btnX);
    // =========================================================================================

    // content panel
    // =========================================================================================
    JTabbedPane contentPanel = new JTabbedPane(JTabbedPane.LEFT);
    contentPanel.setLayout(new BorderLayout(0, 0));
    contentPanel.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);
    contentPanel.setOpaque(true);
    contentPanel.setBackground(Color.DARK_GRAY);
    contentPanel.setForeground(Color.BLACK);

    // content panel / biography panel

    JScrollPane bioPanel = new JScrollPane();
    bioPanel.setLayout(new ScrollPaneLayout());

    // content panel / biography panel / biography TextArea

    JTextArea bioArea = new SanTextbox(Utils.deleteHTMLfromText(a.getWikiFull()));
    bioArea.setBorder(new LineBorder(new Color(0, 0, 0)));
    bioArea.setBounds(new Rectangle(500, 300));
    bioArea.setBackground(Color.DARK_GRAY);
    bioArea.setForeground(Color.WHITE);
    bioArea.setEditable(false);
    bioArea.setWrapStyleWord(true);
    bioArea.setLineWrap(true);
    bioArea.setSelectionColor(bioArea.getBackground());

    Font f = new Font(Font.SANS_SERIF, Font.PLAIN, 12);
    GridBagConstraints gbc_bioArea = new GridBagConstraints();
    gbc_bioArea.insets = new Insets(0, 0, 5, 0);
    gbc_bioArea.fill = GridBagConstraints.BOTH;
    gbc_bioArea.gridx = 0;
    gbc_bioArea.gridy = 0;
    FontMetrics fm = bioArea.getFontMetrics(f);
    bioArea.setSize(width, fm.getHeight() * bioArea.getLineCount());

    bioPanel.getViewport().setView(bioArea);
    VTextIcon contentIcon = new VTextIcon(contentPanel, "biography", VTextIcon.ROTATE_LEFT);

    // content panel / popular content panel

    JPanel popularPanel = new JPanel();
    popularPanel.setLayout(new GridLayout(1, 0));

    // content panel / popular content panel / container panel

    JPanel container = new JPanel();
    container.setLayout(new BorderLayout());

    // content panel / popular content panel / tracks panel
    JPanel tracksPanel = new JPanel();
    tracksPanel.setLayout(new GridLayout(Settings.TRACKFETCH, 0));
    tracksPanel.setBorder(
        new TitledBorder(
            new BevelBorder(BevelBorder.LOWERED, null, null, null, null),
            "top tracks:",
            TitledBorder.LEADING,
            TitledBorder.TOP,
            null,
            null));
    ContentTrackField.resetList();

    Iterator<Track> t = a.getTopTracks().iterator();

    // content panel / popular content panel / tracks panel / tracks
    for (int z = 0; t.hasNext(); z++) {
      Track track = t.next();
      JLabel feld = new ContentTrackField(track.getListeners());
      Dimension feldd = new Dimension(500, (20 - 3 * z));
      feld.setSize(feldd);
      Font fontor = new Font("Tahoma", z < 2 ? Font.BOLD : Font.PLAIN, 19 - z);
      feld.setFont(fontor);
      feld.setText(track.getName() + " (" + nf1.format(track.getListeners()) + " listeners)");
      tracksPanel.add(feld);
    }
    ContentTrackField.recalc();

    container.add(tracksPanel, BorderLayout.CENTER);

    // content panel / popular content panel / albums panel
    JPanel albumsPanel = new JPanel();
    albumsPanel.setSize(500, 100);
    albumsPanel.setLayout(new GridLayout(Settings.ALBUMFETCH, 0));
    albumsPanel.setBorder(
        new TitledBorder(
            new BevelBorder(BevelBorder.LOWERED, null, null, null, null),
            "top albums:",
            TitledBorder.LEADING,
            TitledBorder.TOP,
            null,
            null));
    ContentAlbumField.resetList();

    Iterator<Album> albI = a.getTopAlbums().iterator();

    // content panel / popular content panel / albums panel / albums
    for (int z = 0; albI.hasNext(); z++) {
      Album album = albI.next();
      JLabel feld = new ContentAlbumField(album.getListeners());
      Dimension feldd = new Dimension(500, (20 - 3 * z));
      feld.setSize(feldd);
      Font fontor = new Font("Tahoma", z < 2 ? Font.BOLD : Font.PLAIN, 19 - 2 * z);
      feld.setFont(fontor);
      feld.setText(album.getName());
      albumsPanel.add(feld);
    }
    ContentAlbumField.recalc();

    container.add(albumsPanel, BorderLayout.SOUTH);

    popularPanel.add(container);
    VTextIcon popularIcon = new VTextIcon(contentPanel, "popular content", VTextIcon.ROTATE_LEFT);

    // content panel / blogpost panel

    JScrollPane postPanel = new JScrollPane();
    postPanel.setLayout(new ScrollPaneLayout());
    postPanel.getVerticalScrollBar().setBlockIncrement(1);
    postPanel.setSize(500, 300);
    VTextIcon blogIcon = new VTextIcon(contentPanel, "blog posts", VTextIcon.ROTATE_LEFT);

    // content panel / blogpost panel / posts list

    JList<BlogPost> list = new JList<BlogPost>();
    DefaultListModel<BlogPost> model = new DefaultListModel<BlogPost>();
    BlogPost[] posts = Utils.sortBlogPostArray(a.getRelatedHypemPosts(), Settings.Sort.BYLIKES);
    if (posts != null) {
      for (BlogPost b : posts) {
        model.addElement(b);
      }
      list.setCellRenderer(new BlogPostListCellRenderer());
    } else {
      list.setSelectionBackground(Color.WHITE);
      list.setBorder(null);
    }
    list.setFixedCellHeight(150);
    list.setModel(model);

    postPanel.getViewport().setView(list);

    // composing the tab order for the content panel
    // 1. popular content, 2. biography, 3. blog posts
    contentPanel.addTab(TABLENGTH, popularIcon, popularPanel);
    contentPanel.addTab(TABLENGTH, contentIcon, bioPanel);
    contentPanel.addTab(TABLENGTH, blogIcon, postPanel);

    // adding the content panel to the main panel
    this.add(contentPanel, BorderLayout.CENTER);
    // =========================================================================================

    // west panel
    // =========================================================================================
    JPanel panel = new JPanel();
    panel.setBorder(new EtchedBorder(EtchedBorder.LOWERED, null, null));
    panel.setBackground(Color.DARK_GRAY);
    panel.setLayout(new BorderLayout(0, 0));

    // west panel / image panel

    JPanel imagePanel = new ImagePanel(a.getLargeImage());
    imagePanel.setBackground(Color.DARK_GRAY);

    panel.add(imagePanel, BorderLayout.CENTER);

    // west panel / tags panel
    JPanel tagsPanel = new JPanel();
    tagsPanel.setLayout(new BorderLayout(0, 0));
    tagsPanel.setBorder(
        new TitledBorder(
            new BevelBorder(BevelBorder.LOWERED, null, null, null, null),
            "tags:",
            TitledBorder.LEADING,
            TitledBorder.TOP,
            null,
            null));
    tagsPanel.setForeground(Color.WHITE);
    tagsPanel.setBackground(Color.DARK_GRAY);

    // west panel / image panel / textfield

    JTextArea tagField = new SanTextbox();
    tagField.setWrapStyleWord(true);
    tagField.setEnabled(false);
    tagField.setEditable(false);
    tagField.setLineWrap(true);
    tagField.setBorder(null);
    tagField.setBackground(null);
    tagField.setForeground(Color.WHITE);

    StringBuilder sb = new StringBuilder();
    for (Iterator<String> i = a.getTags().iterator(); i.hasNext(); ) {
      sb.append(i.next());
      if (i.hasNext()) sb.append(", ");
    }
    tagField.setText(sb.toString());
    tagField.setColumns(10);

    tagsPanel.add(tagField);

    panel.add(tagsPanel, BorderLayout.SOUTH);

    this.add(panel, BorderLayout.WEST);

    // =========================================================================================

    // south panel
    // =========================================================================================
    JPanel musicPanel = new JPanel();
    musicPanel.setBorder(new EtchedBorder(EtchedBorder.LOWERED, null, null));
    // get tracks for element creation
    ArrayList<Track> tracks = (ArrayList<Track>) a.getTopTracks();
    musicPanel.setLayout(new GridLayout(0, 2));
    musicPanel.setBackground(Color.DARK_GRAY);

    // south panel / track play elements (according to artist node information)

    JPanel musicElementsPanel = new JPanel();
    musicElementsPanel.setSize(500, 300);
    musicElementsPanel.setBackground(Color.DARK_GRAY);
    musicPanel.add(musicElementsPanel);
    musicElementsPanel.setLayout(new GridLayout(0, 1));

    if (tracks != null && tracks.size() > 0) {
      for (int i = 0; i < 5; i++) {
        TrackPlayElement element = new TrackPlayElement(a.getName(), tracks.get(i).getName());
        if (element != null) {
          element.setForeground(Color.WHITE);
          musicElementsPanel.add(element);
        }
      }
    }

    JPanel buttonsPanel = new JPanel();
    buttonsPanel.setLayout(null);

    JButton confirmButton = new JButton("<html>Save this artist & do another search</html>");
    confirmButton.setBounds(337, 9, 100, 100);
    confirmButton.addMouseListener(ML_CONFIRM);
    buttonsPanel.add(confirmButton);

    JButton abortButton = new JButton("Go back");
    abortButton.setBounds(337, 120, 99, 23);
    abortButton.addMouseListener(ML_CLOSE);
    buttonsPanel.add(abortButton);

    buttonsPanel.setBackground(Color.DARK_GRAY);

    musicPanel.add(buttonsPanel);

    this.add(musicPanel, BorderLayout.SOUTH);
    Dimension d = new Dimension(500, 150);
    Utils.fixSize(musicPanel, d);

    // =========================================================================================
  }