Revisión | 256 (tree) |
---|---|
Tiempo | 2017-03-06 00:09:54 |
Autor | rankingloid |
Cope with the new niconico API (Thanks to Marky-san)
@@ -1403,6 +1403,7 @@ | ||
1403 | 1403 | } |
1404 | 1404 | } |
1405 | 1405 | |
1406 | + /* | |
1406 | 1407 | private string GetSearchKeywordOrTagByAPI(string word, int page, SearchSortMethod sort_method, SearchOrder order, bool is_tag) |
1407 | 1408 | { |
1408 | 1409 | CheckCookie(); |
@@ -1473,7 +1474,80 @@ | ||
1473 | 1474 | network_.Reset(); |
1474 | 1475 | } |
1475 | 1476 | } |
1477 | + */ | |
1476 | 1478 | |
1479 | + //2017-03-03 UPDATE marky 検索API v2 | |
1480 | + private string GetSearchKeywordOrTagByAPI(string word, int page, SearchSortMethod sort_method, SearchOrder order, bool is_tag) | |
1481 | + { | |
1482 | + CheckCookie(); | |
1483 | + | |
1484 | + if (is_no_cache_) | |
1485 | + { | |
1486 | + network_.SetMaxAgeZero(); | |
1487 | + } | |
1488 | + try | |
1489 | + { | |
1490 | + string json = "q="; | |
1491 | + json += word; | |
1492 | + json += "&targets="; | |
1493 | + if (is_tag) | |
1494 | + { // tag search | |
1495 | + json += "tagsExact"; | |
1496 | + } | |
1497 | + else | |
1498 | + { // keyword search | |
1499 | + json += "title,description,tags"; | |
1500 | + } | |
1501 | + json += "&fields=contentId,title,description,tags,categoryTags,viewCounter,mylistCounter,commentCounter,startTime,thumbnailUrl,lengthSeconds"; | |
1502 | + | |
1503 | + json += "&_sort="; | |
1504 | + if (order == SearchOrder.Asc) | |
1505 | + { | |
1506 | + json += "+"; | |
1507 | + } | |
1508 | + else | |
1509 | + { | |
1510 | + json += "-"; | |
1511 | + } | |
1512 | + switch (sort_method) | |
1513 | + { | |
1514 | + case SearchSortMethod.ResNew: | |
1515 | + json += "lastCommentTime"; | |
1516 | + break; | |
1517 | + case SearchSortMethod.View: | |
1518 | + json += "viewCounter"; | |
1519 | + break; | |
1520 | + case SearchSortMethod.SubmitDate: | |
1521 | + json += "startTime"; | |
1522 | + break; | |
1523 | + case SearchSortMethod.Mylist: | |
1524 | + json += "mylistCounter"; | |
1525 | + break; | |
1526 | + case SearchSortMethod.Res: | |
1527 | + json += "commentCounter"; | |
1528 | + break; | |
1529 | + case SearchSortMethod.Time: | |
1530 | + json += "lengthSeconds"; | |
1531 | + break; | |
1532 | + } | |
1533 | + | |
1534 | + json += "&_offset="; | |
1535 | + json += ((page - 1) * 100).ToString(); | |
1536 | + json += "&_limit=100"; | |
1537 | + json += "&_context=" + issuer_ ; | |
1538 | + | |
1539 | + network_.SetDefaultContentType(); | |
1540 | + string str = network_.GetAndReadFromWebUTF8("http://api.search.nicovideo.jp/api/v2/snapshot/video/contents/search?" + json); | |
1541 | + | |
1542 | + //CheckDenied(str); | |
1543 | + return str; | |
1544 | + } | |
1545 | + finally | |
1546 | + { | |
1547 | + network_.Reset(); | |
1548 | + } | |
1549 | + } | |
1550 | + | |
1477 | 1551 | /// <summary> |
1478 | 1552 | /// タグ検索、キーワード検索のURLオプションを取得 |
1479 | 1553 | /// </summary> |
@@ -952,6 +952,7 @@ | ||
952 | 952 | return ParseSearchFromAPI(json, -1); |
953 | 953 | } |
954 | 954 | |
955 | + /* | |
955 | 956 | // 前から start_num - 1 件は捨てる |
956 | 957 | // start_num が -1 なら全件登録 |
957 | 958 | public static List<Video> ParseSearchFromAPI(string json, int start_num) |
@@ -996,7 +997,53 @@ | ||
996 | 997 | } |
997 | 998 | return list; |
998 | 999 | } |
1000 | + */ | |
999 | 1001 | |
1002 | + //2017-03-03 UPDATE marky 検索API v2 | |
1003 | + // 前から start_num - 1 件は捨てる | |
1004 | + // start_num が -1 なら全件登録 | |
1005 | + public static List<Video> ParseSearchFromAPI(string json, int start_num) | |
1006 | + { | |
1007 | + List<Video> list = new List<Video>(); | |
1008 | + int count = 0; | |
1009 | + | |
1010 | + string[] ar = json.Split(new char[] { '\n' }, StringSplitOptions.RemoveEmptyEntries); | |
1011 | + | |
1012 | + for (int i = 0; i < ar.Length; ++i) | |
1013 | + { | |
1014 | + DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(NiconicoAPIResult)); | |
1015 | + using (MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(ar[i]))) | |
1016 | + { | |
1017 | + NiconicoAPIResult result = (NiconicoAPIResult)serializer.ReadObject(ms); | |
1018 | + if (result.data != null) | |
1019 | + { | |
1020 | + for (int j = 0; j < result.data.Count; ++j) | |
1021 | + { | |
1022 | + if (!string.IsNullOrEmpty(result.data[j].contentId)) | |
1023 | + { | |
1024 | + Video video = new Video(); | |
1025 | + video.video_id = result.data[j].contentId; | |
1026 | + video.point.view = int.Parse(result.data[j].viewCounter); | |
1027 | + video.point.res = int.Parse(result.data[j].commentCounter); | |
1028 | + video.point.mylist = int.Parse(result.data[j].mylistCounter); | |
1029 | + video.title = result.data[j].title; | |
1030 | + video.submit_date = DateTime.Parse(result.data[j].startTime, null, System.Globalization.DateTimeStyles.RoundtripKind); | |
1031 | + video.thumbnail_url = result.data[j].thumbnailUrl; | |
1032 | + video.length = result.data[j].lengthSeconds; | |
1033 | + video.tag_set.ParseBlank(result.data[j].tags); | |
1034 | + ++count; | |
1035 | + if (count >= start_num) | |
1036 | + { | |
1037 | + list.Add(video); | |
1038 | + } | |
1039 | + } | |
1040 | + } | |
1041 | + } | |
1042 | + } | |
1043 | + } | |
1044 | + return list; | |
1045 | + } | |
1046 | + | |
1000 | 1047 | // 冗長検索ロジック(1回(冗長検索無し)) |
1001 | 1048 | private List<Video> MakeListBySearchAPI(SearchingTagOption option, ref int log_number) |
1002 | 1049 | { |
@@ -1265,6 +1312,7 @@ | ||
1265 | 1312 | } |
1266 | 1313 | } |
1267 | 1314 | |
1315 | + /* | |
1268 | 1316 | [DataContract] |
1269 | 1317 | class NiconicoAPIResult |
1270 | 1318 | { |
@@ -1314,4 +1362,66 @@ | ||
1314 | 1362 | public string view_counter = ""; |
1315 | 1363 | } |
1316 | 1364 | } |
1365 | + */ | |
1366 | + | |
1367 | + //2017-03-03 UPDATE marky 検索API v2 | |
1368 | + [DataContract] | |
1369 | + class NiconicoAPIResult | |
1370 | + { | |
1371 | + [DataMember] | |
1372 | + public MetaC meta = null; | |
1373 | + | |
1374 | + [DataContract] | |
1375 | + public class MetaC | |
1376 | + { | |
1377 | + [DataMember] | |
1378 | + public string status = ""; | |
1379 | + | |
1380 | + [DataMember] | |
1381 | + public string totalCount = ""; | |
1382 | + | |
1383 | + [DataMember] | |
1384 | + public string id = ""; | |
1385 | + } | |
1386 | + | |
1387 | + [DataMember] | |
1388 | + public List<DataC> data = null; | |
1389 | + | |
1390 | + [DataContract] | |
1391 | + public class DataC | |
1392 | + { | |
1393 | + [DataMember] | |
1394 | + public string contentId = ""; | |
1395 | + | |
1396 | + [DataMember] | |
1397 | + public string title = ""; | |
1398 | + | |
1399 | + [DataMember] | |
1400 | + public string description = ""; | |
1401 | + | |
1402 | + [DataMember] | |
1403 | + public string tags = ""; | |
1404 | + | |
1405 | + [DataMember] | |
1406 | + public string categoryTags = ""; | |
1407 | + | |
1408 | + [DataMember] | |
1409 | + public string viewCounter = ""; | |
1410 | + | |
1411 | + [DataMember] | |
1412 | + public string mylistCounter = ""; | |
1413 | + | |
1414 | + [DataMember] | |
1415 | + public string commentCounter = ""; | |
1416 | + | |
1417 | + [DataMember] | |
1418 | + public string startTime = ""; | |
1419 | + | |
1420 | + [DataMember] | |
1421 | + public string thumbnailUrl = ""; | |
1422 | + | |
1423 | + [DataMember] | |
1424 | + public string lengthSeconds = ""; | |
1425 | + } | |
1426 | + } | |
1317 | 1427 | } |
@@ -32,5 +32,5 @@ | ||
32 | 32 | // すべての値を指定するか、下のように '*' を使ってビルドおよびリビジョン番号を |
33 | 33 | // 既定値にすることができます: |
34 | 34 | // [assembly: AssemblyVersion("1.0.*")] |
35 | -[assembly: AssemblyVersion("3.02.0.0")] | |
36 | -[assembly: AssemblyFileVersion("3.02.0.0")] | |
35 | +[assembly: AssemblyVersion("3.03.0.0")] | |
36 | +[assembly: AssemblyFileVersion("3.03.0.0")] |