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

Renaming of symlinks #4

Closed
eoghan2t9 opened this issue May 25, 2024 · 13 comments
Closed

Renaming of symlinks #4

eoghan2t9 opened this issue May 25, 2024 · 13 comments

Comments

@eoghan2t9
Copy link

Would it be possible for the script to rename the outputted symlinks and also rename the current ones. The reason I ask the media parser I use is very picky over file naming for instance this file

Tiger.King.Murder.Mayhem.and.Madness.S01E08.720p.WEB.X264-AMRAP[eztv].mkv

The parser doesn't like the likes of brackets etc in the naming of the files so would it be possible to customise the naming scheme for instance like this:

{Series Title} - S{season:00}E{episode:00} - {Episode Title} {Quality Full}

@sureshfizzy
Copy link
Owner

Renaming is always been quite Challenging since it cannot be done without implementing API's. Even with them, it will be difficult to handle few names which cannot be completely automated. I need to check upon how to handle these.

@eoghan2t9
Copy link
Author

Happy days mate cheers I did do a quick search online apparently the mv command works to rename the symlink. Would it be possible to run filebot on the folder to see if that works lol

@sureshfizzy
Copy link
Owner

you can manually rename the files using mv, but that method will be hard for all files since you have to do it one by one :). Also can you explain the second method,? Never came across with such thing

@eoghan2t9
Copy link
Author

Yeah to hell one by one renaming lol and filebot it's a tool used for renaming if files to make it easier for media parsers to get the correct metadata. It's a paid for product but could be easily added to your script if a user already has it installed.

https://www.filebot.net/

@sureshfizzy
Copy link
Owner

I hope there is a demo version of it, I'll check the working on ubuntu and add it accordingly.

@eoghan2t9
Copy link
Author

I'll happy get you a years license if you want lol

@sureshfizzy
Copy link
Owner

sureshfizzy commented May 25, 2024

I'm learning on how it is implemented on sonarr :). It just picks the right name all time.

@eoghan2t9
Copy link
Author

Haha that it does but if needed I'll send you my filebot licence via email ;)

@sureshfizzy
Copy link
Owner

I'm just worried about the users who doesn't have it

@eoghan2t9
Copy link
Author

You could possibly do something like this in python got help from chatgpt lol

import os
import re
import requests

# Function to query TMDb API for TV series
def query_tmdb_tv(api_key, query):
    url = "https://api.themoviedb.org/3/search/tv"
    params = {
        'api_key': api_key,
        'query': query
    }
    response = requests.get(url, params=params)
    if response.status_code == 200:
        return response.json()
    else:
        return None

# Function to query TMDb API for specific episode details
def query_tmdb_episode(api_key, tv_id, season_number, episode_number):
    url = f"https://api.themoviedb.org/3/tv/{tv_id}/season/{season_number}/episode/{episode_number}"
    params = {
        'api_key': api_key
    }
    response = requests.get(url, params=params)
    if response.status_code == 200:
        return response.json()
    else:
        return None

# Function to extract series name, season number, and episode number from file name
def extract_info(file_name):
    pattern = re.compile(r"(.+?)[. _-]+[sS](\d+)[eE](\d+)")
    match = pattern.match(file_name)
    if match:
        series_name = match.group(1).replace('.', ' ').replace('_', ' ').replace('-', ' ').strip()
        season_number = int(match.group(2))
        episode_number = int(match.group(3))
        return series_name, season_number, episode_number
    return None, None, None

# Main function
def main():
    api_key = 'YOUR_TMDB_API_KEY'
    media_folder = 'path/to/your/media/files'

    for file_name in os.listdir(media_folder):
        if os.path.isfile(os.path.join(media_folder, file_name)):
            series_name, season_number, episode_number = extract_info(file_name)
            if series_name and season_number and episode_number:
                print(f"Querying TMDb for TV series: {series_name}, Season: {season_number}, Episode: {episode_number}")
                result = query_tmdb_tv(api_key, series_name)
                if result and result['results']:
                    # Get the first result from the list
                    series_info = result['results'][0]
                    tv_id = series_info['id']
                    episode_info = query_tmdb_episode(api_key, tv_id, season_number, episode_number)
                    if episode_info:
                        print(f"Series: {series_info['name']}")
                        print(f"Season: {season_number}, Episode: {episode_number}")
                        # Print the episode title
                        print(f"Episode Title: {episode_info['name']}")
                        print(f"Air Date: {episode_info['air_date']}")
                        print(f"Overview: {episode_info['overview']}")
                    else:
                        print(f"No episode information found for: {series_name}, Season: {season_number}, Episode: {episode_number}")
                else:
                    print(f"No results found for: {series_name}")
            else:
                print(f"File name does not match expected pattern: {file_name}")

if __name__ == "__main__":
    main()

@sureshfizzy
Copy link
Owner

You could possibly do something like this in python got help from chatgpt lol

import os
import re
import requests

# Function to query TMDb API for TV series
def query_tmdb_tv(api_key, query):
    url = "https://api.themoviedb.org/3/search/tv"
    params = {
        'api_key': api_key,
        'query': query
    }
    response = requests.get(url, params=params)
    if response.status_code == 200:
        return response.json()
    else:
        return None

# Function to query TMDb API for specific episode details
def query_tmdb_episode(api_key, tv_id, season_number, episode_number):
    url = f"https://api.themoviedb.org/3/tv/{tv_id}/season/{season_number}/episode/{episode_number}"
    params = {
        'api_key': api_key
    }
    response = requests.get(url, params=params)
    if response.status_code == 200:
        return response.json()
    else:
        return None

# Function to extract series name, season number, and episode number from file name
def extract_info(file_name):
    pattern = re.compile(r"(.+?)[. _-]+[sS](\d+)[eE](\d+)")
    match = pattern.match(file_name)
    if match:
        series_name = match.group(1).replace('.', ' ').replace('_', ' ').replace('-', ' ').strip()
        season_number = int(match.group(2))
        episode_number = int(match.group(3))
        return series_name, season_number, episode_number
    return None, None, None

# Main function
def main():
    api_key = 'YOUR_TMDB_API_KEY'
    media_folder = 'path/to/your/media/files'

    for file_name in os.listdir(media_folder):
        if os.path.isfile(os.path.join(media_folder, file_name)):
            series_name, season_number, episode_number = extract_info(file_name)
            if series_name and season_number and episode_number:
                print(f"Querying TMDb for TV series: {series_name}, Season: {season_number}, Episode: {episode_number}")
                result = query_tmdb_tv(api_key, series_name)
                if result and result['results']:
                    # Get the first result from the list
                    series_info = result['results'][0]
                    tv_id = series_info['id']
                    episode_info = query_tmdb_episode(api_key, tv_id, season_number, episode_number)
                    if episode_info:
                        print(f"Series: {series_info['name']}")
                        print(f"Season: {season_number}, Episode: {episode_number}")
                        # Print the episode title
                        print(f"Episode Title: {episode_info['name']}")
                        print(f"Air Date: {episode_info['air_date']}")
                        print(f"Overview: {episode_info['overview']}")
                    else:
                        print(f"No episode information found for: {series_name}, Season: {season_number}, Episode: {episode_number}")
                else:
                    print(f"No results found for: {series_name}")
            else:
                print(f"File name does not match expected pattern: {file_name}")

if __name__ == "__main__":
    main()

need to check this, can you try it locally ?

@eoghan2t9
Copy link
Author

Not at the moment as I'm not at home but I will later when I'm home again

@sureshfizzy
Copy link
Owner

I'll check on this tomorrow.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants