| OLD | NEW |
| (Empty) | |
| 1 <link rel="import" href="../../polymer/polymer.html"> |
| 2 <link rel="import" href="../../google-youtube/google-youtube.html"> |
| 3 <link rel="import" href="../google-youtube-upload.html"> |
| 4 |
| 5 <dom-module id="youtube-upload-demo-element"> |
| 6 <style> |
| 7 label { |
| 8 display: block; |
| 9 margin-top: 1em; |
| 10 } |
| 11 |
| 12 input { |
| 13 font-size: 100%; |
| 14 width: 50%; |
| 15 } |
| 16 |
| 17 textarea { |
| 18 font-size: 100%; |
| 19 width: 50%; |
| 20 height: 6em; |
| 21 } |
| 22 |
| 23 google-youtube-upload { |
| 24 margin-top: 1em; |
| 25 } |
| 26 </style> |
| 27 <template> |
| 28 <p> |
| 29 Upload videos with a |
| 30 <code><a href="index.html" target="_blank"><google-youtube-upload></
a></code> |
| 31 element! |
| 32 </p> |
| 33 |
| 34 <template is="dom-if" if="{{canShowPreUpload(state)}}"> |
| 35 <div> |
| 36 <label for="video-title">Title:</label> |
| 37 <input id="video-title" type="text" value="{{videoTitle::change}}"> |
| 38 </div> |
| 39 <div> |
| 40 <label for="description">Description:</label> |
| 41 <textarea id="description" value="{{description::change}}"></textarea> |
| 42 </div> |
| 43 <div> |
| 44 <label for="privacy-status">Privacy Status:</label> |
| 45 <select id="privacy-status" value="{{privacyStatus::change}}"> |
| 46 <option>public</option> |
| 47 <option>unlisted</option> |
| 48 <option>private</option> |
| 49 </select> |
| 50 </div> |
| 51 <google-youtube-upload |
| 52 client-id="1054047045356-j8pgqgls9vdef3rl09hapoicumbte0bo.apps.googleuse
rcontent.com" |
| 53 video-title="{{videoTitle}}" |
| 54 description="{{description}}" |
| 55 privacy-status="{{privacyStatus}}" |
| 56 video-id="{{videoId}}" |
| 57 on-youtube-upload-start="handleYouTubeUploadStart" |
| 58 on-youtube-upload-progress="handleYouTubeUploadProgress" |
| 59 on-youtube-upload-complete="handleYouTubeUploadComplete" |
| 60 on-youtube-upload-fail="handleYouTubeUploadFail" |
| 61 on-youtube-processing-poll="handleYouTubeProcessingPoll" |
| 62 on-youtube-processing-complete="handleYouTubeProcessingComplete" |
| 63 on-youtube-processing-fail="handleYouTubeProcessingFail"> |
| 64 </google-youtube-upload> |
| 65 </template> |
| 66 |
| 67 <template is="dom-if" if="{{canShowUpload(state)}}"> |
| 68 <div> |
| 69 Upload Progress: |
| 70 <progress max="1" value="{{fractionComplete}}"></progress> |
| 71 <span>{{computeProgressText(megabytesPerSecond, minutesRemaining, second
sRemaining)}}</span> |
| 72 </div> |
| 73 </template> |
| 74 |
| 75 <template is="dom-if" if="{{canShowUploadComplete(state)}}"> |
| 76 <p> |
| 77 Upload complete. Please wait while video id '<span>{{videoId}}</span>' i
s |
| 78 <a href="https://support.google.com/youtube/answer/71674?ref_topic=28886
03" target="_blank">processing</a><span>{{processingEllipses}}</span> |
| 79 </p> |
| 80 </template> |
| 81 |
| 82 <template is="dom-if" if="{{canShowProcessingComplete(state)}}" restamp> |
| 83 <p> |
| 84 Processing complete. The video is available at |
| 85 <a href$="{{videoUrl}}" target="_blank">{{videoUrl}}</a> |
| 86 and embedded below: |
| 87 </p> |
| 88 <google-youtube video-id="{{videoId}}"></google-youtube> |
| 89 </template> |
| 90 |
| 91 <template is="dom-if" if="{{canShowError(state)}}"> |
| 92 <p>{{error}}</p> |
| 93 </template> |
| 94 |
| 95 </template> |
| 96 </dom-module> |
| 97 <script> |
| 98 Polymer({ |
| 99 is: 'youtube-upload-demo-element', |
| 100 |
| 101 properties: { |
| 102 state: { |
| 103 type: String, |
| 104 value: 'pre-upload' |
| 105 }, |
| 106 processingEllipses: { |
| 107 type: String, |
| 108 value: '...' |
| 109 }, |
| 110 megabytesPerSecond: { |
| 111 type: Number, |
| 112 value: 0 |
| 113 }, |
| 114 minutesRemaining: { |
| 115 type: Number, |
| 116 value: 0 |
| 117 }, |
| 118 secondsRemaining: { |
| 119 type: Number, |
| 120 value: 0 |
| 121 }, |
| 122 fractionComplete: { |
| 123 type: Number, |
| 124 value: 0 |
| 125 }, |
| 126 error: { |
| 127 type: String, |
| 128 value: '' |
| 129 }, |
| 130 videoTitle: { |
| 131 type: String, |
| 132 value: 'Untitled Video' |
| 133 }, |
| 134 description: { |
| 135 type: String, |
| 136 value: 'Uploaded via a web component! Check out https://github.com/Googl
eWebComponents/google-youtube-upload' |
| 137 }, |
| 138 privacyStatus: { |
| 139 type: String, |
| 140 value: 'public' |
| 141 }, |
| 142 videoId: { |
| 143 type: String, |
| 144 value: '' |
| 145 }, |
| 146 videoUrl: { |
| 147 type: String, |
| 148 computed: 'computeVideoUrl(videoId)' |
| 149 } |
| 150 }, |
| 151 |
| 152 canShowPreUpload: function(state) { |
| 153 return state === 'pre-upload'; |
| 154 }, |
| 155 canShowUpload: function(state) { |
| 156 return state === 'upload' |
| 157 }, |
| 158 canShowUploadComplete: function(state) { |
| 159 return state === 'upload-complete'; |
| 160 }, |
| 161 canShowProcessingComplete: function(state) { |
| 162 return state === 'processing-complete'; |
| 163 }, |
| 164 canShowError: function(state) { |
| 165 return state === 'error'; |
| 166 }, |
| 167 computeProgressText: function( megabytesPerSecond, minutesRemaining, seconds
Remaining) { |
| 168 return megabytesPerSecond + "MB/s, " + minutesRemaining + "m" + secondsRem
aining + "s remaining"; |
| 169 }, |
| 170 computeVideoUrl: function(videoId) { |
| 171 return "https://youtu.be/" + videoId; |
| 172 }, |
| 173 handleYouTubeUploadStart: function(e) { |
| 174 this.state = 'upload'; |
| 175 }, |
| 176 |
| 177 handleYouTubeUploadProgress: function(e) { |
| 178 this.megabytesPerSecond = (e.detail.bytesPerSecond / (1024 * 1024)).toFixe
d(2); |
| 179 this.minutesRemaining = Math.floor(e.detail.estimatedSecondsRemaining / 60
); |
| 180 this.secondsRemaining = Math.round(e.detail.estimatedSecondsRemaining % 60
); |
| 181 this.fractionComplete = e.detail.fractionComplete; |
| 182 }, |
| 183 |
| 184 handleYouTubeUploadComplete: function(e) { |
| 185 this.state = 'upload-complete'; |
| 186 }, |
| 187 |
| 188 handleYouTubeUploadFail: function(e) { |
| 189 this.error = e.detail; |
| 190 this.state = 'error'; |
| 191 }, |
| 192 |
| 193 handleYouTubeProcessingPoll: function(e) { |
| 194 this.processingEllipses += '.'; |
| 195 }, |
| 196 |
| 197 handleYouTubeProcessingComplete: function(e) { |
| 198 this.state = 'processing-complete'; |
| 199 }, |
| 200 |
| 201 handleYouTubeProcessingFail: function(e) { |
| 202 var error; |
| 203 switch(e.detail.uploadStatus) { |
| 204 case 'failed': |
| 205 error = e.detail.failureReason || 'unknown error'; |
| 206 break; |
| 207 |
| 208 case 'rejected': |
| 209 error = e.detail.rejectionReason || 'unknown error'; |
| 210 break; |
| 211 |
| 212 default: |
| 213 error = 'unknown error'; |
| 214 break; |
| 215 } |
| 216 |
| 217 this.error = 'YouTube processing failed (' + error + ').'; |
| 218 this.state = 'error'; |
| 219 } |
| 220 }); |
| 221 |
| 222 |
| 223 </script> |
| OLD | NEW |