aboutsummaryrefslogtreecommitdiff
path: root/youtube_dl/extractor/archiveorg.py
blob: ba94b54547122a37e9054cf703d5c2e7cce71eb9 (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
from __future__ import unicode_literals

import json
import re

from .common import InfoExtractor
from ..utils import (
    unified_strdate,
)


class ArchiveOrgIE(InfoExtractor):
    IE_NAME = 'archive.org'
    IE_DESC = 'archive.org videos'
    _VALID_URL = r'(?:https?://)?(?:www\.)?archive\.org/details/(?P<id>[^?/]+)(?:[?].*)?$'
    _TEST = {
        "url": "http://archive.org/details/XD300-23_68HighlightsAResearchCntAugHumanIntellect",
        'file': 'XD300-23_68HighlightsAResearchCntAugHumanIntellect.ogv',
        'md5': '8af1d4cf447933ed3c7f4871162602db',
        'info_dict': {
            "title": "1968 Demo - FJCC Conference Presentation Reel #1",
            "description": "Reel 1 of 3: Also known as the \"Mother of All Demos\", Doug Engelbart's presentation at the Fall Joint Computer Conference in San Francisco, December 9, 1968 titled \"A Research Center for Augmenting Human Intellect.\" For this presentation, Doug and his team astonished the audience by not only relating their research, but demonstrating it live. This was the debut of the mouse, interactive computing, hypermedia, computer supported software engineering, video teleconferencing, etc. See also <a href=\"http://dougengelbart.org/firsts/dougs-1968-demo.html\" rel=\"nofollow\">Doug's 1968 Demo page</a> for more background, highlights, links, and the detailed paper published in this conference proceedings. Filmed on 3 reels: Reel 1 | <a href=\"http://www.archive.org/details/XD300-24_68HighlightsAResearchCntAugHumanIntellect\" rel=\"nofollow\">Reel 2</a> | <a href=\"http://www.archive.org/details/XD300-25_68HighlightsAResearchCntAugHumanIntellect\" rel=\"nofollow\">Reel 3</a>",
            "upload_date": "19681210",
            "uploader": "SRI International"
        }
    }

    def get_optional_metadata(self, data, field):
        try:
            return data['metadata'][field][0]
        except KeyError:
            return None

    def _real_extract(self, url):
        mobj = re.match(self._VALID_URL, url)
        video_id = mobj.group('id')

        json_url = url + ('?' if '?' in url else '&') + 'output=json'
        json_data = self._download_webpage(json_url, video_id)
        data = json.loads(json_data)

        title = self.get_optional_metadata(data, 'title')
        description = self.get_optional_metadata(data, 'description')
        uploader = self.get_optional_metadata(data, 'creator')
        upload_date = self.get_optional_metadata(data, 'date')
        if upload_date:
            upload_date = unified_strdate(upload_date)

        formats = [
            {
                'format': fdata['format'],
                'url': 'http://' + data['server'] + data['dir'] + fn,
                'file_size': int(fdata['size']),
            }
            for fn, fdata in data['files'].items()
            if 'Video' in fdata['format']]

        self._sort_formats(formats)

        return {
            '_type': 'video',
            'id': video_id,
            'title': title,
            'formats': formats,
            'description': description,
            'uploader': uploader,
            'upload_date': upload_date,
            'thumbnail': data.get('misc', {}).get('image'),
        }