|
@@ -1,3 +1,263 @@
|
|
|
+import requests
|
|
|
+
|
|
|
+import hogumathi_app.content_system as h_cs
|
|
|
+import hogumathi_app.view_model as h_vm
|
|
|
+
|
|
|
+VIDEOS_APP="http://localhost:5006"
|
|
|
+
|
|
|
+def get_video_collections ():
|
|
|
+ url = f'{VIDEOS_APP}/channels.json'
|
|
|
+
|
|
|
+ resp = requests.get(url)
|
|
|
+
|
|
|
+ return resp.json()
|
|
|
+
|
|
|
+def get_video_collection (collection_id):
|
|
|
+ url = f'{VIDEOS_APP}/channel/{collection_id}/videos.json'
|
|
|
+
|
|
|
+ resp = requests.get(url)
|
|
|
+
|
|
|
+ coll_data = resp.json()['data']
|
|
|
+
|
|
|
+ def to_feed_item (c):
|
|
|
+ if c['media']['is_archived']:
|
|
|
+ video = h_vm.MediaItem(
|
|
|
+ type = 'video',
|
|
|
+ preview_image_url = c['poster'],
|
|
|
+ url = c['media']['url'],
|
|
|
+ content_type = c['media']['type'],
|
|
|
+ width = c['media']['width'] or 480,
|
|
|
+ height = c['media']['height'] or 360,
|
|
|
+ duration_ms = int(c['duration']) * 1000
|
|
|
+ )
|
|
|
+ else:
|
|
|
+ video = h_vm.MediaItem(
|
|
|
+ type = 'video',
|
|
|
+ preview_image_url = c['poster'],
|
|
|
+ url = c['media']['embed_url'],
|
|
|
+ content_type = c['media']['type'],
|
|
|
+ width = c['media']['width'] or 480,
|
|
|
+ height = c['media']['height'] or 360,
|
|
|
+ duration_ms = int(c['duration']) * 1000
|
|
|
+ )
|
|
|
+ fi = h_vm.FeedItem(
|
|
|
+ id = c['guid'],
|
|
|
+ handle = coll_data['id'],
|
|
|
+ display_name = c['author'],
|
|
|
+ created_at = c['pub_date'],
|
|
|
+ videos = [video],
|
|
|
+
|
|
|
+ title = c['title'],
|
|
|
+ text = c['description'],
|
|
|
+ url = c['link'],
|
|
|
+ author_url = c['author_url'],
|
|
|
+ source_url = c['source_link']
|
|
|
+ )
|
|
|
+
|
|
|
+ return fi
|
|
|
+
|
|
|
+ feed_items = list(map(to_feed_item, coll_data['items']))
|
|
|
+
|
|
|
+ return feed_items
|
|
|
+
|
|
|
+def test_video_collection ():
|
|
|
+ colls = get_video_collections()
|
|
|
+
|
|
|
+ print(colls['data'][32].keys())
|
|
|
+
|
|
|
+ coll = get_video_collection(colls['data'][32]['id'])
|
|
|
+
|
|
|
+ return coll
|
|
|
+
|
|
|
+ #print(coll['data']['items'][1].keys())
|
|
|
+ #print(coll['data']['items'][1]['media'])
|
|
|
+
|
|
|
+def search_videos_cards_collection (q, collection_id):
|
|
|
+ # FIXME cards may not be the best format but it's all we support
|
|
|
+ url = f'{VIDEOS_APP}/videos/search.cards.json'
|
|
|
+ params = dict(
|
|
|
+ channel = collection_id,
|
|
|
+ q = q
|
|
|
+ )
|
|
|
+
|
|
|
+ # card logic from search note cards.
|
|
|
+ resp = requests.get(url, params=params)
|
|
|
+
|
|
|
+ if resp.status_code != 200:
|
|
|
+ return
|
|
|
+
|
|
|
+ resp_json = resp.json()
|
|
|
+
|
|
|
+ cards = resp_json['cards']
|
|
|
+
|
|
|
+
|
|
|
+ def to_feed_item (search_result):
|
|
|
+ # different from normal collection
|
|
|
+
|
|
|
+ # FIXME this uses Os-specific path sep
|
|
|
+ channel_and_video_id = search_result['id']
|
|
|
+
|
|
|
+ # FIXME not provided by videos_app yet
|
|
|
+ #video_channel = search_result['channel']
|
|
|
+
|
|
|
+ c = search_result['card']
|
|
|
+
|
|
|
+ card_id = c['id']
|
|
|
+
|
|
|
+ # work-around since search result ID also includes channel
|
|
|
+ video_id = card_id
|
|
|
+
|
|
|
+ #content_url = f'{NOTES_APP}/notes/{collection_id}.html#note={note_id}&card={card_id}'
|
|
|
+
|
|
|
+ # FIXME we need to update notes app to include the collection_id
|
|
|
+ #content_url = c['content_source'].replace(':notes-app', NOTES_APP)
|
|
|
+ #content_url += f'&card={card_id}'
|
|
|
+
|
|
|
+ content_url = f'{VIDEOS_APP}/channel/{collection_id}/video/{video_id}.html'
|
|
|
+ source_url = c['content_source']
|
|
|
+
|
|
|
+ fi = h_vm.FeedItem(
|
|
|
+ id = card_id,
|
|
|
+ display_name = "Notes App",
|
|
|
+ handle = collection_id,
|
|
|
+ created_at = c['created_at'],
|
|
|
+
|
|
|
+ title = c['title'],
|
|
|
+ text = c['content'],
|
|
|
+ url = content_url,
|
|
|
+ source_url = source_url
|
|
|
+ )
|
|
|
+ return fi
|
|
|
+
|
|
|
+ feed_items = list(map(to_feed_item, cards))
|
|
|
+
|
|
|
+ return feed_items
|
|
|
+
|
|
|
+NOTES_APP = 'http://localhost:5000'
|
|
|
+
|
|
|
+def get_note_cards_collection (note_id, collection_id='daily'):
|
|
|
+ """
|
|
|
+ This is a good use case where we could directly query models,
|
|
|
+
|
|
|
+ Rather than over HTTP.
|
|
|
+
|
|
|
+ Store or Service Layer needs to support multi-process locking or similar.
|
|
|
+ """
|
|
|
+ url = f'{NOTES_APP}/{collection_id}/note/{note_id}/cards'
|
|
|
+
|
|
|
+ resp = requests.get(url)
|
|
|
+
|
|
|
+ if resp.status_code != 200:
|
|
|
+ return
|
|
|
+
|
|
|
+ resp_json = resp.json()
|
|
|
+
|
|
|
+ cards = resp_json['cards']
|
|
|
+
|
|
|
+ def to_feed_item (c):
|
|
|
+ card_id = c['id']
|
|
|
+ note_id = c['note_id']
|
|
|
+
|
|
|
+ content_url = f'{NOTES_APP}/notes/{collection_id}.html#note={note_id}&card={card_id}'
|
|
|
+
|
|
|
+ # FIXME we need to update notes app to include the collection_id
|
|
|
+ #content_url = c['content_source'].replace(':notes-app', NOTES_APP)
|
|
|
+ #content_url += f'&card={card_id}'
|
|
|
+
|
|
|
+ fi = h_vm.FeedItem(
|
|
|
+ id = card_id,
|
|
|
+ display_name = "Notes App",
|
|
|
+ handle = collection_id,
|
|
|
+ created_at = c['created_at'],
|
|
|
+
|
|
|
+ title = c['title'],
|
|
|
+ text = c['content'],
|
|
|
+ url = content_url
|
|
|
+ )
|
|
|
+ return fi
|
|
|
+
|
|
|
+ feed_items = list(map(to_feed_item, cards))
|
|
|
+
|
|
|
+ return feed_items
|
|
|
+
|
|
|
+#@h_cs.query("notes:cards:search", weight=1000)
|
|
|
+def search_note_cards_collection (q, collection_id='daily'):
|
|
|
+ url = f'{NOTES_APP}/{collection_id}/notes/cards/search'
|
|
|
+ params = dict(
|
|
|
+ q = q
|
|
|
+ )
|
|
|
+
|
|
|
+ resp = requests.get(url, params=params)
|
|
|
+
|
|
|
+ if resp.status_code != 200:
|
|
|
+ return
|
|
|
+
|
|
|
+ resp_json = resp.json()
|
|
|
+
|
|
|
+ cards = resp_json['cards']
|
|
|
+
|
|
|
+
|
|
|
+ def to_feed_item (search_result):
|
|
|
+ # different from normal collection
|
|
|
+ c = search_result['card']
|
|
|
+
|
|
|
+ # FIXME we should add this to notes_app
|
|
|
+ #note_id = search_result['id']
|
|
|
+
|
|
|
+ card_id = c['id']
|
|
|
+ note_id = c['note_id']
|
|
|
+
|
|
|
+ content_url = f'{NOTES_APP}/notes/{collection_id}.html#note={note_id}&card={card_id}'
|
|
|
+
|
|
|
+ # FIXME we need to update notes app to include the collection_id
|
|
|
+ #content_url = c['content_source'].replace(':notes-app', NOTES_APP)
|
|
|
+ #content_url += f'&card={card_id}'
|
|
|
+
|
|
|
+ fi = h_vm.FeedItem(
|
|
|
+ id = card_id,
|
|
|
+ display_name = "Notes App",
|
|
|
+ handle = collection_id,
|
|
|
+ created_at = c['created_at'],
|
|
|
+
|
|
|
+ title = c['title'],
|
|
|
+ text = c['content'],
|
|
|
+ url = content_url
|
|
|
+ )
|
|
|
+ return fi
|
|
|
+
|
|
|
+ feed_items = list(map(to_feed_item, cards))
|
|
|
+
|
|
|
+ return feed_items
|
|
|
+
|
|
|
+#@h_cs.command("notes:cards:collection:prepend:<note_id>", weight=1000)
|
|
|
+def post_notes_card_prepend (note_id, text, collection_id='daily', should_create=True):
|
|
|
+ """
|
|
|
+ This is no different than posting a Tweet.
|
|
|
+
|
|
|
+ Logically adds an item to the beginning of the collection.
|
|
|
+
|
|
|
+ In the near future the intents will be manually approved but for now it's just a normal write.
|
|
|
+
|
|
|
+ We might need to add a token of some sort as well for auth.
|
|
|
+ """
|
|
|
+
|
|
|
+
|
|
|
+ url = f'{NOTES_APP}/{collection_id}/intent/prepend-text/{note_id}'
|
|
|
+
|
|
|
+ params = dict(
|
|
|
+ text = text,
|
|
|
+ should_create = should_create
|
|
|
+ )
|
|
|
+
|
|
|
+ resp = requests.get(url, params=params)
|
|
|
+
|
|
|
+ return
|
|
|
+
|
|
|
+def get_librivox_books ():
|
|
|
+ """
|
|
|
+ https://librivox.org/api/info
|
|
|
+ """
|
|
|
+ pass
|
|
|
|
|
|
def register_content_sources ():
|
|
|
"""
|
|
@@ -8,7 +268,17 @@ def register_content_sources ():
|
|
|
bitchute:videos:channel:
|
|
|
bitchute:comments:video:
|
|
|
"""
|
|
|
- pass
|
|
|
+
|
|
|
+ h_cs.register_content_source("notes:cards:collection:", get_note_cards_collection, id_pattern="([^:]+)")
|
|
|
+ h_cs.register_content_source("notes:cards:search", search_note_cards_collection, id_pattern="")
|
|
|
+ #h_cs.register_content_command("notes:cards:collection:prepend", post_notes_card_prepend)
|
|
|
+ #h_cs.register_content_query("notes:cards:search", search_note_cards_collection, id_pattern="")
|
|
|
+ #
|
|
|
+
|
|
|
+ h_cs.register_content_source("videos:collection:", get_video_collection, id_pattern="([^:]+)")
|
|
|
+ h_cs.register_content_source("videos:cards:search", search_videos_cards_collection, id_pattern="")
|
|
|
+
|
|
|
+
|
|
|
|
|
|
def get_bitchute_comments ():
|
|
|
"""
|
|
@@ -259,5 +529,5 @@ def get_bitchute_comments ():
|
|
|
}
|
|
|
|
|
|
"""
|
|
|
-
|
|
|
- pass
|
|
|
+
|
|
|
+ pass
|