aboutsummaryrefslogtreecommitdiff
path: root/youtube_dl/extractor/gogoanime.py
blob: d4f4ecc58afe4bac88878d5a6c41a0c85f533fc0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
from __future__ import unicode_literals

import re

from .common import InfoExtractor
from ..utils import (
    ExtractorError,
    compat_urllib_parse,
    get_element_by_attribute,
    unescapeHTML
)


class GoGoAnimeIE(InfoExtractor):
    IE_NAME = 'gogoanime'
    IE_DESC = 'GoGoAnime'
    _VALID_URL = r'http://www.gogoanime.com/(?P<id>[A-Za-z0-9-]+)'

    _TEST = {
        'url': 'http://www.gogoanime.com/mahou-shoujo-madoka-magica-movie-1',
        'info_dict': {
            'id': 'mahou-shoujo-madoka-magica-movie-1'
        },
        'playlist_count': 3
    }

    def _real_extract(self, url):
        video_id = self._match_id(url)
        page = self._download_webpage(url, video_id)

        if 'Oops! Page Not Found</font>' in page:
            raise ExtractorError('Video does not exist', expected=True)

        content = get_element_by_attribute("class", "postcontent", page)
        vids = re.findall(r'<iframe[^>]*?src=[\'"](h[^\'"]+)[\'"]', content)
        vids = [
            unescapeHTML(compat_urllib_parse.unquote(x))
            for x in vids if not re.search(r".*videofun.*", x)]

        if re.search(r'<div class="postcontent">[^<]*<p><iframe src=[\'"][^>]+></iframe><br />', page):
            return self.playlist_result([self.url_result(vid) for vid in vids], video_id)

        title = self._html_search_regex(
            r'<div class="postdesc">[^<]*<h1>([^<]+)</h1>', page, 'title')

        return {
            '_type': 'url',
            'id': video_id,
            'url': vids[0],
            'title': title,
        }


class GoGoAnimeSearchIE(InfoExtractor):
    IE_NAME = 'gogoanime:search'
    IE_DESC = 'GoGoAnime Search'

    _VALID_URL = r'http://www\.gogoanime\.com/.*\?s=(?P<id>[^&]*)'
    _TEST = {
        'url': 'http://www.gogoanime.com/?s=bokusatsu',
        'info_dict': {
            'id': 'bokusatsu'
        },
        'playlist_count': 6
    }

    def _real_extract(self, url):
        playlist_id = self._match_id(url)
        webpage = self._download_webpage(url, playlist_id)

        posts = re.findall(
            r'<div class="postlist">[^<]*<p[^>]*>[^<]*<a href="(?P<url>[^"]+)"',
            webpage)

        return self.playlist_result(
            [self.url_result(p) for p in posts], playlist_id)