コード例 #1
0
        public static List <trackObj> getPlaylistsDuplicates(string playlistName)
        {
            PrivateProfile          profile   = api.GetPrivateProfile();
            Paging <SimplePlaylist> playlists = api.GetUserPlaylists(profile.Id);

            Console.WriteLine($"Look at playlist: {playlistName}");
            List <trackObj> processedTracks = new List <trackObj>();
            List <trackObj> rtn             = new List <trackObj>();

            do
            {
                playlists.Items.ForEach(playlist => {
                    if (playlist.Name == playlistName || (playlist.Id == playlistName))
                    {
                        //Console.WriteLine($"Checking playlist: {playlist.Name}");
                        Paging <PlaylistTrack> PTracks = api.GetPlaylistTracks(playlist.Id, "", 100, 0);
                        int counter             = 0;
                        List <FullTrack> tracks = new List <FullTrack>();
                        while (counter < PTracks.Total)
                        {
                            PTracks.Items.ForEach(tr => {
                                tracks.Add(tr.Track);
                            });
                            counter += PTracks.Items.Count;
                            PTracks  = api.GetPlaylistTracks(playlist.Id, "", 100, counter);
                        }
                        //Console.WriteLine("tracks.Total: " + PTracks.Total);
                        tracks.ForEach(track => {
                            if (track != null)
                            {
                                trackObj tO = new trackObj {
                                    albumId      = track.Album.Id,
                                    uri          = track.Uri,
                                    artists      = track.Artists,
                                    artistsNames = track.Artists.Select(r => r.Name).ToList(),
                                    duration     = track.DurationMs,
                                    id           = track.Id,
                                    name         = track.Name.Trim(),
                                    actualName   = getActualSongName(track.Name.Trim()).str,
                                    isRemix      = getActualSongName(track.Name.Trim()).bol
                                };
                                processedTracks.ForEach(pTrack => {
                                    double distance = JaroWinklerDistance.proximity(tO.actualName, pTrack.actualName);
                                    if (distance >= 0.9)
                                    {
                                        List <SimpleArtist> PTDub    = new List <SimpleArtist>();
                                        List <SimpleArtist> PTnonDub = new List <SimpleArtist>();
                                        List <SimpleArtist> tODub    = new List <SimpleArtist>();
                                        List <SimpleArtist> tOnonDub = new List <SimpleArtist>();
                                        pTrack.artists.ForEach(artist => {
                                            double highestDistance = 0.0;
                                            tO.artists.ForEach(artist2 => {
                                                double distance2 = JaroWinklerDistance.proximity(artist.Name, artist2.Name);
                                                if (distance2 > highestDistance)
                                                {
                                                    highestDistance = distance2;
                                                }
                                            });
                                            if (highestDistance >= 0.8)
                                            {
                                                PTDub.Add(artist);
                                            }
                                            else
                                            {
                                                PTnonDub.Add(artist);
                                            }
                                        });
                                        tO.artists.ForEach(artist => {
                                            double highestDistance = 0.0;
                                            pTrack.artists.ForEach(artist2 => {
                                                double distance2 = JaroWinklerDistance.proximity(artist.Name, artist2.Name);
                                                if (distance2 > highestDistance)
                                                {
                                                    highestDistance = distance2;
                                                }
                                            });
                                            if (highestDistance >= 0.8)
                                            {
                                                tODub.Add(artist);
                                            }
                                            else
                                            {
                                                tOnonDub.Add(artist);
                                            }
                                        });
                                        pTrack.dupList.Add(new trackDistance {
                                            distance      = distance,
                                            track         = tO,
                                            nonDupArtists = tOnonDub,
                                            dupArtists    = tODub
                                        });

                                        trackObj tmp = pTrack;
                                        tmp.dupList  = new List <trackDistance>();
                                        tO.dupList.Add(new trackDistance {
                                            distance      = distance,
                                            track         = tmp,
                                            nonDupArtists = PTnonDub,
                                            dupArtists    = PTDub
                                        });
                                    }
                                });
                                processedTracks.Add(tO);
                            }
                        });

                        processedTracks.ForEach(pTrack => {
                            if (pTrack.dupList.Count >= 1)
                            {
                                pTrack.dupList = pTrack.dupList.OrderBy(o => o.distance).ToList();
                                rtn.Add(pTrack);
                                //string joinedString = string.Join(", ", pTrack.dupList);
                                //Console.WriteLine(pTrack.name + ": " + joinedString);
                            }
                        });
                    }
                });
                playlists = api.GetNextPage(playlists);
            } while(playlists.HasNextPage());
            return(rtn);
        }
コード例 #2
0
        private static void PrintUsefulData()
        {
            PrivateProfile profile = api.GetPrivateProfile();
            string         name    = string.IsNullOrEmpty(profile.DisplayName) ? profile.Id : profile.DisplayName;

            Console.WriteLine($"Hello there, {name}!");
            Console.WriteLine("Your playlists:");
            Paging <SimplePlaylist> playlists = api.GetUserPlaylists(profile.Id);

            do
            {
                playlists.Items.ForEach(playlist => {
                    Console.WriteLine($"- ({playlist.Id}){playlist.Name}");
                });
                playlists = api.GetNextPage(playlists);
            } while(playlists.HasNextPage());

            playlists = api.GetUserPlaylists(profile.Id);
            Console.Write("Enter playlist name or ID: ");
            string playlistName = Console.ReadLine();

            Console.WriteLine($"Look at playlist: {playlistName}");
            List <trackObj> processedTracks = new List <trackObj>();

            do
            {
                playlists.Items.ForEach(playlist => {
                    if (playlist.Name == playlistName || (playlist.Id == playlistName))
                    {
                        Console.WriteLine($"Checking playlist: {playlist.Name}");
                        Paging <PlaylistTrack> PTracks = api.GetPlaylistTracks(playlist.Id, "", 100, 0);
                        int counter             = 0;
                        List <FullTrack> tracks = new List <FullTrack>();
                        while (counter < PTracks.Total)
                        {
                            PTracks.Items.ForEach(tr => {
                                tracks.Add(tr.Track);
                            });
                            counter += PTracks.Items.Count;
                            PTracks  = api.GetPlaylistTracks(playlist.Id, "", 100, counter);
                        }
                        Console.WriteLine("tracks.Total: " + PTracks.Total);
                        tracks.ForEach(track => {
                            trackObj tO = new trackObj {
                                albumId      = track.Album.Id,
                                artists      = track.Artists,
                                artistsNames = track.Artists.Select(r => r.Name).ToList(),
                                duration     = track.DurationMs,
                                id           = track.Id,
                                name         = track.Name.Trim(),
                                actualName   = getActualSongName(track.Name.Trim()).str,
                                isRemix      = getActualSongName(track.Name.Trim()).bol
                            };


                            processedTracks.ForEach(pTrack => {
                                double distance = JaroWinklerDistance.proximity(tO.actualName, pTrack.actualName);
                                if (distance >= 0.9)
                                {
                                    trackDistance PTrackDistance = new trackDistance {
                                        distance = distance,
                                        track    = tO
                                    };
                                    trackDistance tOTrackDistance = new trackDistance {
                                        distance = distance,
                                        track    = pTrack
                                    };
                                    pTrack.artists.ForEach(artist => {
                                        double highestDistance = 0.0;
                                        tO.artists.ForEach(artist2 => {
                                            double distance2 = JaroWinklerDistance.proximity(artist.Name, artist2.Name);
                                            if (distance2 > highestDistance)
                                            {
                                                highestDistance = distance2;
                                            }
                                        });
                                        if (highestDistance >= 0.9)
                                        {
                                            PTrackDistance.dupArtists.Add(artist);
                                        }
                                        else
                                        {
                                            PTrackDistance.nonDupArtists.Add(artist);
                                        }
                                    });
                                    tO.artists.ForEach(artist => {
                                        double highestDistance = 0.0;
                                        pTrack.artists.ForEach(artist2 => {
                                            double distance2 = JaroWinklerDistance.proximity(artist.Name, artist2.Name);
                                            if (distance2 > highestDistance)
                                            {
                                                highestDistance = distance2;
                                            }
                                        });
                                        if (highestDistance >= 0.9)
                                        {
                                            tOTrackDistance.dupArtists.Add(artist);
                                        }
                                        else
                                        {
                                            tOTrackDistance.nonDupArtists.Add(artist);
                                        }
                                    });
                                    pTrack.dupList.Add(PTrackDistance);
                                    tO.dupList.Add(tOTrackDistance);
                                }
                            });
                            processedTracks.Add(tO);
                        });

                        processedTracks.ForEach(pTrack => {
                            if (pTrack.dupList.Count >= 1)
                            {
                                pTrack.dupList      = pTrack.dupList.OrderBy(o => o.distance).ToList();
                                string joinedString = string.Join(", ", pTrack.dupList);
                                pTrack.dupList.ForEach(dupTrack => {
                                });
                                //Console.WriteLine(pTrack.name + ": " + joinedString);
                            }
                        });
                    }
                });
                playlists = api.GetNextPage(playlists);
            } while(playlists.HasNextPage());
        }