├── .gitignore
├── demo
├── index.html
└── js
│ └── app.js
├── bower.json
├── package.json
├── LICENSE
├── Gruntfile.js
├── dist
├── angular-youtube-api-factory.min.js
└── angular-youtube-api-factory.js
├── README.md
└── src
└── angular-youtube-api-factory.js
/.gitignore:
--------------------------------------------------------------------------------
1 | /bower_components
2 | /.idea/
3 | /.codekit-cache/
4 | config.codekit
5 | /node_modules
--------------------------------------------------------------------------------
/demo/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | angular-youtube-api-factory
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 | Look in your console
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/bower.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "angular-youtube-api-factory",
3 | "homepage": "https://github.com/JohnnyTheTank/angular-youtube-api-factory",
4 | "authors": [
5 | "Jonathan Hornung "
6 | ],
7 | "version": "0.6.2",
8 | "description": "angular factory for youtube rest api connection",
9 | "main": "dist/angular-youtube-api-factory.min.js",
10 | "moduleType": [],
11 | "keywords": [
12 | "youtube",
13 | "angularjs",
14 | "rest",
15 | "api",
16 | "json"
17 | ],
18 | "license": "MIT",
19 | "ignore": [
20 | "**/.*",
21 | "node_modules",
22 | "bower_components",
23 | "test",
24 | "tests"
25 | ],
26 | "dependencies": {
27 | "angular": "*"
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "angular-youtube-api-factory",
3 | "version": "0.6.2",
4 | "description": "angularjs factory for youtube json rest api requests",
5 | "main": "dist/angular-youtube-api-factory.min.js",
6 | "scripts": {
7 | "test": "echo \"Error: no test specified\" && exit 1"
8 | },
9 | "repository": {
10 | "type": "git",
11 | "url": "git+https://github.com/JohnnyTheTank/angular-youtube-api-factory.git"
12 | },
13 | "keywords": [
14 | "angularjs",
15 | "angular",
16 | "youtube",
17 | "api",
18 | "factory"
19 | ],
20 | "author": "Jonathan Hornung",
21 | "license": "MIT",
22 | "bugs": {
23 | "url": "https://github.com/JohnnyTheTank/angular-youtube-api-factory/issues"
24 | },
25 | "homepage": "https://github.com/JohnnyTheTank/angular-youtube-api-factory#readme",
26 | "devDependencies": {
27 | "grunt": "^0.4.5",
28 | "grunt-contrib-concat": "^0.5.1",
29 | "grunt-contrib-uglify": "^0.11.0",
30 | "grunt-contrib-watch": "^0.6.1"
31 | },
32 | "dependencies": {
33 | "angular": "*"
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2015 Jonathan Hornung
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
23 |
--------------------------------------------------------------------------------
/Gruntfile.js:
--------------------------------------------------------------------------------
1 | module.exports = function(grunt) {
2 |
3 | var banner = '/**\n @name: <%= pkg.name %> \n @version: <%= pkg.version %> (<%= grunt.template.today("dd-mm-yyyy") %>) \n @author: <%= pkg.author %> \n @url: <%= pkg.homepage %> \n @license: <%= pkg.license %>\n*/\n';
4 |
5 | grunt.initConfig({
6 | pkg: grunt.file.readJSON('package.json'),
7 | uglify: {
8 | js: {
9 | files : {
10 | 'dist/angular-youtube-api-factory.min.js' : ['src/*.js']
11 | }
12 | },
13 | options: {
14 | banner: banner,
15 | }
16 | },
17 | concat: {
18 | options: {
19 | separator: ';',
20 | banner: banner,
21 | },
22 | dist: {
23 | files : {
24 | 'dist/angular-youtube-api-factory.js' : ['src/*.js']
25 | }
26 | },
27 | },
28 | watch: {
29 | minifiyJs: {
30 | files: [
31 | 'src/*.js'
32 | ],
33 | tasks: ['uglify', 'concat'],
34 | options: {
35 | spawn: true,
36 | },
37 | },
38 | },
39 | });
40 |
41 | grunt.loadNpmTasks('grunt-contrib-uglify');
42 | grunt.loadNpmTasks('grunt-contrib-watch');
43 | grunt.loadNpmTasks('grunt-contrib-concat');
44 |
45 | grunt.registerTask('default', ['watch']);
46 |
47 | };
48 |
--------------------------------------------------------------------------------
/demo/js/app.js:
--------------------------------------------------------------------------------
1 | var app = angular.module("app", ['jtt_youtube']);
2 | app.controller('controller', ['$scope', 'youtubeFactory', function($scope, youtubeFactory) {
3 |
4 | var _apiKey = "";
5 |
6 | youtubeFactory.getVideosFromChannelById({
7 | channelId: "UCVkXCOYluJvD6OPjX9HXj-A",
8 | maxResults: "50",
9 | key: _apiKey,
10 | }).then(function (_data) {
11 | console.info("videos from channel by id", _data);
12 | });
13 |
14 | youtubeFactory.getVideosFromSearchByParams({
15 | q: "fcbayern",
16 | maxResults: "50",
17 | key: _apiKey,
18 | }).then(function (_data) {
19 | console.info("videos from search by q", _data);
20 | });
21 |
22 | youtubeFactory.getVideosFromSearchByParams({
23 | location: "37.42307,-122.08427",
24 | locationRadius: "1000m",
25 | maxResults: "50",
26 | key: _apiKey,
27 | }).then(function (_data) {
28 | console.info("videos from search by location", _data);
29 | });
30 |
31 | youtubeFactory.getVideosFromPlaylistById({
32 | playlistId: "PLNLa2lbKPczGCueOYxjrwYDuNTBtQveK0",
33 | maxResults: "50",
34 | key: _apiKey,
35 | }).then(function (_data) {
36 | console.info("videos from playlist by id", _data);
37 | });
38 |
39 | youtubeFactory.getVideoById({
40 | videoId: "rG-haoIhH9o",
41 | key: _apiKey,
42 | }).then(function (_data) {
43 | console.info("video by id", _data);
44 | });
45 |
46 | youtubeFactory.getChannelById({
47 | channelId: "UCVkXCOYluJvD6OPjX9HXj-A",
48 | key: _apiKey,
49 | }).then(function (_data) {
50 | console.info("channel by id", _data);
51 | });
52 |
53 |
54 | }]);
55 |
--------------------------------------------------------------------------------
/dist/angular-youtube-api-factory.min.js:
--------------------------------------------------------------------------------
1 | /**
2 | @name: angular-youtube-api-factory
3 | @version: 0.6.2 (30-11-2017)
4 | @author: Jonathan Hornung
5 | @url: https://github.com/JohnnyTheTank/angular-youtube-api-factory#readme
6 | @license: MIT
7 | */
8 | "use strict";angular.module("jtt_youtube",[]).factory("youtubeFactory",["$http","youtubeSearchDataService",function(a,b){var c={};return c.getVideosFromChannelById=function(c){var d=b.getNew("videosFromChannelById",c);return a({method:"GET",url:d.url,params:d.object})},c.getVideosFromSearchByParams=function(c){var d=b.getNew("videosFromSearchByParams",c);return a({method:"GET",url:d.url,params:d.object})},c.getVideosFromPlaylistById=function(c){var d=b.getNew("videosFromPlaylistById",c);return a({method:"GET",url:d.url,params:d.object})},c.getChannelById=function(c){var d=b.getNew("channelById",c);return a({method:"GET",url:d.url,params:d.object})},c.getChannelByUsername=function(c){var d=b.getNew("channelByUsername",c);return a({method:"GET",url:d.url,params:d.object})},c.getVideoById=function(c){var d=b.getNew("videoById",c);return a({method:"GET",url:d.url,params:d.object})},c}]).service("youtubeSearchDataService",function(){this.getApiBaseUrl=function(a){return"https://content.googleapis.com/youtube/v3/"},this.fillDataInObjectByList=function(a,b,c){return angular.forEach(c,function(c,d){"undefined"!=typeof c&&c.constructor===Array?angular.isDefined(b[c[0]])?a.object[c[0]]=b[c[0]]:a.object[c[0]]=c[1]:angular.isDefined(b[c])&&(a.object[c]=b[c])}),a},this.getNew=function(a,b){var c={object:{key:b.key},url:""};switch(a){case"videosFromChannelById":c=this.fillDataInObjectByList(c,b,[["part","id,snippet"],["type","video"],["order","date"],["videoEmbeddable",!0],"channelId","q","maxResults","publishedAfter","publishedBefore","regionCode","relevanceLanguage","safeSearch","videoLicense","videoSyndicated","fields"]),c.url=this.getApiBaseUrl()+"search?",(b.nextPageToken||b.prevPageToken)&&(c.url+="pageToken="+(b.nextPageToken||b.prevPageToken)+"&");break;case"videosFromSearchByParams":c=this.fillDataInObjectByList(c,b,[["part","id,snippet"],["type","video"],["order","date"],["videoEmbeddable",!0],"location","q","maxResults","publishedAfter","publishedBefore","regionCode","relevanceLanguage","safeSearch","videoLicense","videoSyndicated","fields"]),angular.isDefined(b.locationRadius)?c.object.locationRadius=b.locationRadius:angular.isDefined(b.location)&&(c.object.locationRadius="5000m"),c.url=this.getApiBaseUrl()+"search?",(b.nextPageToken||b.prevPageToken)&&(c.url+="pageToken="+(b.nextPageToken||b.prevPageToken)+"&");break;case"videosFromPlaylistById":c=this.fillDataInObjectByList(c,b,[["part","id,snippet"],["type","video"],"playlistId","maxResults","fields"]),c.url=this.getApiBaseUrl()+"playlistItems?",(b.nextPageToken||b.prevPageToken)&&(c.url+="pageToken="+(b.nextPageToken||b.prevPageToken)+"&");break;case"videoById":c=this.fillDataInObjectByList(c,b,[["part","id,snippet,contentDetails,statistics"]]),c.object.id=b.videoId,c.url=this.getApiBaseUrl()+"videos?",(b.nextPageToken||b.prevPageToken)&&(c.url+="pageToken="+(b.nextPageToken||b.prevPageToken)+"&");break;case"channelById":c=this.fillDataInObjectByList(c,b,[["part","id,snippet"],["type","channel"]]),c.url=this.getApiBaseUrl()+"search?",(b.nextPageToken||b.prevPageToken)&&(c.url+="pageToken="+(b.nextPageToken||b.prevPageToken)+"&");break;case"channelByUsername":c=this.fillDataInObjectByList(c,b,[["part","id,snippet"],"forUsername"]),c.url=this.getApiBaseUrl()+"channels?",(b.nextPageToken||b.prevPageToken)&&(c.url+="pageToken="+(b.nextPageToken||b.prevPageToken)+"&")}return c}});
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | **angular-youtube-api-factory** is an angularjs module with a youtube api factory.
2 |
3 | [](https://badge.fury.io/js/angular-youtube-api-factory)
4 | [](https://badge.fury.io/bo/angular-youtube-api-factory)
5 |
6 | Author: Jonathan Hornung ([JohnnyTheTank](https://github.com/JohnnyTheTank))
7 |
8 | ## Usage
9 |
10 | 1. Install via either [bower](http://bower.io/), [npm](https://www.npmjs.com/) or downloaded files:
11 | 1. `bower install --save angular-youtube-api-factory`
12 | 2. `npm install --save angular-youtube-api-factory`
13 | 3. download [angular-youtube-api-factory.zip](https://github.com/JohnnyTheTank/angular-youtube-api-factory/zipball/master)
14 | 2. Include dependencies in your HTML.
15 | 1. When using bower:
16 | ```html
17 |
18 | ```
19 | 2. When using npm:
20 | ```html
21 |
22 | ```
23 | 3. when using downloaded files
24 | ```html
25 |
26 | ```
27 | 3. Add **`jtt_youtube`** to your application's module dependencies
28 |
29 | ```JavaScript
30 | angular.module('app', ['jtt_youtube']);
31 | ```
32 | 4. Use the factory `youtubeFactory`
33 |
34 | ```JavaScript
35 | angular.module('app')
36 | .controller('appController', function($scope, youtubeFactory){
37 |
38 | youtubeFactory.getVideosFromSearchByParams({
39 | q: 'fcbayern',
40 | key: ''
41 | }).then(function (data) {
42 | console.info('videos from search by query', data);
43 | });
44 |
45 | });
46 | ```
47 |
48 |
49 | ### factory methods
50 |
51 | #### getVideo
52 | ```js
53 | //docs: https://developers.google.com/youtube/v3/docs/videos/list
54 | youtubeFactory.getVideoById({
55 | videoId: "",
56 | part: "", // (optional) default: 'id,snippet,contentDetails,statistics'
57 | key: "",
58 | }).then(function (_data) {
59 | //on success
60 | }).catch(function (_data) {
61 | //on error
62 | });
63 | ```
64 |
65 | #### getVideos
66 | ```js
67 | //docs: https://developers.google.com/youtube/v3/docs/channels/list
68 | youtubeFactory.getVideosFromChannelById({
69 | channelId: "", // converter: http://johnnythetank.github.io/youtube-channel-name-converter/
70 | q: "", // (optional) search string
71 | location: "", // (optional) The parameter value is a string that specifies latitude/longitude coordinates e.g. '37.42307,-122.08427'.
72 | locationRadius: "", // (optional) valid values e.g. '1500m', '5km', '10000ft', and '0.75mi' | default: '5000m'
73 | order: "", // (optional) valid values: 'date', 'rating', 'relevance', 'title', 'videoCount', 'viewCount' | default: 'date'
74 | maxResults: "", // (optional) valid values: 0-50 | default: 5
75 | publishedAfter: "", // (optional) RFC 3339 formatted date-time value (1970-01-01T00:00:00Z)
76 | publishedBefore: "", // (optional) RFC 3339 formatted date-time value (1970-01-01T00:00:00Z)
77 | regionCode: "", // (optional) ISO 3166-1 alpha-2 country code
78 | relevanceLanguage: "", // (optional) ISO 639-1 two-letter language code
79 | safeSearch: "", // (optional) valid values: 'moderate','none','strict' | defaut: 'moderate'
80 | maxResults: "", // (optional) valid values: 0-50 | default: 5
81 | videoEmbeddable: "", // (optional) valid values: 'true', 'any' | default: 'true'
82 | videoLicense: "", // (optional) valid values: 'any','creativeCommon','youtube'
83 | videoSyndicated: "", // (optional) restrict a search to only videos that can be played outside youtube.com. valid values: 'any','true' | default: 'any'
84 | fields: "", // (optional) Selector specifying which fields to include in a partial response
85 | nextPageToken: "", // (optional) either 'nextPageToken' or 'prevPageToken'
86 | prevPageToken: "", // (optional) either 'nextPageToken' or 'prevPageToken'
87 | part: "", // (optional) default: 'id,snippet'
88 | key: "",
89 | }).then(function (_data) {
90 | //on success
91 | }).catch(function (_data) {
92 | //on error
93 | });
94 | ```
95 |
96 | ```js
97 | //docs: https://developers.google.com/youtube/v3/docs/search/list
98 | youtubeFactory.getVideosFromSearchByParams({
99 | q: "", // (optional) search string
100 | location: "", // (optional) The parameter value is a string that specifies latitude/longitude coordinates e.g. '37.42307,-122.08427'.
101 | locationRadius: "", // (optional) valid values e.g. '1500m', '5km', '10000ft', and '0.75mi' | default: '5000m'
102 | order: "", // (optional) valid values: 'date', 'rating', 'relevance', 'title', 'videoCount', 'viewCount' | default: 'date'
103 | maxResults: "", // (optional) valid values: 0-50 | default: 5
104 | publishedAfter: "", // (optional) RFC 3339 formatted date-time value (1970-01-01T00:00:00Z)
105 | publishedBefore: "", // (optional) RFC 3339 formatted date-time value (1970-01-01T00:00:00Z)
106 | regionCode: "", // (optional) ISO 3166-1 alpha-2 country code
107 | relevanceLanguage: "", // (optional) ISO 639-1 two-letter language code
108 | safeSearch: "", // (optional) valid values: 'moderate','none','strict' | defaut: 'moderate'
109 | maxResults: "", // (optional) valid values: 0-50 | default: 5
110 | videoEmbeddable: "", // (optional) valid values: 'true', 'any' | default: 'true'
111 | videoLicense: "", // (optional) valid values: 'any','creativeCommon','youtube'
112 | videoSyndicated: "", // (optional) restrict a search to only videos that can be played outside youtube.com. valid values: 'any','true' | default: 'any'
113 | fields: "", // (optional) Selector specifying which fields to include in a partial response
114 | nextPageToken: "", // (optional) either 'nextPageToken' or 'prevPageToken'
115 | prevPageToken: "", // (optional) either 'nextPageToken' or 'prevPageToken'
116 | part: "", // (optional) default: 'id,snippet'
117 | key: "",
118 | }).then(function (_data) {
119 | //on success
120 | }).catch(function (_data) {
121 | //on error
122 | });
123 | ```
124 |
125 | ```js
126 | //docs: https://developers.google.com/youtube/v3/docs/playlists/list
127 | youtubeFactory.getVideosFromPlaylistById({
128 | playlistId: "",
129 | maxResults: "", // (optional) valid values: 0-50 // default: 5
130 | nextPageToken: "", // (optional) either 'nextPageToken' or 'prevPageToken'
131 | prevPageToken: "", // (optional) either 'nextPageToken' or 'prevPageToken'
132 | part: "", // (optional) default: 'id,snippet'
133 | key: "",
134 | }).then(function (_data) {
135 | //on success
136 | }).catch(function (_data) {
137 | //on error
138 | });
139 | ```
140 |
141 |
142 | #### getChannel
143 | ```js
144 | // docs: https://developers.google.com/youtube/v3/docs/search/list
145 | youtubeFactory.getChannelById({
146 | channelId: "", // converter: http://johnnythetank.github.io/youtube-channel-name-converter/
147 | nextPageToken: "", // (optional) either 'nextPageToken' or 'prevPageToken'
148 | prevPageToken: "", // (optional) either 'nextPageToken' or 'prevPageToken'
149 | part: "", // (optional) default: 'id,snippet'
150 | key: "",
151 | }).then(function (_data) {
152 | //on success
153 | }).catch(function (_data) {
154 | //on error
155 | });
156 | ```
157 |
158 |
159 | ## Youtube Data JSON API
160 | * Docs: https://developers.google.com/youtube/v3/docs/
161 | * API Explorer: https://developers.google.com/apis-explorer/#p/youtube/v3/
162 | * Youtube Username to Channel ID Converter: http://johnnythetank.github.io/youtube-channel-name-converter/
163 |
164 | ## More angular-api-factories
165 | [bandsintown](https://github.com/JohnnyTheTank/angular-bandsintown-api-factory) - [dailymotion](https://github.com/JohnnyTheTank/angular-dailymotion-api-factory) - [facebook](https://github.com/JohnnyTheTank/angular-facebook-api-factory) - [flickr](https://github.com/JohnnyTheTank/angular-flickr-api-factory) - [footballdata](https://github.com/JohnnyTheTank/angular-footballdata-api-factory) - [github](https://github.com/JohnnyTheTank/angular-github-api-factory) - [openweathermap](https://github.com/JohnnyTheTank/angular-openweathermap-api-factory) - [tumblr](https://github.com/JohnnyTheTank/angular-tumblr-api-factory) - [vimeo](https://github.com/JohnnyTheTank/angular-vimeo-api-factory) - [wikipedia](https://github.com/JohnnyTheTank/angular-wikipedia-api-factory) - **youtube**
166 |
167 | ## License
168 | MIT
169 |
--------------------------------------------------------------------------------
/src/angular-youtube-api-factory.js:
--------------------------------------------------------------------------------
1 | "use strict";
2 |
3 | angular.module("jtt_youtube", [])
4 | .factory('youtubeFactory', ['$http', 'youtubeSearchDataService', function ($http, youtubeSearchDataService) {
5 |
6 | var youtubeFactory = {};
7 |
8 | youtubeFactory.getVideosFromChannelById = function (_params) {
9 | var youtubeSearchData = youtubeSearchDataService.getNew("videosFromChannelById", _params);
10 | return $http({
11 | method: 'GET',
12 | url: youtubeSearchData.url,
13 | params: youtubeSearchData.object,
14 | });
15 | };
16 |
17 | youtubeFactory.getVideosFromSearchByParams = function (_params) {
18 | var youtubeSearchData = youtubeSearchDataService.getNew("videosFromSearchByParams", _params);
19 | return $http({
20 | method: 'GET',
21 | url: youtubeSearchData.url,
22 | params: youtubeSearchData.object,
23 | });
24 | };
25 |
26 | youtubeFactory.getVideosFromPlaylistById = function (_params) {
27 | var youtubeSearchData = youtubeSearchDataService.getNew("videosFromPlaylistById", _params);
28 | return $http({
29 | method: 'GET',
30 | url: youtubeSearchData.url,
31 | params: youtubeSearchData.object,
32 | });
33 | };
34 |
35 | youtubeFactory.getChannelById = function (_params) {
36 | var youtubeSearchData = youtubeSearchDataService.getNew("channelById", _params);
37 | return $http({
38 | method: 'GET',
39 | url: youtubeSearchData.url,
40 | params: youtubeSearchData.object,
41 | });
42 | };
43 |
44 | youtubeFactory.getChannelByUsername = function (_params) {
45 | var youtubeSearchData = youtubeSearchDataService.getNew("channelByUsername", _params);
46 | return $http({
47 | method: 'GET',
48 | url: youtubeSearchData.url,
49 | params: youtubeSearchData.object,
50 | });
51 | };
52 |
53 | youtubeFactory.getVideoById = function (_params) {
54 | var youtubeSearchData = youtubeSearchDataService.getNew("videoById", _params);
55 | return $http({
56 | method: 'GET',
57 | url: youtubeSearchData.url,
58 | params: youtubeSearchData.object,
59 | });
60 | };
61 |
62 | return youtubeFactory;
63 | }])
64 | .service('youtubeSearchDataService', function () {
65 | this.getApiBaseUrl = function (_params) {
66 | return "https://content.googleapis.com/youtube/v3/";
67 | };
68 |
69 | this.fillDataInObjectByList = function (_object, _params, _list) {
70 |
71 | angular.forEach(_list, function (value, key) {
72 | if (typeof value !== "undefined" && value.constructor === Array) {
73 | if (angular.isDefined(_params[value[0]])) {
74 | _object.object[value[0]] = _params[value[0]];
75 | } else {
76 | _object.object[value[0]] = value[1];
77 | }
78 | } else {
79 | if (angular.isDefined(_params[value])) {
80 | _object.object[value] = _params[value];
81 | }
82 | }
83 | });
84 |
85 | return _object;
86 | };
87 |
88 | this.getNew = function (_type, _params) {
89 |
90 | var youtubeSearchData = {
91 | object: {
92 | key: _params.key,
93 | },
94 | url: '',
95 | };
96 |
97 | switch (_type) {
98 | case 'videosFromChannelById':
99 |
100 | youtubeSearchData = this.fillDataInObjectByList(youtubeSearchData, _params, [
101 | ['part', 'id,snippet'],
102 | ['type', 'video'],
103 | ['order', 'date'],
104 | ['videoEmbeddable', true],
105 | 'channelId',
106 | 'q',
107 | 'maxResults',
108 | 'publishedAfter',
109 | 'publishedBefore',
110 | 'regionCode',
111 | 'relevanceLanguage',
112 | 'safeSearch',
113 | 'videoLicense',
114 | 'videoSyndicated',
115 | 'fields'
116 | ]);
117 |
118 | youtubeSearchData.url = this.getApiBaseUrl() + 'search?';
119 |
120 | if (_params.nextPageToken || _params.prevPageToken) {
121 | youtubeSearchData.url += 'pageToken=' + (_params.nextPageToken || _params.prevPageToken) + '&';
122 | }
123 | break;
124 |
125 | case 'videosFromSearchByParams':
126 |
127 | youtubeSearchData = this.fillDataInObjectByList(youtubeSearchData, _params, [
128 | ['part', 'id,snippet'],
129 | ['type', 'video'],
130 | ['order', 'date'],
131 | ['videoEmbeddable', true],
132 | 'location',
133 | 'q',
134 | 'maxResults',
135 | 'publishedAfter',
136 | 'publishedBefore',
137 | 'regionCode',
138 | 'relevanceLanguage',
139 | 'safeSearch',
140 | 'videoLicense',
141 | 'videoSyndicated',
142 | 'fields'
143 | ]);
144 |
145 | if (angular.isDefined(_params.locationRadius)) {
146 | youtubeSearchData.object.locationRadius = _params.locationRadius;
147 | } else {
148 | if (angular.isDefined(_params.location)) {
149 | youtubeSearchData.object.locationRadius = '5000m'
150 | }
151 | }
152 |
153 | youtubeSearchData.url = this.getApiBaseUrl() + 'search?';
154 | if (_params.nextPageToken || _params.prevPageToken) {
155 | youtubeSearchData.url += 'pageToken=' + (_params.nextPageToken || _params.prevPageToken) + '&';
156 | }
157 | break;
158 |
159 | case 'videosFromPlaylistById':
160 |
161 | youtubeSearchData = this.fillDataInObjectByList(youtubeSearchData, _params, [
162 | ['part', 'id,snippet'],
163 | ['type', 'video'],
164 | 'playlistId',
165 | 'maxResults',
166 | 'fields'
167 | ]);
168 |
169 | youtubeSearchData.url = this.getApiBaseUrl() + 'playlistItems?';
170 | if (_params.nextPageToken || _params.prevPageToken) {
171 | youtubeSearchData.url += 'pageToken=' + (_params.nextPageToken || _params.prevPageToken) + '&';
172 | }
173 | break;
174 |
175 | case 'videoById':
176 | youtubeSearchData = this.fillDataInObjectByList(youtubeSearchData, _params, [
177 | ['part', 'id,snippet,contentDetails,statistics'],
178 | ]);
179 |
180 | youtubeSearchData.object.id = _params.videoId;
181 |
182 | youtubeSearchData.url = this.getApiBaseUrl() + 'videos?';
183 | if (_params.nextPageToken || _params.prevPageToken) {
184 | youtubeSearchData.url += 'pageToken=' + (_params.nextPageToken || _params.prevPageToken) + '&';
185 | }
186 | break;
187 |
188 | case 'channelById':
189 | youtubeSearchData = this.fillDataInObjectByList(youtubeSearchData, _params, [
190 | ['part', 'id,snippet'],
191 | ['type', 'channel']
192 | ]);
193 |
194 | youtubeSearchData.url = this.getApiBaseUrl() + 'search?';
195 | if (_params.nextPageToken || _params.prevPageToken) {
196 | youtubeSearchData.url += 'pageToken=' + (_params.nextPageToken || _params.prevPageToken) + '&';
197 | }
198 | break;
199 |
200 | case 'channelByUsername':
201 |
202 | youtubeSearchData = this.fillDataInObjectByList(youtubeSearchData, _params, [
203 | ['part', 'id,snippet'],
204 | 'forUsername'
205 | ]);
206 |
207 | youtubeSearchData.url = this.getApiBaseUrl() + 'channels?';
208 | if (_params.nextPageToken || _params.prevPageToken) {
209 | youtubeSearchData.url += 'pageToken=' + (_params.nextPageToken || _params.prevPageToken) + '&';
210 | }
211 | break;
212 | }
213 |
214 | return youtubeSearchData;
215 | };
216 | });
217 |
--------------------------------------------------------------------------------
/dist/angular-youtube-api-factory.js:
--------------------------------------------------------------------------------
1 | /**
2 | @name: angular-youtube-api-factory
3 | @version: 0.6.2 (30-11-2017)
4 | @author: Jonathan Hornung
5 | @url: https://github.com/JohnnyTheTank/angular-youtube-api-factory#readme
6 | @license: MIT
7 | */
8 | "use strict";
9 |
10 | angular.module("jtt_youtube", [])
11 | .factory('youtubeFactory', ['$http', 'youtubeSearchDataService', function ($http, youtubeSearchDataService) {
12 |
13 | var youtubeFactory = {};
14 |
15 | youtubeFactory.getVideosFromChannelById = function (_params) {
16 | var youtubeSearchData = youtubeSearchDataService.getNew("videosFromChannelById", _params);
17 | return $http({
18 | method: 'GET',
19 | url: youtubeSearchData.url,
20 | params: youtubeSearchData.object,
21 | });
22 | };
23 |
24 | youtubeFactory.getVideosFromSearchByParams = function (_params) {
25 | var youtubeSearchData = youtubeSearchDataService.getNew("videosFromSearchByParams", _params);
26 | return $http({
27 | method: 'GET',
28 | url: youtubeSearchData.url,
29 | params: youtubeSearchData.object,
30 | });
31 | };
32 |
33 | youtubeFactory.getVideosFromPlaylistById = function (_params) {
34 | var youtubeSearchData = youtubeSearchDataService.getNew("videosFromPlaylistById", _params);
35 | return $http({
36 | method: 'GET',
37 | url: youtubeSearchData.url,
38 | params: youtubeSearchData.object,
39 | });
40 | };
41 |
42 | youtubeFactory.getChannelById = function (_params) {
43 | var youtubeSearchData = youtubeSearchDataService.getNew("channelById", _params);
44 | return $http({
45 | method: 'GET',
46 | url: youtubeSearchData.url,
47 | params: youtubeSearchData.object,
48 | });
49 | };
50 |
51 | youtubeFactory.getChannelByUsername = function (_params) {
52 | var youtubeSearchData = youtubeSearchDataService.getNew("channelByUsername", _params);
53 | return $http({
54 | method: 'GET',
55 | url: youtubeSearchData.url,
56 | params: youtubeSearchData.object,
57 | });
58 | };
59 |
60 | youtubeFactory.getVideoById = function (_params) {
61 | var youtubeSearchData = youtubeSearchDataService.getNew("videoById", _params);
62 | return $http({
63 | method: 'GET',
64 | url: youtubeSearchData.url,
65 | params: youtubeSearchData.object,
66 | });
67 | };
68 |
69 | return youtubeFactory;
70 | }])
71 | .service('youtubeSearchDataService', function () {
72 | this.getApiBaseUrl = function (_params) {
73 | return "https://content.googleapis.com/youtube/v3/";
74 | };
75 |
76 | this.fillDataInObjectByList = function (_object, _params, _list) {
77 |
78 | angular.forEach(_list, function (value, key) {
79 | if (typeof value !== "undefined" && value.constructor === Array) {
80 | if (angular.isDefined(_params[value[0]])) {
81 | _object.object[value[0]] = _params[value[0]];
82 | } else {
83 | _object.object[value[0]] = value[1];
84 | }
85 | } else {
86 | if (angular.isDefined(_params[value])) {
87 | _object.object[value] = _params[value];
88 | }
89 | }
90 | });
91 |
92 | return _object;
93 | };
94 |
95 | this.getNew = function (_type, _params) {
96 |
97 | var youtubeSearchData = {
98 | object: {
99 | key: _params.key,
100 | },
101 | url: '',
102 | };
103 |
104 | switch (_type) {
105 | case 'videosFromChannelById':
106 |
107 | youtubeSearchData = this.fillDataInObjectByList(youtubeSearchData, _params, [
108 | ['part', 'id,snippet'],
109 | ['type', 'video'],
110 | ['order', 'date'],
111 | ['videoEmbeddable', true],
112 | 'channelId',
113 | 'q',
114 | 'maxResults',
115 | 'publishedAfter',
116 | 'publishedBefore',
117 | 'regionCode',
118 | 'relevanceLanguage',
119 | 'safeSearch',
120 | 'videoLicense',
121 | 'videoSyndicated',
122 | 'fields'
123 | ]);
124 |
125 | youtubeSearchData.url = this.getApiBaseUrl() + 'search?';
126 |
127 | if (_params.nextPageToken || _params.prevPageToken) {
128 | youtubeSearchData.url += 'pageToken=' + (_params.nextPageToken || _params.prevPageToken) + '&';
129 | }
130 | break;
131 |
132 | case 'videosFromSearchByParams':
133 |
134 | youtubeSearchData = this.fillDataInObjectByList(youtubeSearchData, _params, [
135 | ['part', 'id,snippet'],
136 | ['type', 'video'],
137 | ['order', 'date'],
138 | ['videoEmbeddable', true],
139 | 'location',
140 | 'q',
141 | 'maxResults',
142 | 'publishedAfter',
143 | 'publishedBefore',
144 | 'regionCode',
145 | 'relevanceLanguage',
146 | 'safeSearch',
147 | 'videoLicense',
148 | 'videoSyndicated',
149 | 'fields'
150 | ]);
151 |
152 | if (angular.isDefined(_params.locationRadius)) {
153 | youtubeSearchData.object.locationRadius = _params.locationRadius;
154 | } else {
155 | if (angular.isDefined(_params.location)) {
156 | youtubeSearchData.object.locationRadius = '5000m'
157 | }
158 | }
159 |
160 | youtubeSearchData.url = this.getApiBaseUrl() + 'search?';
161 | if (_params.nextPageToken || _params.prevPageToken) {
162 | youtubeSearchData.url += 'pageToken=' + (_params.nextPageToken || _params.prevPageToken) + '&';
163 | }
164 | break;
165 |
166 | case 'videosFromPlaylistById':
167 |
168 | youtubeSearchData = this.fillDataInObjectByList(youtubeSearchData, _params, [
169 | ['part', 'id,snippet'],
170 | ['type', 'video'],
171 | 'playlistId',
172 | 'maxResults',
173 | 'fields'
174 | ]);
175 |
176 | youtubeSearchData.url = this.getApiBaseUrl() + 'playlistItems?';
177 | if (_params.nextPageToken || _params.prevPageToken) {
178 | youtubeSearchData.url += 'pageToken=' + (_params.nextPageToken || _params.prevPageToken) + '&';
179 | }
180 | break;
181 |
182 | case 'videoById':
183 | youtubeSearchData = this.fillDataInObjectByList(youtubeSearchData, _params, [
184 | ['part', 'id,snippet,contentDetails,statistics'],
185 | ]);
186 |
187 | youtubeSearchData.object.id = _params.videoId;
188 |
189 | youtubeSearchData.url = this.getApiBaseUrl() + 'videos?';
190 | if (_params.nextPageToken || _params.prevPageToken) {
191 | youtubeSearchData.url += 'pageToken=' + (_params.nextPageToken || _params.prevPageToken) + '&';
192 | }
193 | break;
194 |
195 | case 'channelById':
196 | youtubeSearchData = this.fillDataInObjectByList(youtubeSearchData, _params, [
197 | ['part', 'id,snippet'],
198 | ['type', 'channel']
199 | ]);
200 |
201 | youtubeSearchData.url = this.getApiBaseUrl() + 'search?';
202 | if (_params.nextPageToken || _params.prevPageToken) {
203 | youtubeSearchData.url += 'pageToken=' + (_params.nextPageToken || _params.prevPageToken) + '&';
204 | }
205 | break;
206 |
207 | case 'channelByUsername':
208 |
209 | youtubeSearchData = this.fillDataInObjectByList(youtubeSearchData, _params, [
210 | ['part', 'id,snippet'],
211 | 'forUsername'
212 | ]);
213 |
214 | youtubeSearchData.url = this.getApiBaseUrl() + 'channels?';
215 | if (_params.nextPageToken || _params.prevPageToken) {
216 | youtubeSearchData.url += 'pageToken=' + (_params.nextPageToken || _params.prevPageToken) + '&';
217 | }
218 | break;
219 | }
220 |
221 | return youtubeSearchData;
222 | };
223 | });
224 |
--------------------------------------------------------------------------------