]> jfr.im git - yt-dlp.git/blobdiff - yt_dlp/extractor/piapro.py
[ie/orf:on] Improve extraction (#9677)
[yt-dlp.git] / yt_dlp / extractor / piapro.py
index 497e1edbc363909198bf7caf4809159c412a67c4..3ae985da2b36671856a8ac0388f7fb981ca4ade4 100644 (file)
@@ -1,6 +1,3 @@
-# coding: utf-8
-from __future__ import unicode_literals
-
 from .common import InfoExtractor
 from ..compat import compat_urlparse
 from ..utils import (
 
 class PiaproIE(InfoExtractor):
     _NETRC_MACHINE = 'piapro'
-    _VALID_URL = r'https?://piapro\.jp/t/(?P<id>\w+)/?'
+    _VALID_URL = r'https?://piapro\.jp/(?:t|content)/(?P<id>[\w-]+)/?'
     _TESTS = [{
         'url': 'https://piapro.jp/t/NXYR',
-        'md5': 'a9d52f27d13bafab7ee34116a7dcfa77',
+        'md5': 'f7c0f760913fb1d44a1c45a4af793909',
         'info_dict': {
             'id': 'NXYR',
             'ext': 'mp3',
             'uploader': 'wowaka',
             'uploader_id': 'wowaka',
             'title': '裏表ラバーズ',
-            'thumbnail': r're:^https?://.*\.jpg$',
+            'description': 'http://www.nicovideo.jp/watch/sm8082467',
+            'duration': 189.0,
+            'timestamp': 1251785475,
+            'thumbnail': r're:^https?://.*\.(?:png|jpg)$',
+            'upload_date': '20090901',
+            'view_count': int,
+        }
+    }, {
+        'note': 'There are break lines in description, mandating (?s) flag',
+        'url': 'https://piapro.jp/t/9cSd',
+        'md5': '952bb6d1e8de95050206408a87790676',
+        'info_dict': {
+            'id': '9cSd',
+            'ext': 'mp3',
+            'title': '青に溶けた風船 / 初音ミク',
+            'description': 'md5:d395a9bd151447631a5a1460bc7f9132',
+            'uploader': 'シアン・キノ',
+            'duration': 229.0,
+            'timestamp': 1644030039,
+            'upload_date': '20220205',
+            'view_count': int,
+            'thumbnail': r're:^https?://.*\.(?:png|jpg)$',
+            'uploader_id': 'cyankino',
         }
+    }, {
+        'url': 'https://piapro.jp/content/hcw0z3a169wtemz6',
+        'only_matching': True
+    }, {
+        'url': 'https://piapro.jp/t/-SO-',
+        'only_matching': True
     }]
 
-    def _real_initialize(self):
-        self._login_status = self._login()
+    _login_status = False
 
-    def _login(self):
-        username, password = self._get_login_info()
-        if not username:
-            return False
+    def _perform_login(self, username, password):
         login_ok = True
         login_form_strs = {
             '_username': username,
@@ -51,13 +72,13 @@ def _login(self):
         if urlh is False:
             login_ok = False
         else:
-            parts = compat_urlparse.urlparse(urlh.geturl())
+            parts = compat_urlparse.urlparse(urlh.url)
             if parts.path != '/':
                 login_ok = False
         if not login_ok:
             self.report_warning(
                 'unable to log in: bad username or password')
-        return login_ok
+        self._login_status = login_ok
 
     def _real_extract(self, url):
         video_id = self._match_id(url)
@@ -85,7 +106,7 @@ def _real_extract(self, url):
         return {
             'id': video_id,
             'title': self._html_search_regex(r'<h1\s+class="cd_works-title">(.+?)</h1>', webpage, 'title', fatal=False),
-            'description': self._html_search_regex(r'<p\s+class="cd_dtl_cap">(.+?)</p>\s*<div', webpage, 'description', fatal=False),
+            'description': self._html_search_regex(r'(?s)<p\s+class="cd_dtl_cap">(.+?)</p>\s*<div', webpage, 'description', fatal=False),
             'uploader': uploader,
             'uploader_id': uploader_id,
             'timestamp': unified_timestamp(create_date, False),