Skip to content

How to use Filter

tangyoha edited this page Oct 25, 2023 · 14 revisions

author: tangyoha@outlook.com last edit: 2023/06/19

You can use filters to filter messages you don't want to download very easily

Support Units

  • B,KB,MB,GB,TB

Such as file_size > 1 * 1024 is equivalent to file_size > 1KB

Support Type

  • date_time_str - Support using ./- to split year, month, and day. Supports 4 precision time formats.
    • 2013.8.15 22:46:21 (eq 2013.8.15 22:46:21)
    • 2013.8.15 22:46 (eq 2013.8.15 22:46:00)
    • 2013.8.15 (eq 2013.8.15 00:00:00)
    • 2014.8 (eq 2014.8.1 00:00:00)
  • str - String supports two matching formats
    • simple string comparison
      • message_caption == '123'
    • regular expression match
      • message_caption == r'123.*'
  • int
    • message_id >= 1024

Support Operator

type operator
date_time_str > < >= <= != ==
str != ==
int > < >= <= != ==

Support Meta Data

meta data name alias type unit supported version remark
message_date date_time_str message sending time
message_id id int message id
message_caption caption str message caption content
media_file_size file_size int Byte (byte) media file size
media_width int media video width
media_height int media video length
media_file_name file_name str file name of the media
media_duration int media duration
media_type str v2.2.0 type of media
file_extension str v2.2.0 file extension

Support Media type

audio, document, photo, sticker, animation, video, voice, video_note, new_chat_photo

##Note

Pay attention to the configuration format, : is followed by a bracket

Such as 'mychannel': 'xxxx' But 'mychannel':'xxxx' reports an error

in v2.1.4

chat:
  - chat_id: your_chat_id
  download_filter: your filter

in v2.1.3

chat_id: your_chat_id
download_filter:
   'your_chat_id': your filter

Usage

  • The download message id is 1-900 and the title contains #My Favorite and the file size is 1KB-20MB in v2.1.4
chat:
  - chat_id: your_chat_id
  download_filter: id >= 1 && id <= 900 && caption == r'.*#My favorite.*' && file_size >= 1KB && file_size <= 20MB

in v2.1.3

chat_id: your_chat_id
download_filter:
   'your_chat_id': id >= 1 && id <= 900 && caption == r'.*#My favorite.*' && file_size >= 1KB && file_size <= 20MB
  • Download message title contains #My Favorite or #Health Video in v2.1.4
chat:
  - chat_id: your_chat_id
  download_filter: caption == r'.*#health video.*' or caption == r'.*#my favorite.*'

in v2.1.3

chat_id: your_chat_id
download_filter:
   'your_chat_id': caption == r'.*#health video.*' or caption == r'.*#my favorite.*'

Note: If your configuration contains or conditions, please frame other conditions with ( ) to avoid logic errors

  • example: You want to download a file with a size of 10MB - 100MB and the title contains #Three-body or #My favorite

    • 1."file_size > 10MB and file_size < 100MB and (caption == r'.*#Three-body.*' or caption == r'.*#My favorite.*')" everything is correct

    • 2."file_size > 10MB and file_size < 100MB and caption == r'.*#Three-body.*' or caption == r'.*#My favorite.*'" The file size is not enough, but the tag contains #My Favorite, and it can also be downloaded

Note: If the date does not have a day, it defaults to the 1st, such as 2022.01, which is actually parsed as 2022.01.01 00:00:00

*Download messages from 2022.01 - 2022.03

message_date > 2022.01 and message_date < 2022.03
  • Download the message with the message time of 2022.01.14 - 2022.03.15
message_date > 2022.01.14 and message_date < 2022.03.15
  • Download the file whose name contains bios
file_name == r'.*bios.*'
  • Download files whose name does not contain .bin
file_name != r'.*\.bios'

**Note: If you need regular matching of some special characters such as ., *, +, etc., you need to add a \ escape before the character. **

  • Download files with extension name mp4 or mp3
file_extension == r'(mp4|mp3)'
  • Download files with file type video or audio
media_type == r'(video|audio)'

Other

  • message_date_time : - Date the message was sent(date_time_str)
    • like: message_date_time > 2022.03.04 && message_date_time < 2022.03.08
    • like: message_date_time > 2022-03-04 14:50 && message_date_time < 2022.03.08
    • like: message_date_time > 2022-03 && message_date_time < 2022-04
    • like: message_date_time > 2022-03 and message_date_time < 2022-04
    • like: message_date_time >= 2022-03
    • like: message_date_time <= 2022-03
  • message_id : - Message 's id(int)
    • like: message_id >= 20001 && message_id <= 20100
    • like: message_id >= 20001 and message_id <= 20100
  • media_file_size : - File size(int)
    • like: media_file_size >= 10 * 1024 * 1024 && media_file_size <= 1024 * 1024 * 1024 # 1024 * 1024 * 1024 = 1G
  • media_width : - Include photo and video(int)
    • like: media_width >= 1920 and media_height >= 1080
  • media_height : - Include photo and video(int)
  • media_duration: - Media duration(int)
  • media_file_name : - file name(str)
    • like: media_file_name == 'test.mp4'(str equal)
    • like: media_file_name == r'test.*mp4'(with r prefix)
    • like: media_file_name == r'.*test.*'(with r prefix)
  • message_caption : - message caption(tpye: str)
    • like: message_caption == '#v2'(str equal)
    • like: message_caption == r'.*#v2.*'(with r prefix)
    • like: message_caption != r'.*#v2.*'(with r prefix)