Skip to content

Commit

Permalink
初步完成下载和链接搜索
Browse files Browse the repository at this point in the history
  • Loading branch information
AnyListen committed Dec 30, 2018
1 parent 4ac1f99 commit 4e1ddfd
Show file tree
Hide file tree
Showing 271 changed files with 93,702 additions and 42 deletions.
119 changes: 119 additions & 0 deletions FishMusic/AnyListen/AnyListen.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using AnyListen.Models;
using AnyListen.Music;

namespace AnyListen
Expand Down Expand Up @@ -39,5 +42,121 @@ public static string GetRealUrl(string url)
var arr = url.Split(new[] {'_', '.'}, StringSplitOptions.RemoveEmptyEntries);
return GetMusic(arr[0]).GetSongUrl(arr[2], arr[1], arr[3]);
}

public static List<SongResult> Search(string type, string key, int page, int size)
{
var item = "search";
var id = "";
if (key.Contains("music.163.com"))
{
type = "wy";
var match = Regex.Match(key, "/(\\w+)\\?id=(\\d+)");
if (match.Success)
{
item = match.Groups[1].Value;
id = match.Groups[2].Value;
}
}
else if (key.Contains("xiami.com"))
{
type = "xm";
var match = Regex.Match(key, "xiami.com/(\\w+)/(\\w+)");
if (match.Success)
{
item = match.Groups[1].Value;
id = match.Groups[2].Value;
}
}
else if (key.Contains("y.qq.com"))
{
type = "qq";
var match = Regex.Match(key, "yqq/(\\w+)/(\\w+)\\.htm");
if (match.Success)
{
item = match.Groups[1].Value;
id = match.Groups[2].Value;
}
}
else if (key.Contains("taihe.com") || key.Contains("baidu.com"))
{
type = "bd";
var match = Regex.Match(key, "com/(\\w+)/(\\w+)");
if (match.Success)
{
item = match.Groups[1].Value;
id = match.Groups[2].Value;
}
}
else if (key.Contains("kugou.com"))
{
type = "kg";
var match = Regex.Match(key, "/(\\w+)/(\\w+)\\.htm");
if (match.Success)
{
item = match.Groups[1].Value;
id = match.Groups[2].Value;
}
}
else if (key.Contains("kuwo.cn"))
{
type = "kw";
var match = Regex.Match(key, "cn/(\\w+)/(\\d+)");
if (match.Success)
{
item = match.Groups[1].Value;
id = match.Groups[2].Value;
}
if (key.Contains("cinfo"))
{
item = "playlist";
id = Regex.Match(key, @"(?<=cinfo_)\d+").Value;
}
if (key.Contains("m.kuwo.cn"))
{
match = Regex.Match(key, "newh5/(\\w+)/[\\s\\S]+?id=(\\d+)");
if (match.Success)
{
item = match.Groups[1].Value;
id = match.Groups[2].Value;
}
}
}
else if (key.Contains("hi-resmusic"))
{
type = "sn";
var match = Regex.Match(key, "album.html[\\s\\S]*?\\?id=(\\d+)");
if (match.Success)
{
item = "album";
id = match.Groups[1].Value;
}
}
List<SongResult> resultList = new List<SongResult>();
var music = GetMusic(type);
switch (item)
{
case "album":
resultList = music.AlbumSearch(id);
break;
case "song":
resultList = music.GetSingleSong(id);
break;
case "artist":
case "singer":
resultList = music.ArtistSearch(id, page, size);
break;
case "playlist":
case "songlist":
case "playsquare":
case "single":
case "collect":
resultList = music.CollectSearch(id, page, size);
break;
default:
resultList = music.SongSearch(key, page, size);
break;
}
return resultList;
}
}
}
8 changes: 2 additions & 6 deletions FishMusic/FishMusic/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Windows;
using System.Windows;

namespace FishMusic
{
Expand All @@ -12,5 +7,6 @@ namespace FishMusic
/// </summary>
public partial class App : Application
{

}
}
32 changes: 32 additions & 0 deletions FishMusic/FishMusic/Converter/BytesSizeConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using System;
using System.Globalization;
using System.Windows;
using System.Windows.Data;

namespace FishMusic.Converter
{
public class BytesSizeConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value == null)
{
return "";
}
var size = (long)value;
var kb = size / 1024.0;
if (kb < 1000)
{
return Math.Round(kb, 0) + "K";
}

var mb = kb / 1024.0;
return Math.Round(mb, 1) + "M";
}

public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
return null;
}
}
}
32 changes: 32 additions & 0 deletions FishMusic/FishMusic/Converter/DateConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using System;
using System.Globalization;
using System.Windows;
using System.Windows.Data;

namespace FishMusic.Converter
{
public class DateConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value == null || parameter == null)
{
return Visibility.Collapsed;
}

if (Boolean.Parse(parameter.ToString()))
{
return ((DateTime) value).ToString("yyyy-MM-dd HH:mm:ss");
}
else
{
return ((DateTime)value).ToString("yyyy-MM-dd");
}
}

public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
return null;
}
}
}
90 changes: 90 additions & 0 deletions FishMusic/FishMusic/Download/DownloadInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
using System;
using AnyListen.Models;
using GalaSoft.MvvmLight;

namespace FishMusic.Download
{
public class DownloadInfo : ViewModelBase
{
public SongResult SongInfo { get; set; }

private int _progress;

public int Progress
{
get => _progress;
set
{
_progress = value;
RaisePropertyChanged("Progress");
}
}

public string DownLink { get; set; }
public string FilePath { get; set; }

public string Id { get; set; }

private DownStatus _status;

public DownStatus Status
{
get => _status;
set
{
_status = value;
RaisePropertyChanged("Status");
}
}

private long _megaBytesDownloaded;

public long MegaBytesDownloaded
{
get => _megaBytesDownloaded;
set
{
_megaBytesDownloaded = value;
RaisePropertyChanged("MegaBytesDownloaded");
}
}

private long _totalBytesToDownload;

public long TotalBytesToDownload
{
get => _totalBytesToDownload;
set
{
_totalBytesToDownload = value;
RaisePropertyChanged("TotalBytesToDownload");
}
}

private long _downloadSpeed;

public long DownloadSpeed
{
get => _downloadSpeed;
set
{
_downloadSpeed = value;
RaisePropertyChanged("DownloadSpeed");
}
}

public DateTime SuccessTime { get; set; }
public DateTime CreateTime { get; set; }
}

public enum DownStatus
{
WAITING,
RUNNING,
PAUSE,
CANCLE,
ERROR,
SUCCESS,
UNKNOWN
}
}
Loading

0 comments on commit 4e1ddfd

Please sign in to comment.