-
-
Notifications
You must be signed in to change notification settings - Fork 133
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
keyboard shortcuts widget now checks for duplicate shortcuts everytim…
…e shortcut is changed and offers solutions, fixes #1605
- Loading branch information
1 parent
08388cb
commit 68060c7
Showing
5 changed files
with
123 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# Use this as RSS Guard post-processing script. | ||
# | ||
# Example command line usage: | ||
# curl 'PATH_TO_SOME_YOUTUBE_CHANNEL_RSS_FEED' | python 'youtube-limit-length.py' | ||
|
||
import sys | ||
import xml.etree.ElementTree as ET | ||
import requests | ||
import json | ||
import isodate | ||
|
||
sys.stdin.reconfigure(encoding="utf-8") | ||
input_data = sys.stdin.read() | ||
|
||
api_key = "YOUR_API_KEY_HERE" | ||
min_required_length = 90 # In seconds. | ||
|
||
youtube_query = ( | ||
"https://www.googleapis.com/youtube/v3/videos?part=contentDetails&id=VIDEO-ID&key=" | ||
+ api_key | ||
) | ||
ns = { | ||
"atom": "http://www.w3.org/2005/Atom", | ||
"yt": "http://www.youtube.com/xml/schemas/2015", | ||
} | ||
|
||
tree = ET.fromstring(input_data) | ||
entries = tree.findall("atom:entry", ns) | ||
|
||
for entry in entries: | ||
video_id = entry.find("yt:videoId", ns).text | ||
youtube_query_specific = youtube_query.replace("VIDEO-ID", video_id) | ||
api_response = requests.get(youtube_query_specific).text | ||
response_json = json.loads(api_response) | ||
|
||
try: | ||
length_encoded = str(response_json["items"][0]["contentDetails"]["duration"]) | ||
except: | ||
continue | ||
|
||
length = isodate.parse_duration(length_encoded) | ||
|
||
if length.seconds < min_required_length: | ||
tree.remove(entry) | ||
|
||
sys.stdout.buffer.write(ET.tostring(tree, encoding='utf-8', method='xml')) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters