从JSON的Twitter的新功能视频帖子的推文中提取视频URL,然后下载视频。


现在,您可以从官方Twitter应用程序上传视频(最长30秒)。

スクリーンショット 2015-02-03 1.09.17.png
https://twitter.com/n428dev/status/561814427150741505

其他样品
https://twitter.com/n428dev/status/564344850112192512

如果您在JSON中获得此推文,则将如下所示

包含视频发布信息的推文的JSON

video_tweet.json

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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
{
  "contributors": null,
  "text": "ツイッター動画投稿テスト http://t.co/y9hjEfABw1",
  "geo": null,
  "retweeted": false,
  "in_reply_to_screen_name": null,
  "possibly_sensitive": false,
  "truncated": false,
  "lang": "ja",
  "entities": {
    "symbols": [],
    "urls": [],
    "hashtags": [],
    "media": [
      {
        "sizes": {
          "thumb": {
            "w": 150,
            "resize": "crop",
            "h": 150
          },
          "small": {
            "w": 340,
            "resize": "fit",
            "h": 340
          },
          "large": {
            "w": 720,
            "resize": "fit",
            "h": 720
          },
          "medium": {
            "w": 600,
            "resize": "fit",
            "h": 600
          }
        },
        "id": 561814337585569800,
        "media_url_https": "https://pbs.twimg.com/ext_tw_video_thumb/561814337585569793/pu/img/ZyW1taT-3_AkDB-4.jpg",
        "media_url": "http://pbs.twimg.com/ext_tw_video_thumb/561814337585569793/pu/img/ZyW1taT-3_AkDB-4.jpg",
        "expanded_url": "http://twitter.com/n428dev/status/561814427150741505/video/1",
        "indices": [
          13,
          35
        ],
        "id_str": "561814337585569793",
        "type": "photo",
        "display_url": "pic.twitter.com/y9hjEfABw1",
        "url": "http://t.co/y9hjEfABw1"
      }
    ],
    "user_mentions": []
  },
  "in_reply_to_status_id_str": null,
  "id": 561814427150741500,
  "extended_entities": {
    "media": [
      {
        "sizes": {
          "thumb": {
            "w": 150,
            "resize": "crop",
            "h": 150
          },
          "small": {
            "w": 340,
            "resize": "fit",
            "h": 340
          },
          "large": {
            "w": 720,
            "resize": "fit",
            "h": 720
          },
          "medium": {
            "w": 600,
            "resize": "fit",
            "h": 600
          }
        },
        "id": 561814337585569800,
        "media_url_https": "https://pbs.twimg.com/ext_tw_video_thumb/561814337585569793/pu/img/ZyW1taT-3_AkDB-4.jpg",
        "video_info": {
          "duration_millis": 11965,
          "variants": [
            {
              "bitrate": 832000,
              "content_type": "video/webm",
              "url": "https://video.twimg.com/ext_tw_video/561814337585569793/pu/vid/480x480/QKhWzHdEK0QDPtg8.webm"
            },
            {
              "bitrate": 1280000,
              "content_type": "video/mp4",
              "url": "https://video.twimg.com/ext_tw_video/561814337585569793/pu/vid/720x720/IdBKWbELa8D8cqLD.mp4"
            },
            {
              "bitrate": 320000,
              "content_type": "video/mp4",
              "url": "https://video.twimg.com/ext_tw_video/561814337585569793/pu/vid/240x240/7EK_gSEEPFBATzXI.mp4"
            },
            {
              "bitrate": 832000,
              "content_type": "video/mp4",
              "url": "https://video.twimg.com/ext_tw_video/561814337585569793/pu/vid/480x480/QKhWzHdEK0QDPtg8.mp4"
            },
            {
              "content_type": "application/x-mpegURL",
              "url": "https://video.twimg.com/ext_tw_video/561814337585569793/pu/pl/6G6kgS5lRXAOiCcg.m3u8"
            }
          ],
          "aspect_ratio": [
            1,
            1
          ]
        },
        "media_url": "http://pbs.twimg.com/ext_tw_video_thumb/561814337585569793/pu/img/ZyW1taT-3_AkDB-4.jpg",
        "expanded_url": "http://twitter.com/n428dev/status/561814427150741505/video/1",
        "indices": [
          13,
          35
        ],
        "id_str": "561814337585569793",
        "type": "video",
        "display_url": "pic.twitter.com/y9hjEfABw1",
        "url": "http://t.co/y9hjEfABw1"
      }
    ]
  },
  "source": "<a href="http://twitter.com/download/iphone" rel="nofollow">Twitter for iPhone</a>",
  "in_reply_to_user_id_str": null,
  "favorited": false,
  "in_reply_to_status_id": null,
  "retweet_count": 0,
  "created_at": "Sun Feb 01 09:12:52 +0000 2015",
  "in_reply_to_user_id": null,
  "favorite_count": 0,
  "id_str": "561814427150741505",
  "place": null,
  "user": {
    "location": "",
    "default_profile": true,
    "profile_background_tile": false,
    "statuses_count": 66,
    "lang": "ja",
    "profile_link_color": "0084B4",
    "id": 826661216,
    "following": false,
    "protected": false,
    "profile_location": null,
    "favourites_count": 5,
    "profile_text_color": "333333",
    "description": "428で働くプログラマー",
    "verified": false,
    "contributors_enabled": false,
    "profile_sidebar_border_color": "C0DEED",
    "name": "AKB428",
    "profile_background_color": "C0DEED",
    "created_at": "Sun Sep 16 07:06:52 +0000 2012",
    "is_translation_enabled": false,
    "default_profile_image": false,
    "followers_count": 9,
    "profile_image_url_https": "https://pbs.twimg.com/profile_images/507934202185011200/HcQGt2_r_normal.jpeg",
    "geo_enabled": false,
    "profile_background_image_url": "http://abs.twimg.com/images/themes/theme1/bg.png",
    "profile_background_image_url_https": "https://abs.twimg.com/images/themes/theme1/bg.png",
    "follow_request_sent": false,
    "entities": {
      "description": {
        "urls": []
      }
    },
    "url": null,
    "utc_offset": 32400,
    "time_zone": "Irkutsk",
    "notifications": false,
    "profile_use_background_image": true,
    "friends_count": 40,
    "profile_sidebar_fill_color": "DDEEF6",
    "screen_name": "n428dev",
    "id_str": "826661216",
    "profile_image_url": "http://pbs.twimg.com/profile_images/507934202185011200/HcQGt2_r_normal.jpeg",
    "listed_count": 0,
    "is_translator": false
  },
  "coordinates": null
}

如果查看

JSON,则可以看到可以通过从extended_entities:属性的media属性读取来获取视频信息。

配置extended_entities属性图

extended_entities.media还包含有关已发布照片的信息。
JSON的结构如下所示。

video2.png

但是,由于iPhone应用程序的规格,目前无法在一条推文中发布多个视频。
另外,由于无法同时发布照片和视频(可能由于服务器负载),我认为发布视频时唯一应获取的视频信息是extended_entities.media [0]。

媒体属性具有type属性,如果类型是照片,则存储照片,如果类型是视频,则存储视频信息。

media.type =='video'

时媒体属性的JSON配置图

video.png

video_info属性详细信息

如果media.type为'video',则video_info属性存在于media属性中。
视频URL和视频格式将从此处获得。
每个属性的含义如下。

<表格>

video_info属性

含义


<身体>

duration_millis

视频的长度(以毫秒为单位)

Aspect_ratio

视频宽高比

变体

信息数组从发布的视频转换为各种格式


<表格>

变体属性数组的每个元素

含义


<身体>

比特率

视频比特率

content_type

视频格式

网址

视频网址


(设计)将video_info属性转换为语言类型

对于LL语言(Ruby / Python / Perl等),我认为故事已经结束了,仅根据此信息将JSON转换为哈希即可。
但是,对于具有类型的语言,有必要编写一个将JSON转换为gorigori类型的解析器,因此创建一个映射表。

对于Java

VideoInfo类别

<表格>

VideoInfo类属性

类型

备注


<身体>

durationMillis


AspectEatio

列表