Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add YouTube fields parsing and refactoring #31

Merged
merged 2 commits into from Jun 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
@@ -1,5 +1,11 @@
# Change Log

## 2.1.0 (2022-06-23)

### Features / Enhancements

- Add YouTube fields parsing and refactoring (#31)

## 2.0.0 (2022-06-17)

### Breaking changes
Expand Down
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -39,6 +39,7 @@ grafana-cli plugins install volkovlabs-rss-datasource
- Extract and parse as additional fields:
- Image from Meta.
- H4 and Image from the Encoded content.
- Media:Group for YouTube.
- Filter items/entries based on the selected Time Range.

## Provisioning
Expand Down
1 change: 1 addition & 0 deletions docker-compose.yml
Expand Up @@ -14,6 +14,7 @@ services:
- GF_USERS_DEFAULT_THEME=light
- GF_INSTALL_PLUGINS=marcusolsson-dynamictext-panel
- GF_DEFAULT_APP_MODE=development
- GF_DASHBOARDS_DEFAULT_HOME_DASHBOARD_PATH=/etc/grafana/provisioning/dashboards/panels.json
- GF_PANELS_DISABLE_SANITIZE_HTML=true
volumes:
- ./dist:/var/lib/grafana/plugins/volkovlabs-rss-datasource
Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -27,5 +27,5 @@
"upgrade": "yarn upgrade --latest",
"watch": "grafana-toolkit plugin:dev --watch"
},
"version": "2.0.0"
"version": "2.1.0"
}
120 changes: 84 additions & 36 deletions provisioning/dashboards/panels.json
Expand Up @@ -125,17 +125,17 @@
{
"datasource": {
"type": "volkovlabs-rss-datasource",
"uid": "P18E95235D4DEADAE"
"uid": "rZAdZdf82"
},
"gridPos": {
"h": 17,
"w": 13,
"x": 0,
"y": 17
},
"id": 3,
"id": 13,
"options": {
"content": "# {{date pubDate 'LLL'}} <a target=\"_blank\" style=\"color: blue\" href=\"{{link}}\">{{title}}</a>\n{{description}}\n\n<a href='{{guid}}' style='color:gray'>{{guid}}</a>",
"content": "<table width=100% style='border:0'>\n<tr>\n<td style='border:0'><h3><a target=\"_blank\" style=\"color: blue\" href=\"{{link}}\">{{title}}</a></h3>\n{{{content:h4}}}</td>\n<td rowspan=2 style='border:0' width=200px>\n<div style='max-width: 100%; display: inline; height: auto '><img width=200px height=100% src=\"{{media:group:media:thumbnail:url}}\"></div></td>\n</tr>\n<tr>\n<td style='border:0'><b>{{date updated 'MMM, DD YYYY'}} by {{author}}</b></td>\n</table>",
"defaultContent": "The query didn't return any results.",
"everyRow": true
},
Expand All @@ -144,23 +144,24 @@
{
"datasource": {
"type": "volkovlabs-rss-datasource",
"uid": "P18E95235D4DEADAE"
"uid": "rZAdZdf82"
},
"dateField": "pubDate",
"dateField": "updated",
"feedType": "items",
"queryText": "test",
"refId": "A"
}
],
"title": "Amazon CloudFront Service Status",
"title": "Volkov Labs YouTube",
"transformations": [
{
"id": "convertFieldType",
"options": {
"conversions": [
{
"dateFormat": "ddd, DD MMM YYYY HH:mm:ss ZZ",
"dateFormat": "",
"destinationType": "time",
"targetField": "pubDate"
"targetField": "updated"
}
],
"fields": {}
Expand Down Expand Up @@ -219,17 +220,17 @@
{
"datasource": {
"type": "volkovlabs-rss-datasource",
"uid": "PE12154EB4CA97411"
"uid": "P18E95235D4DEADAE"
},
"gridPos": {
"h": 17,
"w": 13,
"x": 0,
"y": 34
},
"id": 7,
"id": 3,
"options": {
"content": "# {{date pubDate 'LLL'}} <a target=\"_blank\" style=\"color: blue\" href=\"{{link}}\">{{title}}</a>\n{{{summary}}}",
"content": "# {{date pubDate 'LLL'}} <a target=\"_blank\" style=\"color: blue\" href=\"{{link}}\">{{title}}</a>\n{{description}}\n\n<a href='{{guid}}' style='color:gray'>{{guid}}</a>",
"defaultContent": "The query didn't return any results.",
"everyRow": true
},
Expand All @@ -238,14 +239,14 @@
{
"datasource": {
"type": "volkovlabs-rss-datasource",
"uid": "PE12154EB4CA97411"
"uid": "P18E95235D4DEADAE"
},
"dateField": "updated",
"dateField": "pubDate",
"feedType": "items",
"refId": "A"
}
],
"title": "Google Workspace",
"title": "Amazon CloudFront Service Status",
"transformations": [
{
"id": "convertFieldType",
Expand Down Expand Up @@ -314,17 +315,17 @@
{
"datasource": {
"type": "volkovlabs-rss-datasource",
"uid": "rZAdZdf72"
"uid": "PE12154EB4CA97411"
},
"gridPos": {
"h": 17,
"w": 13,
"x": 0,
"y": 51
},
"id": 9,
"id": 7,
"options": {
"content": "<table width=100% style='border:0'>\n<tr>\n<td style='border:0'><h3><a target=\"_blank\" style=\"color: blue\" href=\"{{link}}\">{{title}}</a> on {{date dc:date 'MMM, DD YYYY'}}</h3>\n{{{description}}}</td>\n</tr>\n</table>",
"content": "# {{date pubDate 'LLL'}} <a target=\"_blank\" style=\"color: blue\" href=\"{{link}}\">{{title}}</a>\n{{{summary}}}",
"defaultContent": "The query didn't return any results.",
"everyRow": true
},
Expand All @@ -333,40 +334,27 @@
{
"datasource": {
"type": "volkovlabs-rss-datasource",
"uid": "rZAdZdf72"
"uid": "PE12154EB4CA97411"
},
"dateField": "dc:date",
"dateField": "updated",
"feedType": "items",
"queryText": "test",
"refId": "A"
}
],
"title": "National Vulnerability Database",
"title": "Google Workspace",
"transformations": [
{
"id": "convertFieldType",
"options": {
"conversions": [
{
"dateFormat": "YYYY-MM-DDThh:mm:ssZ",
"dateFormat": "ddd, DD MMM YYYY HH:mm:ss ZZ",
"destinationType": "time",
"targetField": "dc:date"
"targetField": "pubDate"
}
],
"fields": {}
}
},
{
"id": "sortBy",
"options": {
"fields": {},
"sort": [
{
"desc": true,
"field": "dc:date"
}
]
}
}
],
"type": "marcusolsson-dynamictext-panel"
Expand Down Expand Up @@ -418,6 +406,66 @@
}
],
"type": "marcusolsson-dynamictext-panel"
},
{
"datasource": {
"type": "volkovlabs-rss-datasource",
"uid": "rZAdZdf72"
},
"gridPos": {
"h": 17,
"w": 13,
"x": 0,
"y": 68
},
"id": 9,
"options": {
"content": "<table width=100% style='border:0'>\n<tr>\n<td style='border:0'><h3><a target=\"_blank\" style=\"color: blue\" href=\"{{link}}\">{{title}}</a> on {{date dc:date 'MMM, DD YYYY'}}</h3>\n{{{description}}}</td>\n</tr>\n</table>",
"defaultContent": "The query didn't return any results.",
"everyRow": true
},
"pluginVersion": "8.3.3",
"targets": [
{
"datasource": {
"type": "volkovlabs-rss-datasource",
"uid": "rZAdZdf72"
},
"dateField": "dc:date",
"feedType": "items",
"queryText": "test",
"refId": "A"
}
],
"title": "National Vulnerability Database",
"transformations": [
{
"id": "convertFieldType",
"options": {
"conversions": [
{
"dateFormat": "YYYY-MM-DDThh:mm:ssZ",
"destinationType": "time",
"targetField": "dc:date"
}
],
"fields": {}
}
},
{
"id": "sortBy",
"options": {
"fields": {},
"sort": [
{
"desc": true,
"field": "dc:date"
}
]
}
}
],
"type": "marcusolsson-dynamictext-panel"
}
],
"refresh": "",
Expand All @@ -435,6 +483,6 @@
"timezone": "",
"title": "Panels",
"uid": "O4tc_E6Gz",
"version": 1,
"version": 2,
"weekStart": ""
}
9 changes: 9 additions & 0 deletions provisioning/datasources/datasource.yaml
Expand Up @@ -70,3 +70,12 @@ datasources:
editable: true
jsonData:
feed: https://github.com/sonatype/nexus-public/releases.atom
- name: Volkov Labs YouTube
type: volkovlabs-rss-datasource
access: proxy
orgId: 1
uid: rZAdZdf82
version: 1
editable: true
jsonData:
feed: https://www.youtube.com/feeds/videos.xml?channel_id=UCQadniwbukI6ZmTN2oTTb-g
70 changes: 70 additions & 0 deletions src/api/api.test.ts
Expand Up @@ -345,5 +345,75 @@ describe('Api', () => {
let result = await api.getFeed({ refId: 'A', feedType: FeedTypeValue.ALL }, range);
expect(result?.length).toEqual(0);
});

/**
* YouTube
*/
it('Should handle getFeed request for YouTube', async () => {
xmlResponse.data = `<feed xmlns:yt="http://www.youtube.com/xml/schemas/2015"
xmlns:media="http://search.yahoo.com/mrss/"
xmlns="http://www.w3.org/2005/Atom">
<link rel="self" href="http://www.youtube.com/feeds/videos.xml?channel_id=UCQadniwbukI6ZmTN2oTTb-g"/>
<id>yt:channel:UCQadniwbukI6ZmTN2oTTb-g</id>
<yt:channelId>UCQadniwbukI6ZmTN2oTTb-g</yt:channelId>
<title>Volkov Labs</title>
<link rel="alternate" href="https://www.youtube.com/channel/UCQadniwbukI6ZmTN2oTTb-g"/>
<author>
<name>Volkov Labs</name>
<uri>https://www.youtube.com/channel/UCQadniwbukI6ZmTN2oTTb-g</uri>
</author>
<published>2022-01-18T15:17:13+00:00</published>
<entry>
<id>yt:video:PaiGygHI-dA</id>
<yt:videoId>PaiGygHI-dA</yt:videoId>
<yt:channelId>UCQadniwbukI6ZmTN2oTTb-g</yt:channelId>
<title>Favorite sessions of Grafana Conference 2022 | GrafanaCONline 2022 | Grafana 9</title>
<link rel="alternate" href="https://www.youtube.com/watch?v=PaiGygHI-dA"/>
<author>
<name>Volkov Labs</name>
<uri>https://www.youtube.com/channel/UCQadniwbukI6ZmTN2oTTb-g</uri>
</author>
<published>2022-06-20T18:10:53+00:00</published>
<updated>2022-06-20T19:26:02+00:00</updated>
<media:group>
<media:title>Favorite sessions of Grafana Conference 2022 | GrafanaCONline 2022 | Grafana 9</media:title>
<media:content url="https://www.youtube.com/v/PaiGygHI-dA?version=3" type="application/x-shockwave-flash" width="640" height="390"/>
<media:thumbnail url="https://i1.ytimg.com/vi/PaiGygHI-dA/hqdefault.jpg" width="480" height="360"/>
<media:description>ABOUT THIS VIDEO Grafa</media:description>
<media:community>
<media:starRating count="0" average="0.00" min="1" max="5"/>
<media:statistics views="42"/>
</media:community>
</media:group>
</entry>
<entry>
<id>yt:video:RAxqS2hpWkg</id>
<yt:videoId>RAxqS2hpWkg</yt:videoId>
<yt:channelId>UCQadniwbukI6ZmTN2oTTb-g</yt:channelId>
<title>RSS/Atom Data Source for Grafana | News feed tutorial for Grafana Dashboard</title>
<link rel="alternate" href="https://www.youtube.com/watch?v=RAxqS2hpWkg"/>
<author>
<name>Volkov Labs</name>
<uri>https://www.youtube.com/channel/UCQadniwbukI6ZmTN2oTTb-g</uri>
</author>
<published>2022-06-08T22:26:34+00:00</published>
<updated>2022-06-09T00:10:05+00:00</updated>
<media:group>
<media:title>RSS/Atom Data Source for Grafana | News feed tutorial for Grafana Dashboard</media:title>
<media:content url="https://www.youtube.com/v/RAxqS2hpWkg?version=3" type="application/x-shockwave-flash" width="640" height="390"/>
<media:thumbnail url="https://i3.ytimg.com/vi/RAxqS2hpWkg/hqdefault.jpg" width="480" height="360"/>
<media:description>ABOUT THIS VIDEO In the m</media:description>
<media:community>
<media:starRating count="0" average="0.00" min="1" max="5"/>
<media:statistics views="65"/>
</media:community>
</media:group>
</entry>
</feed>`;

let result = await api.getFeed({ refId: 'A', feedType: FeedTypeValue.ITEMS }, range);
expect(result?.length).toEqual(1);
expect(result[0].fields.length).toEqual(12);
});
});
});
34 changes: 34 additions & 0 deletions src/api/api.ts
Expand Up @@ -262,6 +262,40 @@ export class Api {
value = value['@_url'];
}

/**
* Media Group
*/
if (key === ItemKey.MEDIA_GROUP) {
/**
* Thumbnail URL
*/
if (value[ItemKey.MEDIA_THUMBNAIL] && value[ItemKey.MEDIA_THUMBNAIL]['@_url']) {
setItem(
entries,
`${ItemKey.MEDIA_GROUP}:${ItemKey.MEDIA_THUMBNAIL}:url`,
value[ItemKey.MEDIA_THUMBNAIL]['@_url']
);
}

/**
* Content URL
*/
if (value[ItemKey.MEDIA_CONTENT] && value[ItemKey.MEDIA_CONTENT]['@_url']) {
setItem(
entries,
`${ItemKey.MEDIA_GROUP}:${ItemKey.MEDIA_CONTENT}:url`,
value[ItemKey.MEDIA_CONTENT]['@_url']
);
}

/**
* Description
*/
if (value[ItemKey.MEDIA_DESCRIPTION]) {
setItem(entries, `${ItemKey.MEDIA_GROUP}:${ItemKey.MEDIA_DESCRIPTION}`, value[ItemKey.MEDIA_DESCRIPTION]);
}
}

setItem(entries, key, value);
});
});
Expand Down