GithubHelp home page GithubHelp logo

media_cleaner's People

Contributors

clara-j avatar terrelsa13 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

media_cleaner's Issues

problem jellyfin docker

not working for me Jellyfin is inside a docker image:

root@openmediavault:~# ./media_cleaner.py


Start...

Cleaning media for server at: http://192.168.1.xxx:8096



Get List Of Watched Media


Traceback (most recent call last):

File "./media_cleaner.py", line 436, in

deleteItems=get_items(cfg.server_url, cfg.user_key, cfg.access_token)

File "./media_cleaner.py", line 228, in get_items

item_details=item['Type'] + ' - ' + item['SeriesName'] + ' - ' + item['Name'] + ' - ' + get_days_since_watched(item['UserData']['LastPlayedDate']) + ' - Favorite: ' + str(item['UserData']['IsFavorite']) + ' - ' + 'EpisodeID: ' + item['Id']

File "./media_cleaner.py", line 167, in get_days_since_watched

date_time_last_watched = datetime.strptime(date_last_played, '%Y-%m-%dT%H:%M:%S.0000000+00:00')

File "/usr/lib/python3.7/_strptime.py", line 577, in _strptime_datetime

tt, fraction, gmtoff_fraction = _strptime(data_string, format)

File "/usr/lib/python3.7/_strptime.py", line 359, in _strptime

(data_string, format))

ValueError: time data '2020-03-24T06:52:14.1311383Z' does not match format '%Y-%m-%dT%H:%M:%S.0000000+00:00'

root@openmediavault:~#

[little help] modifying your script to simply move all watched files

I use MergerFS to pool 2 HDDs with an SSD, I specifically use the tiered caching solution, having 2 pools: one that includes a folder on my system SSD, plus the 2 HDDs. The second pool only contains the (same) HDDs.
All data goes to the first pool.
A script runs nightly to move files that have not been accessed in the past 30 days to the second pool. Note this pool is a subset of the first pool and the path to this 2nd pool is not used in any way, it only exists to be able to move files away from the SSD. Files moved to the 2nd pool are only moved within the array (SSD >> HDDs), they can still be found in the same path location on the first pool when you look at a file manager, because that first pool simply shows all data on HDDs and SSD, regardless on which of those disks it is stored.

Now I would like to run a nightly script that will move watched files (regardless when it has been watched) to the second pool. This will free up even more space. If I have 4GB episode files (2160p), watch 10 episodes in a week, I could save 40GB on my SSD. The Media_Cleaner script erases these files after 15 days (to give other fam members time to watch it). But before cleaning them, I can safely move them off my SSD already.

The command to move files based on last accessed is simple:

find "${CACHE}" -type f -atime +${N} -printf '%P\n' | nocache rsync --files-from=- -axHAXWES --progress --preallocate --remove-source-files "${CACHE}/" "${BACKING}/"
This moves files from one pool to the other (the 3 variables are given as input when I run the script).

I now like to modify this command to find all (watched) files. But looking at your script (I am no Python expert) it seems I would need quite a bit of code to get the data from Jellyfin, build a list and then perform the rsync action on that list. So now I wonder if it is better to start with your script and remove everything :)
I don't need # of days, favourite status, don't care about whether it is a show, season, movie or episode as the folder structure won't change. So I can just focus on episodes, movies and their watched status (boolean).
First thing I notice: you are not asking the mediaserver for the boolean "watched status", instead you obtain date_last_played. Is this correct?

Not working with Jellyfin 10.7.6

The script is not working with Jellyfin 10.7.6, got this error message :

Traceback` (most recent call last):
  File "/home/thomas/Downloads/Media_Cleaner/Nous/media_cleaner.py", line 643, in <module>
    import media_cleaner_config as cfg
ModuleNotFoundError: No module named 'media_cleaner_config'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3.8/urllib/request.py", line 1354, in do_open
    h.request(req.get_method(), req.selector, req.data, headers,
  File "/usr/lib/python3.8/http/client.py", line 1252, in request
    self._send_request(method, url, body, headers, encode_chunked)
  File "/usr/lib/python3.8/http/client.py", line 1298, in _send_request
    self.endheaders(body, encode_chunked=encode_chunked)
  File "/usr/lib/python3.8/http/client.py", line 1247, in endheaders
    self._send_output(message_body, encode_chunked=encode_chunked)
  File "/usr/lib/python3.8/http/client.py", line 1007, in _send_output
    self.send(msg)
  File "/usr/lib/python3.8/http/client.py", line 947, in send
    self.connect()
  File "/usr/lib/python3.8/http/client.py", line 918, in connect
    self.sock = self._create_connection(
  File "/usr/lib/python3.8/socket.py", line 787, in create_connection
    for res in getaddrinfo(host, port, 0, SOCK_STREAM):
  File "/usr/lib/python3.8/socket.py", line 918, in getaddrinfo
    for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno -2] Name or service not known

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/thomas/Downloads/Media_Cleaner/Nous/media_cleaner.py", line 789, in <module>
    generate_config()
  File "/home/thomas/Downloads/Media_Cleaner/Nous/media_cleaner.py", line 155, in generate_config
    auth_key=get_auth_key(server_url, username, password, password_sha1)
  File "/home/thomas/Downloads/Media_Cleaner/Nous/media_cleaner.py", line 263, in get_auth_key
    with request.urlopen(req) as response:
  File "/usr/lib/python3.8/urllib/request.py", line 222, in urlopen
    return opener.open(url, data, timeout)
  File "/usr/lib/python3.8/urllib/request.py", line 525, in open
    response = self._open(req, data)
  File "/usr/lib/python3.8/urllib/request.py", line 542, in _open
    result = self._call_chain(self.handle_open, protocol, protocol +
  File "/usr/lib/python3.8/urllib/request.py", line 502, in _call_chain
    result = func(*args)
  File "/usr/lib/python3.8/urllib/request.py", line 1383, in http_open
    return self.do_open(http.client.HTTPConnection, req)
  File "/usr/lib/python3.8/urllib/request.py", line 1357, in do_open
    raise URLError(err)
urllib.error.URLError: <urlopen error [Errno -2] Name or service not known>

me again after more testing done

Hello @terrelsa13 so i did what you told me and i created 2 different folders one for me and one for requested items.. now i found 2 new features/improvements that you might want to consider

  1. when scanning all library for the max age and you have mutliple users, you are scanning the whole library for each one of them. i guess this is correct becuase i am using the same library and because i do not have them separated am i right? i guess while writing this out i figured this is the right behavior in case they do not have the same libraries even though on this case it is just waste of resources becuase it is scanning the same thing over and over again

  2. is there a posibility to have the summary of deleted save into a txt file and record that with a date and time?
    image
    what is happening is that i will be running this on a job on the background so i am not able to see the summary of deleted but it would be nice to keep a history of what was deleted on a txt file so i can go back a day or 2 later and see what was deleted.

Thanks!

Hashed Password Does Not Seem To Work For Me Anymore

Anyone else getting urllib.error.HTTPError: HTTP Error 401: Unauthorized?
I started getting this after I updated to Emby-Server 4.3.0.30. Seems to be failing when trying to get the access token from the server. I took at look at the emby-server API to see if I could find anything and came across Authenticating A User:

The password must be sent in the body, in three different form fields:

pw - password in plain text
password - password in Sha1
passwordMd5 - password in MD5

IMPORTANT - The Emby login API is in a state of transition, and this is why three different forms of the password are required. Beginning April 1, 2018, only the "pw" param will be required. Until then, all three are needed in order to support both newer and older servers.

With this information, I changed my script to skip the sha1 hashing and send the (pw) plain text password. This seemed to fix it for me. Any idea why the hashed password no longer plays nicely with emby?

Changed these two lines:

    #password_hash=hashlib.sha1(password.encode()).hexdigest()
    password_hash=password

    #values = {'Username' : username, 'Password' : password}
    values = {'Username' : username, 'Pw' : password}

@clara-j I have not had a chance to grab emby-server logs and upload them to pastebin yet. If I need to do that, just let me know.

option for just summary output from script

Hi, I'm still in the dry run phase and I start the script form cron. I would like to have an option to only see the result which I can redirect for some logging.

Just an option to log only the summary what is deleted.

I have already noticed that I should change the metadata to let this script do its work. The Date Added should be set correctly which is in the library settings. A old movie would be deleted immediately in my setup.

@terrelsa13 you asked to be mentioned

Shows to delete

I wish there was a way to say only delete the following shows episodes after they are watched by everyone but keep the rest. Like there some cop and drama shows we will never watch again, but other shows like Game of Thrones that we will go back and watch again,

It would almost be like wanting to invert favorites. Current shows we are watching but won't ever watch again so don't keep those episodes once everyone has watched them.

Ability to whitelist/ignore series entirely?

Great script, thanks!

Would it be possible/able to whitelist entire series/folders to prevent them being deleted?

I've got some classic tv shows I'd like to keep, David Attenboroughs, etc.

Thanks!

episode is deleted while favorite

It looks like when UserA has seen a media file (episode or movie) and UserB has it marked as Favorite but has not seen the media it is still being deleted by media_cleaner.

Episode S01E01
UserA = seen
UserB = unseen, favorite

When I mark UserB has seen the Episode only then 'sees' the script that the episode is a favorite.

What I expect to see is that the Favorite status is first evaluated before the seen status IF another user has seen it. (hope this make sense)

I have tried with keep_favorites_episode=1 and keep_favorites_episode=2 It does not seem the make a difference. It is the same for Movies

@terrelsa13

trying to modify code without luck

Hello guys, is there a way in which we can skip certain genres? lets say i do not want my kids movies or tv shows to be deleted so is there a way to not delete animated videos? maybe set paths that should not be deleted?

not sure if issue or by design

hello @terrelsa13,

so i was running the script and i deleted a whole season 1 of a tv show, when looking into my folders it looks like it did deleted the episodes but left the empty folder in my library:
image
is there a way to validate if that is the last episode on the folder so the folder is also deleted? also maybe check if that is the last show season to also delete the tv show main folder? on my example i have your honor with just season 1 folder on it but both empty.

Error when creating an new media_cleaner_config.py

@terrelsa13 Because of the new options. I thought I would probably need a new media_cleaner_config. I removed my old config and when creating I get the follow error.

On first look the config seems to be ok... I choose blacklist and use the enter key to accept the default -1

Choose the number of days to wait before deleting played audio media items
Valid values: 0-730500 days
-1 to disable deleting audio media items
Enter number of days (default -1):
"-----------------------------------------------------------
Traceback (most recent call last):
File "/home/xxx/xxx/xxx/media_cleaner/media_cleaner.py", line 3324, in
import media_cleaner_config as cfg
ModuleNotFoundError: No module named 'media_cleaner_config'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/home/xxx/xxx/xxx/media_cleaner/media_cleaner.py", line 3343, in
generate_config(update_config)
File "/home/xxx/xxx/xxx/media_cleaner/media_cleaner.py", line 579, in generate_config
if ((cfg.not_played_age_movie == -1) and
NameError: name 'cfg' is not defined

unclear how to use black and whitelist

#----------------------------------------------------------#

User blacklisted libraries of corresponding user account(s) to monitor media items; chosen during setup

#----------------------------------------------------------#
user_bl_libs='["", ""]'

#----------------------------------------------------------#

User whitelisted libraries of corresponding user account(s) to exclude monitoring media items; chosen during setup

#----------------------------------------------------------#
user_wl_libs='["", ""]'

Maybe its my comprehension of the english language. But this is in my config I have 2 libraries.
I blacklist the library for a user so that the script can monitor(delete) from this library for this user
I whitlist the library for a user so that the script can NOT monitor(delete) from this library for this user

So is it my understanding that if every user should be monitored for all(2) libraries I should enter them in the Blacklist?
If I look at my output 1 admin sees all regardless of the above and a users sees only movies which I did not white or blacklist but is still monitored. The user sees also favorite series.

perhaps I can experiment some more with the black/whitelist

Episodes Not Deleting

Hello,

The script works great but I am not sure how to debug it not deleting the quoted "[DELETED]" episodes.

image

As can be seen in the above image, the files remain.

Is there a log file?

Which version to use?

I'm interested in your script. It seems to do what I what I was searching for.

I'm a bit confused about this script or a similar script from https://github.com/terrelsa13/media_cleaner. They seem to be the same but the read.me is completly differrent and the last edited seem also different.

Shoud I try this one or the one from terrelsa13?

Error

Traceback (most recent call last):
  File "media_cleaner.py", line 155, in <module>
    deleteItems=get_items(cfg.server_url, cfg.user_key, auth_key)
  File "media_cleaner.py", line 124, in get_items
    item_details=item['Type'] +' - '+ item['Name'] +' - ' + item['UserData']['LastPlayedDate'] + ' - ' + item['UserData']['Key'] + ' - ' + item['Id']
KeyError: 'Key'

script fails on items that are missing

Receiving error on all items that are watched but missing

`Error encounter:

{'Name': 'Episode 15', 'ServerId': '8421c3xxxxxxxxxxxxxxxxxxxxxxxxeb', 'Id': '34906', 'IndexNumber': 15, 'ParentIndexNumber': 9, 'IsFolder': False, 'Type': 'Episode', 'ParentLogoItemId': '13996', 'ParentBackdropItemId': '13996', 'ParentBackdropImageTags': ['d0e490e4253dd7a60747c8637d17e23c', 'bcb049b1a8b979b60f8344b3b823814b'], 'UserData': {'PlaybackPositionTicks': 0, 'PlayCount': 1, 'IsFavorite': False, 'LastPlayedDate': '2019-01-29T02:23:29.0000000+00:00', 'Played': True}, 'SeriesId': '13996', 'SeasonId': '13998', 'SeriesPrimaryImageTag': '70f77846509cf2173ded22611a926c8b', 'ImageTags': {}, 'BackdropImageTags': [], 'ParentLogoImageTag': '8914369c16c715171ac5e198fd89a84d', 'ParentThumbItemId': '13996', 'ParentThumbImageTag': '7478b7ccc10569f42037593562092b23', 'LocationType': 'Virtual', 'MediaType': 'Video'}
`

If i go to that show in emby i see its Added 2019-01-20 but Missing

http://app.emby.media/#!/item?id=34906&serverId=8421c3xxxxxxxxxxxxxxxxxxxaeb

new suggestion

Hello @terrelsa13 we probably already talked about this so i really like the latest script but i would like to know if there is a chance for another change. so you know you added the possibility to delete videos depending on the date the movie/show was added to the library. is there a way to do this by path? so lets say i would like to delete movies/tv shows from the library people request to me if it was added more than 30 days ago but my personal movies i would not like to touch or maybe 1 year. but right now it is deleting it for all libraries

also is there a way to include the name of the user for which something is been deleted?
image
on the image above everything is from my username except the movie and i had to go up and check the user through the whole list to see what user already watched that. it would be nice to have the username here in this list of deleting items

Thanks!

[Feature Request / Function Query] Ignore specific libraries

Hello & Thank you for this script.

/media/shows/shows-auto-delete
/media/shows/shows-keep-forever

these are my actual directory names and same naming system for movies.

is it possible to get this script to either whitelist/blacklist the corresponding folders?

not issue but suggestion

Hello me again, so i am sharing my jellyfin with my sisters and some friends and i was thinking about also deleting things that they have already watched but right now what i am doing is having different folders with different configurations and different users so i need to run each one of them to delete media for that particular user.

is there a way to put everything tgether? so on my setup, i have ombi and whatever users request there it will go into a ombi folder and that will be another media library on jellyfin, so i am whilisting everything except for tv shows and movies on the ombi folder for those users.. so if they watched already then i delete it.

it would be nice to configure this by user and then when running just 1 time the script it will do all that per user checking their whitelist and everything.. i guess it would need to be a whitelist per user and at the beginning of the config it should do something like the whitelist does in which you can select multiple users and after selecting the user then select the folders for that user

Thanks!

Error HttpServer: Error processing request; Access to path denied

Here is the new issue I am opening as requested.

I am not sure if you are talking linux rwx permissions or the "User-->Profile-->Allow Media Deletion From-->All Libraries" setting on the emby server?

Either way, I have tried running the script from my server as the user I am logged in as and as root. Both have rwx permissions to my media files/folders.

When running the script for the first time to set up the config file, I input my username/password for the emby admin account. I then select a different account as the user to track with. Both accounts have their "User-->Profile-->Allow Media Deletion From-->All Libraries" setting checked.

I see the same issue.
https://pastebin.com/raw/nsFvPw35

Please add the item type "Book" (audio books)

A wonderful tool that works very well for me, but unfortunately not for audio books.
I use Jellyfin to listen to my podcast collection, I would like to have already listened podcasts automatically deleted by the
media_cleaner script.
The MP3 files of the podcasts are not recognized as "audio" (but the content type of the library is also Book and not Music).

Thank you very much!

This feature would perfectionize my user experience.

movies/shows not been deleted for multiple users

Hello @terrelsa13 so i have my personal script which is running correctly and deleting everything as planned. but when i am running the other script we talked about in which we can delete from other users.. i am using blacklist as i do in my personal one but this one have 5 users and even though it shows 2 files have been deleted, it is not deleting it.. everytime i run it, it will continue to say those 2 files will be deleted..

any logs you would like to see? here is the script after it is run

pastebin

nice feature that it would be nice to have

@terrelsa13 hello how are you?

so i have been using the script for a long time now and everything is working perfectly with it.. i even switch to Linux. now here is my situation..

couple of times per month, i will add new users to jellyfin so the problem is that then i will need to delete the config file for the media cleaner and run it again.. and imagine every time it get bigger and bigger..

do you think there is a way in which i will just run something and instead of having to run everything again, it will just check the config and let you select just the new users to add into the already configured config file?

Thanks!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.