Skip to content

Commit

Permalink
modules.youtube: add mode --all to dump all videos + minor cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
karlicoss committed Sep 22, 2024
1 parent 0c04543 commit ed12951
Showing 1 changed file with 31 additions and 17 deletions.
48 changes: 31 additions & 17 deletions src/orger/modules/youtube.py
Original file line number Diff line number Diff line change
@@ -1,37 +1,51 @@
#!/usr/bin/env python3
from orger import Mirror
from orger.inorganic import node, link
from orger.common import dt_heading, error

from my.media.youtube import watched
from __future__ import annotations

from itertools import groupby

from orger import Mirror
from orger.common import dt_heading, error
from orger.inorganic import link, node


class YoutubeView(Mirror):
@property
def mode(self) -> str:
assert self.cmdline_args is not None
return self.cmdline_args.mode

def get_items(self) -> Mirror.Results:
from my.media.youtube import watched

good = []
for i in watched():
if isinstance(i, Exception):
yield error(i)
else:
good.append(i)

by_url = lambda w: w.url
by_when = lambda w: w.when
items = [
max(group, key=by_when)
for _, group in groupby(sorted(good, key=by_url), key=by_url)
]
items = sorted(items, key=by_when)
# TODO for each url only take latest?
if self.mode == 'last':
by_url = lambda w: w.url
items = [
max(group, key=by_when)
for _, group in groupby(sorted(good, key=by_url), key=by_url)
]
items = sorted(good, key=by_when)
for item in items:
deleted = item.url == item.title # todo move to HPI?
deleted = item.url == item.title # todo move to HPI?
l = link(title=item.title + (' (DELETED)' if deleted else ''), url=item.url)
yield (item.url, node(
heading=dt_heading(item.when, l),
))
yield (
item.url,
node(heading=dt_heading(item.when, l))
)


def setup_parser(p) -> None:
p.add_argument(
'--mode', choices=['all', 'last'], default='last', help="'all' would dump all watch history, 'last' only last watch for each video"
)


if __name__ == '__main__':
YoutubeView.main()
YoutubeView.main(setup_parser=setup_parser)

0 comments on commit ed12951

Please sign in to comment.