[xtube] user playlist extractor
authorfiocfun <fiocfun@gmail.com>
Sat, 22 Mar 2014 18:16:35 +0000 (00:16 +0600)
committerfiocfun <fiocfun@gmail.com>
Sat, 22 Mar 2014 18:16:35 +0000 (00:16 +0600)
test/test_playlists.py
youtube_dl/extractor/__init__.py
youtube_dl/extractor/xtube.py

index 4c9c34057dd535ac2cd4c4b0148917ab3c440237..2b1a7e849af597eeea461183d1f0942a058e671d 100644 (file)
@@ -38,6 +38,7 @@ from youtube_dl.extractor import (
     GenericIE,
     TEDIE,
     ToypicsUserIE,
+    XTubeUserIE,
 )
 
 
@@ -278,5 +279,13 @@ class TestPlaylists(unittest.TestCase):
         self.assertEqual(result['id'], 'Mikey')
         self.assertTrue(len(result['entries']) >= 17)
 
+    def test_xtube_user(self):
+        dl = FakeYDL()
+        ie = XTubeUserIE(dl)
+        result = ie.extract('http://www.xtube.com/community/profile.php?user=greenshowers')
+        self.assertIsPlaylist(result)
+        self.assertEqual(result['id'], 'greenshowers')
+        self.assertTrue(len(result['entries']) >= 155)
+
 if __name__ == '__main__':
     unittest.main()
index b8c843515d48341862c446fa004b277f37d5f9db..35f6e33581bdff70168b7d9c19574074d87c91c7 100644 (file)
@@ -288,7 +288,7 @@ from .worldstarhiphop import WorldStarHipHopIE
 from .xhamster import XHamsterIE
 from .xnxx import XNXXIE
 from .xvideos import XVideosIE
-from .xtube import XTubeIE
+from .xtube import XTubeUserIE, XTubeIE
 from .yahoo import (
     YahooIE,
     YahooNewsIE,
index 033a9d893ed2e44316ac0b26cebacf817acd8ec1..b293e2665b81b9a486bff2ec91b410da4a6d9998 100644 (file)
@@ -75,4 +75,40 @@ class XTubeIE(InfoExtractor):
             'comment_count': comment_count,
             'formats': formats,
             'age_limit': 18,
-        }
\ No newline at end of file
+        }
+
+class XTubeUserIE(InfoExtractor):
+    IE_DESC = 'XTube user profile'
+    _VALID_URL = r'https?://(?:www\.)?xtube\.com/community/profile\.php\?(.*?)user=(?P<username>[^&#]+)(?:$|[&#])'
+
+    def _real_extract(self, url):
+        mobj = re.match(self._VALID_URL, url)
+        username = mobj.group('username')
+
+        profile_page = self._download_webpage(
+            url, username, note='Retrieving profile page')
+
+        video_count = int(self._search_regex(
+            r'<strong>%s\'s Videos \(([0-9]+)\)</strong>'%username, profile_page,
+            'video count'))
+
+        PAGE_SIZE = 25
+        urls = []
+        page_count = (video_count + PAGE_SIZE + 1) // PAGE_SIZE
+        for n in range(1, page_count + 1):
+            lpage_url = 'http://www.xtube.com/user_videos.php?page=%d&u=%s' % (n, username)
+            lpage = self._download_webpage(
+                lpage_url, username,
+                note='Downloading page %d/%d' % (n, page_count))
+            urls.extend(
+                re.findall(r'addthis:url="([^"]+)"', lpage))
+
+        return {
+            '_type': 'playlist',
+            'id': username,
+            'entries': [{
+                '_type': 'url',
+                'url': eurl,
+                'ie_key': 'XTube',
+            } for eurl in urls]
+        }