1
0
mirror of https://codeberg.org/polarisfm/youtube-dl synced 2024-12-04 06:17:54 +01:00

made regex more robust, fixed coding conventions

This commit is contained in:
john 2018-09-08 15:00:05 -07:00
parent 9ccab97034
commit efae7c1a5d

View File

@ -4,7 +4,6 @@ from __future__ import unicode_literals
import json import json
import datetime import datetime
import re import re
import datetime
from .common import InfoExtractor, SearchInfoExtractor from .common import InfoExtractor, SearchInfoExtractor
from ..compat import ( from ..compat import (
@ -471,11 +470,13 @@ class NiconicoPlaylistIE(InfoExtractor):
'entries': entries, 'entries': entries,
} }
# USAGE: youtube-dl "nicosearch<NUMBER OF ENTRIES>:<SEARCH STRING>" # USAGE: youtube-dl "nicosearch<NUMBER OF ENTRIES>:<SEARCH STRING>"
class NicovideoIE(SearchInfoExtractor): class NicovideoIE(SearchInfoExtractor):
IE_DESC = 'Nico video search' IE_DESC = 'Nico video search'
_MAX_RESULTS = 100000 _MAX_RESULTS = 100000
_SEARCH_KEY = 'nicosearch' _SEARCH_KEY = 'nicosearch'
def _get_n_results(self, query, n): def _get_n_results(self, query, n):
"""Get a specified number of results for a query""" """Get a specified number of results for a query"""
entries = [] entries = []
@ -507,7 +508,7 @@ class NicovideoIE(SearchInfoExtractor):
link = url + "&page=" + str(pageNumber) + "&start=" + str(date) + "&end=" + str(date) link = url + "&page=" + str(pageNumber) + "&start=" + str(date) + "&end=" + str(date)
results = self._download_webpage(link, query, note='Downloading results page %s for date %s' % (pageNumber, date)) results = self._download_webpage(link, query, note='Downloading results page %s for date %s' % (pageNumber, date))
entries = [] entries = []
r = re.findall(r'<a href="/watch/(..[0-9]{1,8})\?', results) r = re.findall(r'''<li.*(?!</li>) data-video-id=['|"](..[0-9]{1,8})''', results)
for item in r: for item in r:
e = self.url_result("http://www.nicovideo.jp/watch/" + str(item), 'Niconico') e = self.url_result("http://www.nicovideo.jp/watch/" + str(item), 'Niconico')