purdie 0.0.8 → 0.0.9

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1defd8c81ee1d21b6f6a39584ca1836d4f4d281b
4
- data.tar.gz: 05a2275ab518862ebd272c0725b75056d533f614
3
+ metadata.gz: d177170f97f8a450e4d71facbf39f758da4b21ef
4
+ data.tar.gz: ea6e3b001078141fd3c36ac313245b3b8a658e17
5
5
  SHA512:
6
- metadata.gz: 4612b24c608b32764d7c4ce8a3b42e8ed080dbabce1726065ec85394209a6edfe561a8c87fd2492e8ce59c862840ba121e37e31a40e9fb233fcea66d37bd3151
7
- data.tar.gz: a0937e230214dfb2ee3033513c72a386f28560b84db2a9fce6426191b1818e4d44ae3e4d4a78dd343c9b420a6ebf5933dba2eabf9fb93e07e0804888b0f0d0bc
6
+ metadata.gz: 7e614308d4a9467a0dda0f69b38d9ee425ce8584132c0f06cec0bdcd046868585cfc32160480f567b4372baaddbd76041a0c71cc03c69ad2bd72fd55e2f75318
7
+ data.tar.gz: 9fe6faca8d5736f14647826b88927ef1c389744b6e220cc4b8db0b91c1fd55d5127c53a52742e7580460d544f3cb6631c625c9cd76aa8b4d86c923076aede7d8
data/README.md CHANGED
@@ -10,7 +10,7 @@
10
10
 
11
11
  We have 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/sounds.yml) [of](https://github.com/rawfunkmaharishi/rawfunkmaharishi.github.io/blob/master/_data/pictures.yml) [YAML](https://github.com/rawfunkmaharishi/rawfunkmaharishi.github.io/blob/master/_data/videos.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
12
 
13
- But you know what, It's 2015 and everything has an API, so let's build a robot to do this stuff properly!
13
+ But this is dumb. It's 2015 and everything has an API, so let's build a robot to do this stuff properly!
14
14
 
15
15
  ##The great metadata shift
16
16
 
@@ -24,19 +24,70 @@ Am I going to regret these decisions? Almost certainly.
24
24
 
25
25
  ##Using it
26
26
 
27
- You need to set up a *_sources* directory in your Jekyll project, containing files with one-URL-per-line, like this:
27
+ You need to create a *_sources* directory in your Jekyll project, containing files with one-URL-per-line, like this:
28
28
 
29
29
  https://soundcloud.com/rawfunkmaharishi/hexaflexagon-1
30
30
  https://soundcloud.com/rawfunkmaharishi/junalbandi-3
31
31
 
32
- and a *.env* with API keys in it, and then you can run
32
+ (you can alternatively specify a source file on the command line with the `-f` flag).
33
+
34
+ You also need a *.env* file with API secrets in it:
35
+
36
+ FLICKR_API_KEY: this_a_key
37
+ FLICKR_SECRET: this_a_secret
38
+
39
+ SOUNDCLOUD_CLIENT_ID: this_a_client_is
40
+ SOUNDCLOUD_USER_ID: this_a_user_id
41
+
42
+ VIMEO_BEARER_TOKEN: this_bearer_token
43
+
44
+ (get those keys 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))
45
+
46
+ And then you can run
33
47
 
34
48
  purdie fetch
35
49
 
36
50
  and it will dump out YAML files into *_data* ready for Jekyll to consume.
37
51
 
38
- For now, though, please don't. None of my metadata hacks are documented, it's got some very Raw Funk Maharishi-specific lookups nailed into it, the output filenames are hardcoded (so it may well overwrite stuff you care about), there are flickering tests, you'll have a bad time. But soon...
52
+ ###Customisation
53
+
54
+ You can supply your own _config/purdie.yaml_ file to specify a few things:
55
+
56
+ # Flickr photos are happy to have a null title
57
+ default_title: Raw Funk Maharishi
58
+
59
+ # Map Flickr users to better names
60
+ photographer_lookups:
61
+ pikesley: sam
62
+
63
+ # Specify output files per-service
64
+ services:
65
+ Flickr:
66
+ output_file: "_outfiles/photos.yaml"
67
+
68
+ (see [this](https://github.com/rawfunkmaharishi/purdie/blob/master/_config/defaults.yaml) for some other things you can tweak)
69
+
70
+ Tread carefully for now, because my metadata hacks aren't fully documented.
71
+
72
+ ##What next?
73
+
74
+ There's no reason I couldn't support other services - YouTube springs immediately to mind, and others should be fairly simple. 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:
75
+
76
+ * includes the `Purdie::Ingester` module, and
77
+ * sports a `#configure` method which sets at least a
78
+ * `@matcher` string which will pick a URL out of an input file, and an
79
+ * `@output_file`, and
80
+ * has a `#distill` method which takes a URL representing an item on the service and returns a hash of metadata, see e.g.
81
+ * [Flickr](https://github.com/rawfunkmaharishi/purdie/blob/master/lib/purdie/services/flickr.rb#L26-L48)
82
+ * [SoundCloud](https://github.com/rawfunkmaharishi/purdie/blob/master/lib/purdie/services/soundcloud.rb#L30-L41)
83
+ * [Vimeo](https://github.com/rawfunkmaharishi/purdie/blob/master/lib/purdie/services/vimeo.rb#L27-L37)
84
+
85
+ then this should all Just Work. There's definitely a blog post in this, because Ruby introspection and metaprogramming is just mind-bogglingly powerful (and dangerous).
39
86
 
87
+ More prosaically, I think it will be fairly simple to support Flickr sets and SoundCloud albums as input data.
88
+
89
+ And I can definitely rationalise these [horrible license lookups](https://github.com/rawfunkmaharishi/purdie/blob/master/_config/defaults.yaml#L5-L13) into a module or even a gem of their own.
90
+
40
91
  ##Why Purdie?
41
92
 
42
- Because Bernard Purdie is [amazing](https://www.youtube.com/watch?v=E9E0WxLbqVA&list=PLuPLM2FI60-OIgFTc9YCrGgH5XWGT6znV&index=6)
93
+ Because Bernard Purdie is [even more amazing that Ruby introspection](https://www.youtube.com/watch?v=E9E0WxLbqVA&list=PLuPLM2FI60-OIgFTc9YCrGgH5XWGT6znV&index=6).
@@ -1,13 +1,14 @@
1
- source-dir: _sources
2
- output-dir: _data
3
- default-title: Bernard Purdie, the World's most-recorded drummer
1
+ source_dir: _sources
2
+ output_dir: _data
3
+ default_title: Bernard Purdie, the World's most-recorded drummer
4
4
 
5
- license-lookups:
5
+ # those unwieldy lookups are because each service calls the CC licenses by a slightly different name and defaults to a different version of the license. I think I need to abstract all of this out into a modlue or even a gem of its own
6
+ license_lookups:
6
7
  cc-by-nc-sa:
7
- short-name: BY-NC-SA
8
- full-name: Attribution-NonCommercial-ShareAlike
8
+ short_name: BY-NC-SA
9
+ full_name: Attribution-NonCommercial-ShareAlike
9
10
  url: http://creativecommons.org/licenses/by-nc-sa/4.0/
10
11
  by-nc-sa:
11
- short-name: BY-NC-SA
12
- full-name: Attribution-NonCommercial-ShareAlike
12
+ short_name: BY-NC-SA
13
+ full_name: Attribution-NonCommercial-ShareAlike
13
14
  url: http://creativecommons.org/licenses/by-nc-sa/3.0/
@@ -0,0 +1,29 @@
1
+ @vcr
2
+ Feature: Flickr
3
+
4
+ Scenario: Generate Flickr YAML
5
+ Given a file named "_sources/flickr.csv" with:
6
+ """
7
+ https://www.flickr.com/photos/rawfunkmaharishi/15631479625/
8
+ """
9
+ And a file named "_config/purdie.yaml" with:
10
+ """
11
+ services:
12
+ Flickr:
13
+ output_file: "_outfiles/photos.yaml"
14
+ """
15
+ When I successfully run `purdie fetch`
16
+ Then a file named "_outfiles/photos.yaml" should exist
17
+ And the file "_outfiles/photos.yaml" should contain:
18
+ """
19
+ - title: The Comedy, October 2014
20
+ date: '2014-10-22'
21
+ photo_page: https://www.flickr.com/photos/rawfunkmaharishi/15631479625/
22
+ photo_url: https://farm4.staticflickr.com/3933/15631479625_b6168ee903_m.jpg
23
+ license: Attribution-NonCommercial-ShareAlike
24
+ license_url: https://creativecommons.org/licenses/by-nc-sa/2.0/
25
+ photographer: kim
26
+ """
27
+ And a file named "_data/flickr.yaml" should not exist
28
+ And a file named "_data/soundcloud.yaml" should not exist
29
+ And a file named "_data/vimeo.yaml" should not exist
@@ -1,4 +1,4 @@
1
- default-title: Raw Funk Maharishi
1
+ default_title: Raw Funk Maharishi
2
2
 
3
- photographer-lookups:
3
+ photographer_lookups:
4
4
  cluttercup: jane
@@ -17,7 +17,7 @@ http_interactions:
17
17
  message: OK
18
18
  headers:
19
19
  Date:
20
- - Tue, 03 Mar 2015 17:44:01 GMT
20
+ - Wed, 04 Mar 2015 22:02:49 GMT
21
21
  Server:
22
22
  - Apache
23
23
  Vary:
@@ -25,7 +25,7 @@ http_interactions:
25
25
  Cache-Control:
26
26
  - no-cache, max-age=315360000
27
27
  Expires:
28
- - Fri, 28 Feb 2025 17:44:01 GMT
28
+ - Sat, 01 Mar 2025 22:02:49 GMT
29
29
  Content-Length:
30
30
  - '3688'
31
31
  Content-Type:
@@ -37,5 +37,5 @@ http_interactions:
37
37
  string: '{"uri":"/videos/117102891","name":"Bernard","description":null,"link":"https://vimeo.com/117102891","duration":239,"width":1280,"language":null,"height":720,"created_time":"2015-01-18T17:26:10+00:00","modified_time":"2015-02-25T21:11:06+00:00","content_rating":["unrated"],"license":"by-nc-sa","privacy":{"view":"anybody","embed":"public","download":true,"add":true,"comments":"anybody"},"pictures":{"uri":"/videos/117102891/pictures/503683214","active":true,"sizes":[{"width":100,"height":75,"link":"https://i.vimeocdn.com/video/503683214_100x75.jpg"},{"width":200,"height":150,"link":"https://i.vimeocdn.com/video/503683214_200x150.jpg"},{"width":295,"height":166,"link":"https://i.vimeocdn.com/video/503683214_295x166.jpg"},{"width":640,"height":360,"link":"https://i.vimeocdn.com/video/503683214_640x360.jpg"},{"width":960,"height":540,"link":"https://i.vimeocdn.com/video/503683214_960x540.jpg"},{"width":1280,"height":720,"link":"https://i.vimeocdn.com/video/503683214_1280x720.jpg"}]},"tags":[],"stats":{"plays":18},"embed":{"buttons":{"like":true,"watchlater":true,"share":true,"embed":true,"hd":false,"fullscreen":true,"scaling":true},"logos":{"vimeo":true,"custom":{"active":false,"link":null,"sticky":false}},"title":{"name":"user","owner":"user","portrait":"user"},"playbar":true,"volume":true,"color":"00adef"},"metadata":{"connections":{"comments":{"uri":"/videos/117102891/comments","options":["GET","POST"],"total":0},"credits":{"uri":"/videos/117102891/credits","options":["GET","POST"],"total":1},"likes":{"uri":"/videos/117102891/likes","options":["GET"],"total":0},"pictures":{"uri":"/videos/117102891/pictures","options":["GET","POST"],"total":1},"texttracks":{"uri":"/videos/117102891/texttracks","options":["GET","POST"],"total":0}},"interactions":{"watchlater":{"added":false,"added_time":null,"uri":"/users/33772623/watchlater/117102891"}}},"embed_presets":null,"user":{"uri":"/users/33772623","name":"Raw
38
38
  Funk Maharishi","link":"https://vimeo.com/rawfunkmaharishi","location":null,"bio":null,"created_time":"2014-10-27T12:06:25+00:00","account":"basic","pictures":{"uri":"/users/33772623/pictures/8588995","active":true,"sizes":[{"width":30,"height":30,"link":"https://i.vimeocdn.com/portrait/8588995_30x30.jpg"},{"width":75,"height":75,"link":"https://i.vimeocdn.com/portrait/8588995_75x75.jpg"},{"width":100,"height":100,"link":"https://i.vimeocdn.com/portrait/8588995_100x100.jpg"},{"width":300,"height":300,"link":"https://i.vimeocdn.com/portrait/8588995_300x300.jpg"}]},"websites":[{"name":"http://rawfunkmaharishi.uk/","link":"http://rawfunkmaharishi.uk/","description":null}],"metadata":{"connections":{"activities":{"uri":"/users/33772623/activities","options":["GET"]},"albums":{"uri":"/users/33772623/albums","options":["GET"],"total":0},"channels":{"uri":"/users/33772623/channels","options":["GET"],"total":0},"feed":{"uri":"/users/33772623/feed","options":["GET"]},"followers":{"uri":"/users/33772623/followers","options":["GET"],"total":0},"following":{"uri":"/users/33772623/following","options":["GET"],"total":0},"groups":{"uri":"/users/33772623/groups","options":["GET"],"total":0},"likes":{"uri":"/users/33772623/likes","options":["GET"],"total":0},"portfolios":{"uri":"/users/33772623/portfolios","options":["GET"],"total":0},"videos":{"uri":"/users/33772623/videos","options":["GET"],"total":4},"watchlater":{"uri":"/users/33772623/watchlater","options":["GET"],"total":0},"shared":{"uri":"/users/33772623/shared/videos","options":["GET"],"total":0},"pictures":{"uri":"/users/33772623/pictures","options":["GET","POST"],"total":1}}},"content_filter":["language","drugs","violence","nudity","safe","unrated"]},"app":null,"status":"available"}'
39
39
  http_version:
40
- recorded_at: Tue, 03 Mar 2015 17:44:01 GMT
40
+ recorded_at: Wed, 04 Mar 2015 22:02:49 GMT
41
41
  recorded_with: VCR 2.9.3
@@ -7,8 +7,8 @@ module Purdie
7
7
  def initialize
8
8
  @config = Config.new
9
9
  begin
10
- @sources = Dir.entries(@config['source-dir']).select { |e| e !~ /^\./ }
11
- @sources.map! { |s| "#{@config['source-dir']}/#{s}"}
10
+ @sources = Dir.entries(@config['source_dir']).select { |e| e !~ /^\./ }
11
+ @sources.map! { |s| "#{@config['source_dir']}/#{s}"}
12
12
  rescue Errno::ENOENT
13
13
  @sources = nil
14
14
  end
data/lib/purdie/config.rb CHANGED
@@ -14,5 +14,9 @@ module Purdie
14
14
  def [] key
15
15
  @conf[key]
16
16
  end
17
+
18
+ def []= key, value
19
+ @conf[key] = value
20
+ end
17
21
  end
18
22
  end
@@ -21,6 +21,17 @@ module Purdie
21
21
  configure
22
22
  end
23
23
 
24
+ def configure
25
+ if @config['services']
26
+ if @config['services'][Purdie.basename self]
27
+ if @config['services'][Purdie.basename self]['output_file']
28
+ @config['output_dir'] = File.dirname(@config['services'][Purdie.basename self]['output_file'])
29
+ @output_file = File.basename(@config['services'][Purdie.basename self]['output_file'])
30
+ end
31
+ end
32
+ end
33
+ end
34
+
24
35
  def ingest url
25
36
  @items.push distill url
26
37
  end
@@ -39,9 +50,8 @@ module Purdie
39
50
 
40
51
  def write
41
52
  if self.has_items?
42
- FileUtils.mkdir_p @config['output-dir']
43
-
44
- File.open "#{@config['output-dir']}/#{@output_file}", 'w' do |f|
53
+ FileUtils.mkdir_p @config['output_dir']
54
+ File.open "#{@config['output_dir']}/#{@output_file}", 'w' do |f|
45
55
  f.write self.to_yaml
46
56
  end
47
57
  end
@@ -13,6 +13,8 @@ module Purdie
13
13
  def configure
14
14
  @matcher = 'flickr.com'
15
15
  @output_file = 'flickr.yaml'
16
+
17
+ super
16
18
  end
17
19
 
18
20
  def licenses
@@ -28,7 +30,7 @@ module Purdie
28
30
  results = {}
29
31
 
30
32
  results['title'] = photo['title']
31
- results['title'] = @config['default-title'] if photo['title'] == ''
33
+ results['title'] = @config['default_title'] if photo['title'] == ''
32
34
  results['date'] = photo['dates']['taken'].split(' ')[0]
33
35
  results['photo_page'] = photo['urls'][0]['_content']
34
36
  results['photo_url'] = FlickRaw.url_m(photo)
@@ -41,7 +43,7 @@ module Purdie
41
43
  snapper = photo['tags'].select { |t| t['raw'] =~ /photographer/ }[0]
42
44
  results['photographer'] = snapper['raw'].split(':')[1]
43
45
  rescue NoMethodError
44
- results['photographer'] = @config['photographer-lookups'][photo['owner']['username']]
46
+ results['photographer'] = @config['photographer_lookups'][photo['owner']['username']]
45
47
  unless results['photographer']
46
48
  results['photographer'] = photo['owner']['username']
47
49
  end
@@ -11,6 +11,8 @@ module Purdie
11
11
  @host = 'https://api.soundcloud.com'
12
12
  @matcher = 'soundcloud.com'
13
13
  @output_file = 'soundcloud.yaml'
14
+
15
+ super
14
16
  end
15
17
 
16
18
  def all_tracks
@@ -34,8 +36,8 @@ module Purdie
34
36
  results['id'] = track['id']
35
37
  results['location'] = track['description']
36
38
  results['date'] = "%4d-%02d-%02d" % [ track['release_year'], track['release_month'], track['release_day'] ]
37
- results['license'] = @config['license-lookups'][track['license']]['full-name']
38
- results['license_url'] = @config['license-lookups'][track['license']]['url']
39
+ results['license'] = @config['license_lookups'][track['license']]['full_name']
40
+ results['license_url'] = @config['license_lookups'][track['license']]['url']
39
41
 
40
42
  results
41
43
  end
@@ -9,6 +9,8 @@ module Purdie
9
9
  @host = 'https://api.vimeo.com'
10
10
  @matcher = 'vimeo.com'
11
11
  @output_file = 'vimeo.yaml'
12
+
13
+ super
12
14
  end
13
15
 
14
16
  def get url
@@ -30,8 +32,8 @@ module Purdie
30
32
 
31
33
  results['title'] = video['name']
32
34
  results['id'] = @id
33
- results['license'] = @config['license-lookups'][video['license']]['full-name']
34
- results['license_url'] = @config['license-lookups'][video['license']]['url']
35
+ results['license'] = @config['license_lookups'][video['license']]['full_name']
36
+ results['license_url'] = @config['license_lookups'][video['license']]['url']
35
37
 
36
38
  results
37
39
  end
@@ -1,3 +1,3 @@
1
1
  module Purdie
2
- VERSION = "0.0.8"
2
+ VERSION = "0.0.9"
3
3
  end
data/spec/config_spec.rb CHANGED
@@ -4,12 +4,12 @@ module Purdie
4
4
  describe Config do
5
5
  it 'has defaults' do
6
6
  c = Config.new
7
- expect(c['output-dir']).to eq '_data'
7
+ expect(c['output_dir']).to eq '_data'
8
8
  end
9
9
 
10
10
  it 'reads a local config file' do
11
11
  c = Config.new
12
- expect(c['default-title']).to eq 'Raw Funk Maharishi'
12
+ expect(c['default_title']).to eq 'Raw Funk Maharishi'
13
13
  end
14
14
  end
15
15
  end
data/spec/purdie_spec.rb CHANGED
@@ -4,7 +4,7 @@ module Purdie
4
4
  describe Bernard do
5
5
  it 'has config' do
6
6
  b = Bernard.new
7
- expect(b.config['output-dir']).to eq '_data'
7
+ expect(b.config['output_dir']).to eq '_data'
8
8
  end
9
9
 
10
10
  it 'does not throw a fit when initialized with no _sources dir' do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: purdie
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - pikesley
@@ -284,6 +284,7 @@ files:
284
284
  - cruft.rb
285
285
  - features/bad-url.feature
286
286
  - features/comments.feature
287
+ - features/flickr-alternative-outfile.feature
287
288
  - features/flickr.feature
288
289
  - features/no-sources.feature
289
290
  - features/purdie.feature
@@ -364,6 +365,7 @@ summary: Capture metadata from Flickr, SoundCloud et al for when we're building
364
365
  test_files:
365
366
  - features/bad-url.feature
366
367
  - features/comments.feature
368
+ - features/flickr-alternative-outfile.feature
367
369
  - features/flickr.feature
368
370
  - features/no-sources.feature
369
371
  - features/purdie.feature