purdie 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.travis.yml +1 -1
- data/README.md +12 -15
- data/features/soundcloud-set.feature +4 -0
- data/features/soundcloud.feature +3 -0
- data/lib/purdie.rb +0 -1
- data/lib/purdie/services/soundcloud.rb +2 -1
- data/lib/purdie/version.rb +1 -1
- data/purdie.gemspec +0 -1
- data/spec/purdie/duff_keys_spec.rb +0 -26
- data/spec/purdie/resolver_spec.rb +0 -6
- data/spec/purdie/services/soundcloud_spec.rb +2 -0
- metadata +3 -25
- data/features/youtube-playlist.feature +0 -52
- data/features/youtube.feature +0 -20
- data/lib/purdie/services/youtube.rb +0 -104
- data/spec/purdie/services/youtube_spec.rb +0 -40
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a14361f8e926e30d231a55883fd912f97d8819cd
|
4
|
+
data.tar.gz: d136e42f963c194290b756216219b47394b53961
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2ca8d9d2def2594320c9c74589ac5c796d9b98ef6f7df603947a17ee0b75320022b92270d4e774eea6d3aec9f293ab96fb17c0f7340fbf31f0325a787c3fbd6b
|
7
|
+
data.tar.gz: b00b45a907e843712b764e81f13f15388de8c8af60d88ce202ab7c4cd1e5c84e5294a24362bea809286a94d2262b1eabedeef516b249214adf39da5a73bca35f
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -4,11 +4,10 @@
|
|
4
4
|
[](https://codeclimate.com/github/rawfunkmaharishi/purdie)
|
5
5
|
[](https://rubygems.org/gems/purdie)
|
6
6
|
[](http://rawfunkmaharishi.mit-license.org)
|
7
|
-
[](https://github.com/badges/badgerbadgerbadger)
|
8
7
|
|
9
8
|
#Purdie
|
10
9
|
|
11
|
-
|
10
|
+
My band has music on SoundCloud, photos on Flickr, and videos on Vimeo, and we want to feature them on [http://rawfunkmaharishi.uk/](http://rawfunkmaharishi.uk/). Up until now, this has been managed by curating, by hand (or [very shonky scripts](https://github.com/rawfunkmaharishi/rawfunkmaharishi.github.io/blob/master/flickriser.rb)), [bits](https://github.com/rawfunkmaharishi/rawfunkmaharishi.github.io/blob/master/_data/soundcloud.yml) [of](https://github.com/rawfunkmaharishi/rawfunkmaharishi.github.io/blob/master/_data/flickr.yml) [YAML](https://github.com/rawfunkmaharishi/rawfunkmaharishi.github.io/blob/master/_data/vimeo.yml) to feed into Jekyll, but this gets old quickly, especially when you run into things like SoundCloud's decision to only expose the track ID deep inside the embeddable iframe code.
|
12
11
|
|
13
12
|
But this is dumb. It's 2015 and everything has an API, so let's build a robot to do this stuff properly!
|
14
13
|
|
@@ -18,7 +17,7 @@ Up until now, the Hand-Crafted YAML (which sounds like a thing you may be able t
|
|
18
17
|
|
19
18
|
###Moving the hacks upstream
|
20
19
|
|
21
|
-
Moving the metadata is not 100% foolproof, however: for example, we have photos on [our Flickr account](https://www.flickr.com/photos/rawfunkmaharishi/) which were not taken by us, but by our friend [Kim](http://www.kimberlycabbott.com/). But the Flickr API has no way of knowing this, so I've added a tag to those pictures which looks like `photographer:kim` and then I'm looking for and extracting that in this gem. Similarly, for the SoundCloud music, I'd like to tag them with a recording location but this is not supported, so I'm nailing
|
20
|
+
Moving the metadata is not 100% foolproof, however: for example, we have photos on [our Flickr account](https://www.flickr.com/photos/rawfunkmaharishi/) which were not taken by us, but by our friend [Kim](http://www.kimberlycabbott.com/). But the Flickr API has no way of knowing this, so I've added a tag to those pictures which looks like `photographer:kim` and then I'm looking for and extracting that in this gem. Similarly, for the SoundCloud music, I'd like to tag them with a recording location (and now an engineer's name) but this is not supported, so I'm nailing those into the _Description_ field as something YAML-ish.
|
22
21
|
|
23
22
|
Am I going to regret these decisions? Almost certainly.
|
24
23
|
|
@@ -38,7 +37,7 @@ or
|
|
38
37
|
|
39
38
|
###Configuration
|
40
39
|
|
41
|
-
You need to create a
|
40
|
+
You need to create a `_sources` directory in your Jekyll project, containing files with one-URL-per-line, like this:
|
42
41
|
|
43
42
|
https://soundcloud.com/rawfunkmaharishi/hexaflexagon-1
|
44
43
|
https://soundcloud.com/rawfunkmaharishi/junalbandi-3
|
@@ -47,13 +46,13 @@ It also resolves sets/albums on all of the supported services, so this kind of t
|
|
47
46
|
|
48
47
|
https://www.flickr.com/photos/pikesley/sets/72157648589429938/
|
49
48
|
|
50
|
-
####Notes about
|
49
|
+
####Notes about `_sources`:
|
51
50
|
|
52
51
|
* Purdie maps each input file onto an output file, replacing any extension with _.yaml_, something like:
|
53
|
-
*
|
54
|
-
*
|
55
|
-
*
|
56
|
-
*
|
52
|
+
* `_sources/flickr.csv` -> `_data/flickr.yaml`
|
53
|
+
* `_sources/pictures.source` -> `_data/pictures.yaml`
|
54
|
+
* `_sources/soundcloud.sounds` -> `_data/soundcloud.yaml`
|
55
|
+
* `_sources/vimeo` -> `_data/vimeo.yaml`
|
57
56
|
|
58
57
|
* Mixing up different services in the same input file makes no sense to Purdie. Don't do this
|
59
58
|
* If a URL appears multiple times in a resolved list, only the first appearance will be propagated to the output file
|
@@ -67,15 +66,13 @@ You also need a *.env* file with the relevant credentials in it:
|
|
67
66
|
|
68
67
|
VIMEO_BEARER_TOKEN: this_is_bearer_token
|
69
68
|
|
70
|
-
|
71
|
-
|
72
|
-
(get those things from [Flickr](https://www.flickr.com/services/apps/create/apply), [SoundCloud](http://soundcloud.com/you/apps/new), [Vimeo](https://developer.vimeo.com/apps/new) and [YouTube](https://console.developers.google.com/project))
|
69
|
+
(get those things from [Flickr](https://www.flickr.com/services/apps/create/apply), [SoundCloud](http://soundcloud.com/you/apps/new) and [Vimeo](https://developer.vimeo.com/apps/new)
|
73
70
|
|
74
71
|
And then you can run
|
75
72
|
|
76
73
|
purdie fetch
|
77
74
|
|
78
|
-
(`fetch` is the default task (in fact currently the only task), so just `purdie` will work) and it will dump out YAML files into
|
75
|
+
(`fetch` is the default task (in fact currently the only task), so just `purdie` will work) and it will dump out YAML files into `_data`:
|
79
76
|
|
80
77
|
flickr.yaml
|
81
78
|
pictures.yaml
|
@@ -86,7 +83,7 @@ ready for Jekyll to consume.
|
|
86
83
|
|
87
84
|
###Customisation
|
88
85
|
|
89
|
-
You can supply your own
|
86
|
+
You can supply your own `_config/purdie.yaml` file to specify a few things:
|
90
87
|
|
91
88
|
# Flickr photos are happy to have a null title
|
92
89
|
default_title: Raw Funk Maharishi
|
@@ -108,7 +105,7 @@ Tread carefully for now, because my metadata hacks aren't fully documented, and
|
|
108
105
|
|
109
106
|
##What next?
|
110
107
|
|
111
|
-
There's no reason I couldn't support other services
|
108
|
+
There's no reason I couldn't support other services. There's some introspection magic at the heart of all of this which means that as long as each service is represented by a class that:
|
112
109
|
|
113
110
|
* includes the `Purdie::Service` module, and
|
114
111
|
* sports a `::matcher` class method which returns a string which will pick a URL out of an input file, and
|
@@ -13,24 +13,28 @@ Feature: Soundcloud set
|
|
13
13
|
---
|
14
14
|
- title: Hexaflexagon
|
15
15
|
id: 193008299
|
16
|
+
url: http://soundcloud.com/rawfunkmaharishi/hexaflexagon-1
|
16
17
|
location: Islington Academy
|
17
18
|
date: '2015-02-18'
|
18
19
|
license: Attribution-NonCommercial-ShareAlike
|
19
20
|
license_url: http://creativecommons.org/licenses/by-nc-sa/4.0/
|
20
21
|
- title: Beer, Of Course, But Why
|
21
22
|
id: 193006525
|
23
|
+
url: http://soundcloud.com/rawfunkmaharishi/beer-of-course-but-why
|
22
24
|
location: Islington Academy
|
23
25
|
date: '2015-02-18'
|
24
26
|
license: Attribution-NonCommercial-ShareAlike
|
25
27
|
license_url: http://creativecommons.org/licenses/by-nc-sa/4.0/
|
26
28
|
- title: Junalbandi
|
27
29
|
id: 193005357
|
30
|
+
url: http://soundcloud.com/rawfunkmaharishi/junalbandi-3
|
28
31
|
location: Islington Academy
|
29
32
|
date: '2015-02-18'
|
30
33
|
license: Attribution-NonCommercial-ShareAlike
|
31
34
|
license_url: http://creativecommons.org/licenses/by-nc-sa/4.0/
|
32
35
|
- title: Bernard
|
33
36
|
id: 192841052
|
37
|
+
url: http://soundcloud.com/rawfunkmaharishi/bernard
|
34
38
|
location: Islington Academy
|
35
39
|
date: '2015-02-18'
|
36
40
|
license: Attribution-NonCommercial-ShareAlike
|
data/features/soundcloud.feature
CHANGED
@@ -12,6 +12,7 @@ Feature: Soundcloud
|
|
12
12
|
"""
|
13
13
|
- title: Hexaflexagon
|
14
14
|
id: 193008299
|
15
|
+
url: http://soundcloud.com/rawfunkmaharishi/hexaflexagon-1
|
15
16
|
location: Islington Academy
|
16
17
|
date: '2015-02-18'
|
17
18
|
license: Attribution-NonCommercial-ShareAlike
|
@@ -30,12 +31,14 @@ Feature: Soundcloud
|
|
30
31
|
"""
|
31
32
|
- title: Hexaflexagon
|
32
33
|
id: 193008299
|
34
|
+
url: http://soundcloud.com/rawfunkmaharishi/hexaflexagon-1
|
33
35
|
location: Islington Academy
|
34
36
|
date: '2015-02-18'
|
35
37
|
license: Attribution-NonCommercial-ShareAlike
|
36
38
|
license_url: http://creativecommons.org/licenses/by-nc-sa/4.0/
|
37
39
|
- title: Junalbandi
|
38
40
|
id: 193005357
|
41
|
+
url: http://soundcloud.com/rawfunkmaharishi/junalbandi-3
|
39
42
|
location: Islington Academy
|
40
43
|
date: '2015-02-18'
|
41
44
|
license: Attribution-NonCommercial-ShareAlike
|
data/lib/purdie.rb
CHANGED
@@ -21,7 +21,8 @@ module Purdie
|
|
21
21
|
results = {}
|
22
22
|
results['title'] = track['title']
|
23
23
|
results['id'] = track['id']
|
24
|
-
|
24
|
+
results['url'] = track['permalink_url']
|
25
|
+
|
25
26
|
description = YAML.load track['description']
|
26
27
|
if description.class == Hash
|
27
28
|
description.keys.each do |k|
|
data/lib/purdie/version.rb
CHANGED
data/purdie.gemspec
CHANGED
@@ -25,7 +25,6 @@ Gem::Specification.new do |spec|
|
|
25
25
|
spec.add_dependency 'flickraw-cached', '= 20120701'
|
26
26
|
spec.add_dependency 'soundcloud', '~> 0.3'
|
27
27
|
spec.add_dependency 'activesupport', '~> 4.2'
|
28
|
-
spec.add_dependency 'google-api-client', '~> 0.8'
|
29
28
|
|
30
29
|
spec.add_development_dependency 'bundler', '~> 1.7'
|
31
30
|
spec.add_development_dependency 'rake', '~> 10.0'
|
@@ -85,31 +85,5 @@ module Purdie
|
|
85
85
|
}
|
86
86
|
end
|
87
87
|
end
|
88
|
-
|
89
|
-
describe YouTube do
|
90
|
-
after :each do
|
91
|
-
reset_env
|
92
|
-
end
|
93
|
-
|
94
|
-
it 'responds usefully in the face of no credentials' do
|
95
|
-
unset_env
|
96
|
-
y = YouTube.new
|
97
|
-
expect { y.distill 'https://www.youtube.com/watch?v=JCix1XW329g' }.to raise_exception { |e|
|
98
|
-
expect(e).to be_a Purdie::CredentialsException
|
99
|
-
expect(e.service.class).to eq Purdie::Services::YouTube
|
100
|
-
expect(e.message).to eq 'missing'
|
101
|
-
}
|
102
|
-
end
|
103
|
-
|
104
|
-
it 'responds usefully in the face of duff credentials' do
|
105
|
-
randomise_env
|
106
|
-
y = YouTube.new
|
107
|
-
expect { y.distill 'https://www.youtube.com/watch?v=JCix1XW329g' }.to raise_exception { |e|
|
108
|
-
expect(e).to be_a Purdie::CredentialsException
|
109
|
-
expect(e.service.class).to eq Purdie::Services::YouTube
|
110
|
-
expect(e.message).to eq 'duff'
|
111
|
-
}
|
112
|
-
end
|
113
|
-
end
|
114
88
|
end
|
115
89
|
end
|
@@ -30,11 +30,5 @@ module Purdie
|
|
30
30
|
expect(Purdie.strip_scheme resolved[0]).to eq '//soundcloud.com/rawfunkmaharishi/beer-of-course-but-why'
|
31
31
|
expect(Purdie.strip_scheme resolved[2]).to eq '//soundcloud.com/rawfunkmaharishi/junalbandi-3'
|
32
32
|
end
|
33
|
-
|
34
|
-
it 'resolves a YouTube playlist', :vcr do
|
35
|
-
resolved = Resolver.resolve 'https://www.youtube.com/playlist?list=PLuPLM2FI60-OIgFTc9YCrGgH5XWGT6znV'
|
36
|
-
expect(resolved.count).to eq 9
|
37
|
-
expect(Purdie.strip_scheme resolved.first).to eq '//youtube.com/watch?v=U23Ezi6q30E'
|
38
|
-
end
|
39
33
|
end
|
40
34
|
end
|
@@ -17,6 +17,7 @@ module Purdie
|
|
17
17
|
"---
|
18
18
|
title: Hexaflexagon
|
19
19
|
id: 193008299
|
20
|
+
url: http://soundcloud.com/rawfunkmaharishi/hexaflexagon-1
|
20
21
|
location: Islington Academy
|
21
22
|
date: '2015-02-18'
|
22
23
|
license: Attribution-NonCommercial-ShareAlike
|
@@ -31,6 +32,7 @@ license_url: http://creativecommons.org/licenses/by-nc-sa/4.0/
|
|
31
32
|
"---
|
32
33
|
title: Don The Crown
|
33
34
|
id: 234830006
|
35
|
+
url: http://soundcloud.com/rawfunkmaharishi/don-the-crown-1
|
34
36
|
location: Rogue Studios
|
35
37
|
engineer: Alessio
|
36
38
|
date: '2015-11-25'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: purdie
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- pikesley
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-01-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|
@@ -108,20 +108,6 @@ dependencies:
|
|
108
108
|
- - "~>"
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: '4.2'
|
111
|
-
- !ruby/object:Gem::Dependency
|
112
|
-
name: google-api-client
|
113
|
-
requirement: !ruby/object:Gem::Requirement
|
114
|
-
requirements:
|
115
|
-
- - "~>"
|
116
|
-
- !ruby/object:Gem::Version
|
117
|
-
version: '0.8'
|
118
|
-
type: :runtime
|
119
|
-
prerelease: false
|
120
|
-
version_requirements: !ruby/object:Gem::Requirement
|
121
|
-
requirements:
|
122
|
-
- - "~>"
|
123
|
-
- !ruby/object:Gem::Version
|
124
|
-
version: '0.8'
|
125
111
|
- !ruby/object:Gem::Dependency
|
126
112
|
name: bundler
|
127
113
|
requirement: !ruby/object:Gem::Requirement
|
@@ -358,8 +344,6 @@ files:
|
|
358
344
|
- features/support/vcr.rb
|
359
345
|
- features/vimeo-albums.feature
|
360
346
|
- features/vimeo.feature
|
361
|
-
- features/youtube-playlist.feature
|
362
|
-
- features/youtube.feature
|
363
347
|
- lib/purdie.rb
|
364
348
|
- lib/purdie/bernard.rb
|
365
349
|
- lib/purdie/cli.rb
|
@@ -373,7 +357,6 @@ files:
|
|
373
357
|
- lib/purdie/services/flickr.rb
|
374
358
|
- lib/purdie/services/soundcloud.rb
|
375
359
|
- lib/purdie/services/vimeo.rb
|
376
|
-
- lib/purdie/services/youtube.rb
|
377
360
|
- lib/purdie/source_list.rb
|
378
361
|
- lib/purdie/version.rb
|
379
362
|
- purdie.gemspec
|
@@ -387,7 +370,6 @@ files:
|
|
387
370
|
- spec/purdie/services/flickr_spec.rb
|
388
371
|
- spec/purdie/services/soundcloud_spec.rb
|
389
372
|
- spec/purdie/services/vimeo_spec.rb
|
390
|
-
- spec/purdie/services/youtube_spec.rb
|
391
373
|
- spec/purdie/source_list_spec.rb
|
392
374
|
- spec/spec_helper.rb
|
393
375
|
- spec/support/fixtures/output-generator
|
@@ -450,7 +432,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
450
432
|
version: '0'
|
451
433
|
requirements: []
|
452
434
|
rubyforge_project:
|
453
|
-
rubygems_version: 2.
|
435
|
+
rubygems_version: 2.5.1
|
454
436
|
signing_key:
|
455
437
|
specification_version: 4
|
456
438
|
summary: Capture metadata from Flickr, SoundCloud et al for when we're building a
|
@@ -504,8 +486,6 @@ test_files:
|
|
504
486
|
- features/support/vcr.rb
|
505
487
|
- features/vimeo-albums.feature
|
506
488
|
- features/vimeo.feature
|
507
|
-
- features/youtube-playlist.feature
|
508
|
-
- features/youtube.feature
|
509
489
|
- spec/purdie/bernard_spec.rb
|
510
490
|
- spec/purdie/config_spec.rb
|
511
491
|
- spec/purdie/duff_keys_spec.rb
|
@@ -516,7 +496,6 @@ test_files:
|
|
516
496
|
- spec/purdie/services/flickr_spec.rb
|
517
497
|
- spec/purdie/services/soundcloud_spec.rb
|
518
498
|
- spec/purdie/services/vimeo_spec.rb
|
519
|
-
- spec/purdie/services/youtube_spec.rb
|
520
499
|
- spec/purdie/source_list_spec.rb
|
521
500
|
- spec/spec_helper.rb
|
522
501
|
- spec/support/fixtures/output-generator
|
@@ -559,4 +538,3 @@ test_files:
|
|
559
538
|
- spec/vcr/Purdie_SourceList/resolve_sets/resolves_a_Flickr_set.yml
|
560
539
|
- spec/vcr/Purdie_SourceList/resolve_sets/resolves_a_SoundCloud_set.yml
|
561
540
|
- spec/vcr/Purdie_SourceList/resolves_a_Flickr_set.yml
|
562
|
-
has_rdoc:
|
@@ -1,52 +0,0 @@
|
|
1
|
-
@vcr
|
2
|
-
Feature: YouTube playlists
|
3
|
-
|
4
|
-
Scenario: Generate YAML for a YouTube playlist
|
5
|
-
Given a file named "_sources/youtube" with:
|
6
|
-
"""
|
7
|
-
https://www.youtube.com/playlist?list=PLuPLM2FI60-OIgFTc9YCrGgH5XWGT6znV
|
8
|
-
"""
|
9
|
-
When I successfully run `purdie fetch`
|
10
|
-
Then a file named "_data/youtube.yaml" should exist
|
11
|
-
And the file "_data/youtube.yaml" should contain:
|
12
|
-
"""
|
13
|
-
---
|
14
|
-
- title: Chuck Rainey - Bernard Purdie Project "Love the One Your With...Drink Muddy
|
15
|
-
Water"
|
16
|
-
id: U23Ezi6q30E
|
17
|
-
license: YouTube
|
18
|
-
license_url: https://www.youtube.com/static?gl=GB&template=terms
|
19
|
-
- title: Godfathers of Groove Bernard "Pretty" Purdie,Grant Green Jr,Ruben Wilson
|
20
|
-
March 30-31
|
21
|
-
id: _ZbWTg8G6eM
|
22
|
-
license: YouTube
|
23
|
-
license_url: https://www.youtube.com/static?gl=GB&template=terms
|
24
|
-
- title: Pretty Purdie - Good Livin' (Good Lovin') HQ
|
25
|
-
id: zJnnNZk9o0Q
|
26
|
-
license: YouTube
|
27
|
-
license_url: https://www.youtube.com/static?gl=GB&template=terms
|
28
|
-
- title: Hot Popcorn Bernard Purdie
|
29
|
-
id: baQe6MoSAHw
|
30
|
-
license: YouTube
|
31
|
-
license_url: https://www.youtube.com/static?gl=GB&template=terms
|
32
|
-
- title: Red Beans and Rice Bernard Purdie
|
33
|
-
id: NLFP1T1e2BA
|
34
|
-
license: YouTube
|
35
|
-
license_url: https://www.youtube.com/static?gl=GB&template=terms
|
36
|
-
- title: Bernard Purdie - Ad Lib
|
37
|
-
id: E9E0WxLbqVA
|
38
|
-
license: YouTube
|
39
|
-
license_url: https://www.youtube.com/static?gl=GB&template=terms
|
40
|
-
- title: Bernard Purdie - Black Purd's Theme
|
41
|
-
id: wa-K4LouFVk
|
42
|
-
license: YouTube
|
43
|
-
license_url: https://www.youtube.com/static?gl=GB&template=terms
|
44
|
-
- title: Bernard "Pretty" Purdie - Heavy Soul Slinger
|
45
|
-
id: LatmKZQd7-s
|
46
|
-
license: YouTube
|
47
|
-
license_url: https://www.youtube.com/static?gl=GB&template=terms
|
48
|
-
- title: 'Bernard "Pretty" Purdie: Funky Grooves in Japan'
|
49
|
-
id: P842kq0bnOc
|
50
|
-
license: YouTube
|
51
|
-
license_url: https://www.youtube.com/static?gl=GB&template=terms
|
52
|
-
"""
|
data/features/youtube.feature
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
@vcr
|
2
|
-
Feature: YouTube
|
3
|
-
|
4
|
-
Scenario: Generate YouTube YAML
|
5
|
-
Given a file named "_sources/youtube.movies" with:
|
6
|
-
"""
|
7
|
-
https://www.youtube.com/watch?v=Qt_J0jNqtZg&list=PLuPLM2FI60-M0-aWejF9WgB-Dkt1TuQXv&index=2
|
8
|
-
"""
|
9
|
-
When I successfully run `purdie fetch`
|
10
|
-
Then a file named "_data/youtube.yaml" should exist
|
11
|
-
And the file "_data/youtube.yaml" should contain:
|
12
|
-
"""
|
13
|
-
- title: Sam Pikesley – Vandalising your Github commit history for fun and profit
|
14
|
-
id: Qt_J0jNqtZg
|
15
|
-
license: Attribution
|
16
|
-
license_url: https://creativecommons.org/licenses/by/3.0/
|
17
|
-
"""
|
18
|
-
And a file named "_data/soundcloud.yaml" should not exist
|
19
|
-
And a file named "_data/vimeo.yaml" should not exist
|
20
|
-
And a file named "_data/flickr.yaml" should not exist
|
@@ -1,104 +0,0 @@
|
|
1
|
-
require 'google/api_client'
|
2
|
-
|
3
|
-
module Purdie
|
4
|
-
module Services
|
5
|
-
class YouTube
|
6
|
-
include Service
|
7
|
-
|
8
|
-
API_SERVICE_NAME = 'youtube'
|
9
|
-
API_VERSION = 'v3'
|
10
|
-
|
11
|
-
def configure
|
12
|
-
@api_service_name = 'youtube'
|
13
|
-
@api_version = 'v3'
|
14
|
-
super
|
15
|
-
end
|
16
|
-
|
17
|
-
def client
|
18
|
-
@client ||= Google::APIClient.new(
|
19
|
-
key: ENV['YOUTUBE_API_KEY'],
|
20
|
-
authorization: nil,
|
21
|
-
application_name: self.class.name.split('::').first,
|
22
|
-
application_version: Purdie::VERSION
|
23
|
-
)
|
24
|
-
end
|
25
|
-
|
26
|
-
def yt_service
|
27
|
-
@yt_service ||= client.discovered_api(
|
28
|
-
@api_service_name,
|
29
|
-
@api_version
|
30
|
-
)
|
31
|
-
end
|
32
|
-
|
33
|
-
def get_data id, part
|
34
|
-
client.execute!(
|
35
|
-
api_method: yt_service.videos.list,
|
36
|
-
parameters: {
|
37
|
-
id: id,
|
38
|
-
part: part
|
39
|
-
}
|
40
|
-
)
|
41
|
-
end
|
42
|
-
|
43
|
-
def get url
|
44
|
-
begin
|
45
|
-
data = get_data Purdie.get_id(url), 'status,snippet'
|
46
|
-
JSON.parse data.body
|
47
|
-
rescue Google::APIClient::ClientError => ce
|
48
|
-
raise Purdie::CredentialsException.new self, 'missing' if ce.message.match /Daily Limit for Unauthenticated Use Exceeded/
|
49
|
-
raise Purdie::CredentialsException.new self, 'duff' if ce.message.match /Bad Request/
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
def distill url
|
54
|
-
video = get url
|
55
|
-
results = {}
|
56
|
-
|
57
|
-
results['title'] = video['items'][0]['snippet']['localized']['title']
|
58
|
-
results['id'] = Purdie.get_id(url)
|
59
|
-
|
60
|
-
results.attach_license self, video['items'][0]['status']['license']
|
61
|
-
|
62
|
-
results
|
63
|
-
end
|
64
|
-
|
65
|
-
def self.resolve url
|
66
|
-
query = CGI.parse(URI.parse(url).query).keys
|
67
|
-
return [url] unless (query.include?('list') and not query.include?('index'))
|
68
|
-
|
69
|
-
set = YouTube.client.execute!(
|
70
|
-
api_method: YouTube.yt_service.playlist_items.list,
|
71
|
-
parameters: {
|
72
|
-
playlistId: 'PLuPLM2FI60-OIgFTc9YCrGgH5XWGT6znV',
|
73
|
-
part: 'contentDetails',
|
74
|
-
maxResults: 50
|
75
|
-
}
|
76
|
-
).body
|
77
|
-
|
78
|
-
ids = JSON.parse(set)['items'].map { |v| v['contentDetails']['videoId'] }
|
79
|
-
|
80
|
-
ids.map { |id| "https://youtube.com/watch?v=#{id}"}
|
81
|
-
end
|
82
|
-
|
83
|
-
def self.client
|
84
|
-
Google::APIClient.new(
|
85
|
-
key: ENV['YOUTUBE_API_KEY'],
|
86
|
-
authorization: nil,
|
87
|
-
application_name: self.class.name.split('::').first,
|
88
|
-
application_version: Purdie::VERSION
|
89
|
-
)
|
90
|
-
end
|
91
|
-
|
92
|
-
def self.yt_service
|
93
|
-
client.discovered_api(
|
94
|
-
API_SERVICE_NAME,
|
95
|
-
API_VERSION
|
96
|
-
)
|
97
|
-
end
|
98
|
-
|
99
|
-
def self.matcher
|
100
|
-
'youtube.com'
|
101
|
-
end
|
102
|
-
end
|
103
|
-
end
|
104
|
-
end
|
@@ -1,40 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
module Purdie
|
4
|
-
module Services
|
5
|
-
describe YouTube do
|
6
|
-
before :each do
|
7
|
-
@yt = YouTube.new
|
8
|
-
end
|
9
|
-
|
10
|
-
it 'gets a video', :vcr do
|
11
|
-
expect(@yt.get 'https://www.youtube.com/watch?v=JCix1XW329g').to be_a Hash
|
12
|
-
end
|
13
|
-
|
14
|
-
it 'has yaml for a video', :vcr do
|
15
|
-
dist = @yt.distill 'https://www.youtube.com/watch?v=JCix1XW329g'
|
16
|
-
expect(dist.to_yaml).to eq(
|
17
|
-
"---
|
18
|
-
title: EMFCamp 2014 Day 3 Lightning talk 6
|
19
|
-
id: JCix1XW329g
|
20
|
-
license: Attribution
|
21
|
-
license_url: https://creativecommons.org/licenses/by/3.0/
|
22
|
-
"
|
23
|
-
)
|
24
|
-
end
|
25
|
-
|
26
|
-
it 'gets the correct license', :vcr do
|
27
|
-
vid = @yt.distill 'https://www.youtube.com/watch?v=baQe6MoSAHw'
|
28
|
-
expect(vid['license']).to eq 'YouTube'
|
29
|
-
end
|
30
|
-
|
31
|
-
context 'resolve a playlist', :vcr do
|
32
|
-
it 'resolves a playlist from a shitty YouTube URL', :vcr do
|
33
|
-
list = YouTube.resolve 'https://www.youtube.com/playlist?list=PLuPLM2FI60-OIgFTc9YCrGgH5XWGT6znV'
|
34
|
-
expect(list.count).to eq 9
|
35
|
-
expect(list[8]).to eq 'https://youtube.com/watch?v=P842kq0bnOc'
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|